Open dervur opened 3 years ago
I'm too lazy to dig in your code and find what you are doing for you. If you believe either the client or the library does not work properly then write the smallest possible example where this can be reproduced, post how you call the client or the library, what you get back, and confirm that with a network capture showing the flag is indeed not as it should.
This is the specific code I used to send the message:
//Publish first message "online"
void msg_online()
{
MQTT::Message message_pub;
//Topic
const char* topic = "EE579/ESP01/status";
//Payload
const char* message = "online";
char payload[100];
snprintf(payload, strlen(message)+1, "%s", (char*)message);
message_pub.payload = (void*)payload;
message_pub.payloadlen = strlen(payload);
//Settings
message_pub.qos = MQTT::QOS1;
message_pub.retained = true;
message_pub.dup = false;
//Publish message
int rc = client.publish(topic, message_pub);
}
In the library struct Message, retained is bool, whence I set it correctly setting it to true. The publish function I call, in the library is declared as:
template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE, int b>
int MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::publish(const char* topicName, Message& message)
{
return publish(topicName, message.payload, message.payloadlen, message.qos, message.retained);
}
This HiveMQ public client shows if the message is retained, as you can see there is a previously published online that is retained, but the new one not. As I said, sometimes it publishes it retained but 99% of the times not... I guess it's a problem of the library, because if with the same code sometimes the message is retained but many times not, the code should be right I guess....
Hello there,
I'm trying to use a modified version of the sample code for Arduino (I'm using an ESP01 with arduino's framework) however, if I try to retain the messages as I did below in msg_online() and in the last will, they are published as not retained 99% of time. Every once in while they are set as retained, but it a very very rare case. Would you know where the problem in my code is or suggest some solutions?
This is my code below (I only cleared my Wifi and personal broker fields for privacy reasons, but I have the problem both with my broker and with hiveMQ's public broker, so I left only hivemq's broker field):
Kind regards, Vur