mysensors / MySensors

MySensors library and examples
https://www.mysensors.org
1.32k stars 895 forks source link

MQTT Gateways don't support Last Will and Testiment/Keep Alive #1411

Open Cloolalang opened 4 years ago

Cloolalang commented 4 years ago

Mysensors/gateway/Transport/MQTT-pubsubclient/Lastwill

It would be very cool if the MQTT gateway could offer the option for Last Will so that our controllers can monitor and alert to loss of MQTT connection.

Pubsubclient API offers this feature already.

https://pubsubclient.knolleary.net/api.html

Cloolalang commented 4 years ago

I've been working on this. it seems to be working OK, I have found that I needed to add a publish MQTT "online" message to the LWT topic just after _MQTT_client.connect in MyGatewayTransportMQTTClient.cpp to set up the LWT topic with an inital message. And, I am publishing "online" every minute in my main gateway sketch to maintain it. ( I found that if I reset my MQTT broker, or Controller client (Hassio) the LWT topic sometimes comes up with no message "online")

How it looks on Hassio Dashboard:

image

P