Compare commits

..

No commits in common. "c8c96f30075362b310d46af460698b9a74686a35" and "c46657913921a8bcfddc0be68d7530974ca9b89d" have entirely different histories.

2 changed files with 3 additions and 8 deletions

View File

@ -45,8 +45,7 @@ def on_message(channel, method_frame, header_frame, body):
if msg_json['probability'] > 0.5: if msg_json['probability'] > 0.5:
r = requests.get(f"http://{config.INPUT_HOSTNAME}/sample/{msg_json['tag']}") r = requests.get(f"http://{config.INPUT_HOSTNAME}/sample/{msg_json['tag']}")
r.raise_for_status() r.raise_for_status()
mqtt.publish(subtopic=r.json()['device_id'], mqtt.publish(json.dumps({"deviceID": r.json()['device_id'], "sensorID": "", "command": "doAlert"}))
message=json.dumps({"command": "doAlert"}))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -61,14 +61,10 @@ class MQTT:
transport="tcp") transport="tcp")
self.client.connect(host=self.host, port=self.port, keepalive=60) self.client.connect(host=self.host, port=self.port, keepalive=60)
def publish(self, message: str, subtopic: str = "") -> None: def publish(self, message: str) -> None:
""" """
Publish a message Publish a message
:param message: :param message:
:param subtopic:
:return: :return:
""" """
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) self.client.publish(self.topic, message, qos=self.qos, retain=self.retain)