Fixed potential crashes
This commit is contained in:
parent
a3d3b27817
commit
1f7f977e75
@ -64,11 +64,15 @@ def on_message_creator(mqtt_: MQTT):
|
|||||||
msg_json = json.loads(body)
|
msg_json = json.loads(body)
|
||||||
if 'probability' not in msg_json:
|
if 'probability' not in msg_json:
|
||||||
logging.error("Malformed message from broker")
|
logging.error("Malformed message from broker")
|
||||||
|
return
|
||||||
|
|
||||||
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()
|
||||||
if 'device_id' not in r.json():
|
if 'device_id' not in r.json():
|
||||||
logging.error("Input-service response invalid")
|
logging.error("Input-service response invalid")
|
||||||
|
return
|
||||||
|
|
||||||
logging.info(f"Sending alert command to device {r.json()['device_id']}")
|
logging.info(f"Sending alert command to device {r.json()['device_id']}")
|
||||||
mqtt_.publish(subtopic=r.json()['device_id'],
|
mqtt_.publish(subtopic=r.json()['device_id'],
|
||||||
message=json.dumps({"command": "doAlert"}))
|
message=json.dumps({"command": "doAlert"}))
|
||||||
|
Loading…
Reference in New Issue
Block a user