-2

I have simple MQTT application on Arduino ESP8266 device. Can't find why code line below not formats MQTT retain message:

 pubsubClient.publish(topic.c_str(), payload.c_str(), true);

Message just not delivered to remoter device after it is connected after some delay when message was transmitted from ESP8266. Software MQTT client that works on PC works fine in this case.

vico
  • 17,051
  • 45
  • 159
  • 315
  • 1
    Also clarify the question, are you seeing the message published if the subscriber is online at the time the message is published? But you are just not receiving the retained message if you subscribe to the topic later? – hardillb Apr 09 '20 at 11:44
  • 1
    If you turn on the verbose logging in mosquitto it will show you if the message is received by the broker with the retained bit set. As it is we can't possibly answer this question as we have no where near enough information. – hardillb Apr 09 '20 at 12:44

1 Answers1

1

I have corrected code line to :

 if (pubsubClient.publish(topic.c_str(), payload.c_str(), retained))

and now it works.

It was new to me that if expression below is valid

if (true,true)
{
}
vico
  • 17,051
  • 45
  • 159
  • 315
  • 1
    This is why you should have posted more context for the code, since the original question did not include the if statement. Please include a LOT more context next time. – hardillb Apr 09 '20 at 12:56