A while back, to extend the battery life on the esp8266, I added the sleep function, so every few minutes the ESP wakes up, check the retained message on the MQTT queue, processes and goes back to sleep. The lag of a couple of minute is an okay trade off for extended battery life,
However there was a problem. The every time the esp wakes up a new wifi and MQTT connection is established, and the retained message was reprocessed. So 2 weekends ago I finally had time to read up on MQTT. Turns out it is a very simple fix, writing back a 0 byte MQTT message with retain flag on to the queue clears the queue.
So I modified my code to, clear the queue before the ESP goes to sleep, and the state problem was resolved.
I also soldered up a new prototype, this one is a hat for Wemos D1. IT works great, and the serial interface is a lot easier to debug than the esp-01 board I made. Great for tracking down bugs.
Now on to test the battery life.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.