Compare commits
2 Commits
c466579139
...
c8c96f3007
Author | SHA1 | Date | |
---|---|---|---|
c8c96f3007 | |||
3cd7167e90 |
@ -45,7 +45,8 @@ def on_message(channel, method_frame, header_frame, body):
|
||||
if msg_json['probability'] > 0.5:
|
||||
r = requests.get(f"http://{config.INPUT_HOSTNAME}/sample/{msg_json['tag']}")
|
||||
r.raise_for_status()
|
||||
mqtt.publish(json.dumps({"deviceID": r.json()['device_id'], "sensorID": "", "command": "doAlert"}))
|
||||
mqtt.publish(subtopic=r.json()['device_id'],
|
||||
message=json.dumps({"command": "doAlert"}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -61,10 +61,14 @@ class MQTT:
|
||||
transport="tcp")
|
||||
self.client.connect(host=self.host, port=self.port, keepalive=60)
|
||||
|
||||
def publish(self, message: str) -> None:
|
||||
def publish(self, message: str, subtopic: str = "") -> None:
|
||||
"""
|
||||
Publish a message
|
||||
:param message:
|
||||
:param subtopic:
|
||||
:return:
|
||||
"""
|
||||
self.client.publish(self.topic, message, qos=self.qos, retain=self.retain)
|
||||
if subtopic:
|
||||
self.client.publish(f"{self.topic}/{subtopic}", message, qos=self.qos, retain=self.retain)
|
||||
else:
|
||||
self.client.publish(self.topic, message, qos=self.qos, retain=self.retain)
|
||||
|
Loading…
Reference in New Issue
Block a user