60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
from flask import Flask
|
|
|
|
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
|
|
from services.mqtt_service import MQTTService
|
|
|
|
app = Flask(__name__)
|
|
|
|
screen = Screen()
|
|
mqtt_service = MQTTService("127.0.0.1", 1883)
|
|
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 exit_app():
|
|
rfid_reader.stop()
|
|
light_sensor_reader.stop()
|
|
exit()
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try :
|
|
print("Starting app...")
|
|
|
|
screen.enableBackground()
|
|
screen.displayMessage("Waiting for scan...")
|
|
|
|
print("Screen enabled.")
|
|
|
|
rfid_reader.subscribe(lambda uid: mqtt_service.publish(
|
|
"rpi", "/board-mate/rfid/scan", str(uid), 1
|
|
))
|
|
rfid_reader.start()
|
|
|
|
print("RFID reader started.")
|
|
|
|
light_sensor_reader.subscribe(lambda light_value: mqtt_service.publish(
|
|
"rpi", "/board-mate/light/notify", str(light_value), 0
|
|
))
|
|
light_sensor_reader.start()
|
|
print("Light sensor reader started.")
|
|
|
|
app.run(host="0.0.0.0", port=5000, debug=False)
|
|
|
|
except KeyboardInterrupt:
|
|
print("Keyboard interrupt. Stopping app...")
|
|
exit_app()
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
exit_app()
|