-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (27 loc) · 998 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import threading
import time
from sensors.motion_sensor import motion_detection
from web.app import run_flask
from sensors.light_sensor import monitor_light_sensor
from sensors.temperature import monitor_temperature
try:
motion_thread = threading.Thread(target=motion_detection)
motion_thread.daemon = True # ensure thread exits when main program does
motion_thread.start()
flask_thread = threading.Thread(target=run_flask)
flask_thread.daemon = True
flask_thread.start()
light_sensor_thread = threading.Thread(target=monitor_light_sensor)
light_sensor_thread.daemon = True
light_sensor_thread.start()
temperature_sensor_thread = threading.Thread(target=monitor_temperature)
temperature_sensor_thread.daemon = True
temperature_sensor_thread.start()
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("Exiting program.")
finally:
from sensors.motion_sensor import stop_all
stop_all()
print("Program exited.")