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

ESP8266 (nodemcu) send updates just once after startup #261

Open
andrewhack opened this issue Jul 11, 2024 · 1 comment
Open

ESP8266 (nodemcu) send updates just once after startup #261

andrewhack opened this issue Jul 11, 2024 · 1 comment

Comments

@andrewhack
Copy link

andrewhack commented Jul 11, 2024

I noticed an issue (not sure if is my mistake) when using the library with nodemcu, no updates are send after the first one at the initial startup. For example, similar code with Arduino works fine.
Any suggestions?

The code:

WiFiClient client;
HADevice device;
HAMqtt mqtt(client, device);
HASensorNumber Sensor("Sensor");

void setup() {
..................................................
  device.setUniqueId(mac, sizeof(mac));
  device.setName("controller");
  device.setSoftwareVersion("1.0.dummy");
  Sensor.setIcon("mdi:flash-triangle");
  Sensor.setName("Sensor");
..................................................
  mqtt.onConnected(onConnected);
  mqtt.onMessage(onMessage);
  mqtt.begin(BROKER_ADDR, BROKER_USERNAME, BROKER_PASSWORD);
...................................................

void loop() {
........................................................
  mqtt.loop();
........................................................
}
void onConnected() {
    Sensor.setValue(float(sensor));
}

void onMessage(const char* topic, const uint8_t* payload, uint16_t length) {
 .......................................................
}
@srsly4
Copy link

srsly4 commented Aug 13, 2024

I encountered the same with my BinarySensor on ESP-32.

MQTT Explorer sees all the messages but Home Assistant does not recognize them as state changes for some reason.

Update: I have no idea why but changing MQTT broker from nanomq to mosquito helped and now everything works.

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

2 participants