Mark as offline when the MQTT connection is lost

This commit is contained in:
Correl Roush 2023-05-18 14:50:49 -04:00
parent c1a8872962
commit 49396869d5

View file

@ -87,6 +87,7 @@ def loop():
print("Starting MQTT client") print("Starting MQTT client")
mqtt = MQTTClient(mqtt_client_id, mqtt_broker, keepalive=MQTT_KEEPALIVE) mqtt = MQTTClient(mqtt_client_id, mqtt_broker, keepalive=MQTT_KEEPALIVE)
mqtt.set_callback(on_message) mqtt.set_callback(on_message)
mqtt.set_last_will(f"{mqtt_prefix}/status", b"offline", retain=True)
mqtt.connect() mqtt.connect()
mqtt.subscribe(f"{mqtt_prefix}/set") mqtt.subscribe(f"{mqtt_prefix}/set")
mqtt_device = { mqtt_device = {