Add LWT for each device

This commit is contained in:
Meatballs1
2024-03-24 01:12:24 +00:00
parent 1087ce8a19
commit 0fe37f918b

View File

@@ -179,6 +179,7 @@ def client_connect(client, device, mqtt_topic):
while True:
msg = dev[device["name"]].recv()
client.publish(F"{mqtt_topic}/LWT", "online")
if msg is None:
break
if len(msg) > 0:
@@ -210,6 +211,7 @@ def client_connect(client, device, mqtt_topic):
except Exception as e:
print(device["name"], "ERROR", e, file=sys.stderr)
client.publish(F"{mqtt_topic}/LWT", "offline", retain=True)
time.sleep(40)