uMQTTBroker
uMQTTBroker copied to clipboard
Locally published topics do not appear to retain
I am sure I am missing something very obvious here but for the life of me I cannot get locally published messages to retain.
I have setup the broker on a ESP8266 NodeMcu. I have connected to the broker using MQTT explorer . Everything is working great.
However, when I try to publish a retained message locally (from the ESP8266) it is not retained. It will appear in the explorer but if I disconnect and connect again it is gone. Using virtual bool publish(String topic, String data, uint8_t qos=0, uint8_t retain=0);
If I publish a retained message from MQTT explorer (i.e. button2/state: OFF) it will retain and persist disconnection and connection.
Am I missing something obvious here?
Below is a cut down of the code.
#include <ESP8266WiFi.h>
#include "uMQTTBroker.h"
uMQTTBroker myBroker;
void startWiFiClient(){
// WiFi init stuff
}
void setup(){
startWiFiClient();
myBroker.init();
}
int buttonState;
void loop(){
int read = digitalRead(0);
if (buttonState != read) {
myBroker.publish("button/state", read ? "ON" : "OFF" , 2, 1);
buttonState = read;
}
}