Skip to content

Commit

Permalink
Remove Flask app and threading
Browse files Browse the repository at this point in the history
  • Loading branch information
infinitel8p committed Nov 11, 2023
1 parent d58279d commit b40a5e8
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import picamera
import RPi.GPIO as GPIO
from dotenv import load_dotenv
from threading import Thread
from web_server import app, socketio, send_status_update
from functions import *

# Set up logging with custom timestamp format
Expand Down Expand Up @@ -40,19 +38,7 @@

# Initialize the camera
camera = picamera.PiCamera()
app.camera = camera
recording = False
app.recording = recording

# Start Flask app in a separate thread


def start_flask_app():
socketio.run(app, host='0.0.0.0', port=5000)


flask_thread = Thread(target=start_flask_app)
flask_thread.start()

# Set up GPIO
GPIO.setmode(GPIO.BCM)
Expand All @@ -72,7 +58,6 @@ def start_flask_app():
logging.info("Recording was in progress. Pausing recording.")
camera.stop_recording()
recording = False
app.recording = False
else:
logging.warning("Door is open.")
# Check if any of the smartphones' Bluetooth addresses are visible or if they're connected to the AP
Expand All @@ -81,20 +66,13 @@ def start_flask_app():
logging.info("Device detected. Stop recording.")
camera.stop_recording()
recording = False
app.recording = False
# If no device is connected, start recording
else:
if not recording:
logging.info("Device not detected. Start recording.")
camera.start_recording(
f"./recordings/video_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.h264")
recording = True
app.recording = True
# Emit status to the client
if GPIO.input(Digital_Pin):
send_status_update('Door is closed.')
else:
send_status_update('Door is open.')
time.sleep(1)
except KeyboardInterrupt:
if recording:
Expand Down

0 comments on commit b40a5e8

Please sign in to comment.