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