added camera with motion
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import io
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
import bme680
|
||||
import uvicorn
|
||||
@@ -81,9 +82,33 @@ is_recording = False
|
||||
picam2 = None
|
||||
|
||||
def camera_loop():
|
||||
global is_recording, picam2
|
||||
try:
|
||||
while True:
|
||||
while True and not is_recording:
|
||||
val = GPIO.input(camera_pin)
|
||||
|
||||
if val == 1:
|
||||
is_recording = True
|
||||
print("Start recording!")
|
||||
|
||||
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
filename = f"recordings/video_{timestamp}.mp4"
|
||||
|
||||
picam2.start_and_record_video(filename, duration=10)
|
||||
|
||||
cursor.execute(
|
||||
"INSERT INTO recordings (file_path) VALUES (%s)",
|
||||
filename
|
||||
)
|
||||
|
||||
|
||||
connection.commit()
|
||||
|
||||
print("Recorded video of 10 seconds, motion detected!!!!")
|
||||
|
||||
is_recording = False
|
||||
|
||||
print(val)
|
||||
|
||||
except Exception as e:
|
||||
@@ -128,9 +153,9 @@ def init_camera():
|
||||
camera_config = camera.create_preview_configuration(main={"format": "RGB888", "size": (640, 480)})
|
||||
camera.configure(camera_config)
|
||||
|
||||
camera.start()
|
||||
#camera.start()
|
||||
picam2 = camera
|
||||
print("Kamera bereit für das Streaming!")
|
||||
#print("Kamera bereit für das Streaming!")
|
||||
except Exception as e:
|
||||
picam2 = None
|
||||
print(f"Kamera konnte nicht initialisiert werden: {e}")
|
||||
@@ -249,8 +274,8 @@ def startup_event():
|
||||
|
||||
if use_camera:
|
||||
init_camera()
|
||||
#camera_thread = threading.Thread(target=camera_loop, daemon=True)
|
||||
#camera_thread.start()
|
||||
camera_thread = threading.Thread(target=camera_loop, daemon=True)
|
||||
camera_thread.start()
|
||||
|
||||
print("Sensor thread started")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user