ESP sleep state problem and resolution

A project log for ESP8266 MQTT Infrared AirCon Control

An amateur build of a monitoring and control system for the aircon in my baby's room, using an ESP8266, IR Led, JSON and MQTT protocol.

ShoeboxShoebox 12/01/2017 at 12:240 Comments

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.