Hi… Im using MQTT on my ESP8266 that im flashing with Arduino IDE using PubSubClient library… When I boot the ESP8266 it always receives messages from my switch items in my sitemap even if i didnt changed them.
Im doing it simple, just subscribing 2 topics, one for each switch. But when it (ESP8266) connect to MQTT server, it receives 2 messages from the 2 topics saying 1.
I configured the bindings like this:
Is it possible you are configuring the topics to have “retained” messages? If so, when clients subscribe they will receive the last message published to the subscribed topic.
Connects the client with a Will message specified.
Parameters
clientID : the client ID to use when connecting to the server.
willTopic : the topic to be used by the will message (const char[])
willQoS : the quality of service to be used by the will message (int : 0,1 or 2)
willRetain : whether the will should be published with the retain flag (boolean)
willMessage : the payload of the will message (const char[])
Returns
false - connection failed.
true - connection succeeded
First, I should warn you that I’m not an expert on MQTT and it’s use in OH.
However, I believe those arguments are for the “last will and testament” message, which is something different.
When a message is published, the publisher sets a flag to indicate whether the message should be retained or not. In this case, OH is the publisher, right? There is a mqtt:.retain setting in openhab.cfg. If that is set to true, the messages will be published with the retain flag set.
I changed that in openhab.cfg. I set it false. And it keeps doing the same.
Everytime my ESP8266 reconnects to MQTT server. It receives the status of my switches.
Why? I don’t changed anything on the switch sides. It is supposed to receive the data (from my subscriptions) only when I change anything from the switch side (openHAB APP).