Closed mytechnotalent closed 3 years ago
When it goes offline this feed never is seen on the server.
I'm unsure what you mean by this. When your client goes offline, after a period the broker should publish to the topic myfeed
and the message should be picked up by all clients subscribed to that topic.
Which broker are you using? All testing was done with mosquitto.
Hi @peterhinch thank you for getting back so quickly! I am using the Adafruit IO. Perhaps this service is not compatible with the feature. If it is not do you have any suggestions how I might find a device offline?
Make sure you're matching the requirements stated here: https://io.adafruit.com/blog/tips/2016/06/24/last-will/
For example, it must be an abrupt disconnect, you cannot call disconnect() or close(), you must lose connection instead. The config you have looks correct Adafruit also requires 5 minutes before it publishes the LWT, and if you connect within that time it is not sent.
To reproduce, connect as you are, with your config correctly set as it is. Then disconnect the WiFi on what I assume is an ESP32, and then wait more than 5 minutes. You should see the LWT published under those conditions.
@nevercast I have killed the connection and it still have not published the LWT.
You might like to try https://test.mosquitto.org/ or https://www.hivemq.com/public-mqtt-broker/ or install your own MQTT server to test this separately from Adafruit to see if the issue is with the ESP32 or with the broker.
@mytechnotalent At risk of stating the obvious, it's worth bearing in mind how the last will (LW) feature works.
The client, on initial connection to the broker, sends a connect message informing it of its LW. From then on the broker maintains its own timeout on client connectivity. When the timeout occurs, the broker publishes the LW. The client firmware has stopped running long before this event occurs - after all, the plug may literally have been pulled. It would seem that failure modes are:
I think 1. and 2. are unlikely for two reasons.
I recommend testing with a different broker, preferably mosquitto as this was used for our testing. Either install a local version or adopt the suggestion of @nevercast and use the mosquitto public broker.
@peterhinch @nevercast I will try out Mosquitto. Thank you both for the help!
I have
will
enabled in myconfig.py
as such:config['will'] = ('myfeed', 'Offline', True, 1)
When it goes offline this feed never is seen on the server.