Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locally published topics do not appear to retain #65

Open
pklitscher opened this issue Jun 20, 2022 · 0 comments
Open

Locally published topics do not appear to retain #65

pklitscher opened this issue Jun 20, 2022 · 0 comments

Comments

@pklitscher
Copy link

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;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant