diff --git a/alert-scheduler/src/__init__.py b/alert-scheduler/src/__init__.py index 39ecfe8..8f2b1ad 100644 --- a/alert-scheduler/src/__init__.py +++ b/alert-scheduler/src/__init__.py @@ -1,10 +1,30 @@ import paho.mqtt.client as mqtt from alert import Alert +from mqtt_msg import MqttMsg +from datetime import datetime as dt #alerts : Alert = [Alert("JUST A TEST1"),Alert("JUST A TEST2")] alerts : Alert = [] +mqtt_msgs = {} + client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) client.connect("192.168.178.36",1884,keepalive=60) -client.publish("watchdog/alerts/status","Watchdog-Alerts starting up...") \ No newline at end of file +client.publish("watchdog/alerts/status","Watchdog-Alerts starting up...") + +def on_connect(client, userdata, flags, reason_code, properties=None): + client.subscribe(topic="#") + +def on_message(client, userdata, message, properties=None): + new_msg = MqttMsg(message.payload.decode("utf-8"), message.topic, dt.now()) + mqtt_msgs[message.topic] = new_msg + +def on_subscribe(client, userdata, mid, qos, properties=None): + pass + +client.on_connect = on_connect +client.on_message = on_message +client.on_subscribe = on_subscribe + +client.loop_start() \ No newline at end of file diff --git a/alert-scheduler/src/alert.py b/alert-scheduler/src/alert.py index 4e2893a..f2d27e4 100644 --- a/alert-scheduler/src/alert.py +++ b/alert-scheduler/src/alert.py @@ -1,6 +1,8 @@ +from dataclasses import dataclass +@dataclass class Alert(): - message = "" + message : str def __init__(self,message) -> None: self.message = message diff --git a/alert-scheduler/src/mqtt_msg.py b/alert-scheduler/src/mqtt_msg.py new file mode 100644 index 0000000..d56ad8f --- /dev/null +++ b/alert-scheduler/src/mqtt_msg.py @@ -0,0 +1,9 @@ +from dataclasses import dataclass +from datetime import datetime as dt + +@dataclass +class MqttMsg: + """Class for keeping track of an item in inventory.""" + message: str + topic: str + time_stamp: dt \ No newline at end of file diff --git a/alert-scheduler/src/update_alerts.py b/alert-scheduler/src/update_alerts.py index de62aaa..76cbb15 100644 --- a/alert-scheduler/src/update_alerts.py +++ b/alert-scheduler/src/update_alerts.py @@ -1,4 +1,4 @@ -from __init__ import alerts +from __init__ import alerts, client, mqtt_msgs class updateAlerts: @@ -10,5 +10,11 @@ class updateAlerts: def update(self): pass + def _store_active_alerts(self): + alerts = self.alerts.copy() + def _get_alerts(self): - self.alerts = alerts.copy() + pass + + def _get_all_message(self): + pass \ No newline at end of file