Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the twentysixteen domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /usr/share/wordpress-www.bakke.online/wp-includes/functions.php on line 6114
MQTT – OppoverBakke

Adding retained messages to Adafruit's MQTT library

Recently, when building a weather station based on Adafruit’s Huzzah ESP8266 breakout board, I needed the ability to send messages that should be retained on the MQTT server.

I am using mosquitto on my home server, acting as a message broker.  My weather stations send messages to it and these are then forwarded to the subscribers who have signed up for them.  At the moment, these subscribers are a weather logging system, a current weather display panel on the different computers at home, and, occasionally, a command-line client used for troubleshooting.

As the weather stations are battery powered, they will not run always on, always connected, but they wake up every few minutes, check the weather, and transmit the results to the MQTT server before they go to sleep again.

Any subscribers will receive these messages as soon as they are sent.  However, when a subscriber starts running and connects to the MQTT server, it will not receive any messages until the relevant weather station sends one.  By default, there’s no concept of the most recent values.  This is kind of inconvenient for the weather panel application on the computers, as they will not show any values until the next time the weather station wakes up.  Depending on the battery levels and configuration, that could be quite a while…

Continue reading “Adding retained messages to Adafruit's MQTT library”