58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
|
|
from flask import Flask
|
|
from dotenv import load_dotenv
|
|
import broker_starter as bs
|
|
from hardware.light.lora_light_sensor_reader import LoraLightSensorReader
|
|
from hardware.screen.screen import Screen
|
|
from hardware.rfid.reader import RfidReader
|
|
from services.detection_service import DetectionService
|
|
|
|
load_dotenv()
|
|
app = Flask(__name__)
|
|
|
|
screen = Screen()
|
|
rfid_reader = RfidReader("/dev/serial0", 9600)
|
|
light_sensor_reader = LoraLightSensorReader("/dev/ttyUSB1", 9600)
|
|
|
|
detection_service = DetectionService()
|
|
|
|
@app.route("/party/start", methods=['POST'])
|
|
def start_party():
|
|
print("Party started!")
|
|
pass
|
|
|
|
def start_serial_devices():
|
|
screen.enableBackground()
|
|
screen.displayMessage("Waiting for scan...")
|
|
|
|
rfid_reader.subscribe(lambda uid: bs.local_broker.publish("/system/sensor/rfid", str(uid), 1))
|
|
rfid_reader.start()
|
|
|
|
light_sensor_reader.subscribe(lambda light_value: bs.local_broker.publish("/system/sensor/light", str(light_value), 0))
|
|
light_sensor_reader.start()
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try :
|
|
print("Starting app...")
|
|
|
|
bs.start()
|
|
print("Brokers started")
|
|
|
|
#start_serial_devices()
|
|
print("Serial devices started")
|
|
|
|
app.run(host="0.0.0.0", port=5000, debug=False)
|
|
|
|
except KeyboardInterrupt:
|
|
print("Keyboard interrupt. Stopping app...")
|
|
bs.stop()
|
|
exit()
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
bs.stop()
|
|
exit()
|