Added subscription to all mqtt messages
This commit is contained in:
@@ -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...")
|
||||
|
||||
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()
|
||||
@@ -1,6 +1,8 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Alert():
|
||||
message = ""
|
||||
message : str
|
||||
|
||||
def __init__(self,message) -> None:
|
||||
self.message = message
|
||||
|
||||
9
alert-scheduler/src/mqtt_msg.py
Normal file
9
alert-scheduler/src/mqtt_msg.py
Normal file
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user