Properly Setting up Last Will Message
Opened this issue · 3 comments
In example:
https://github.com/tuanpmt/ESP8266MQTTClient/blob/master/examples/MQTTClient/MQTTClient.ino#L32
The last will message is set up without referring to the keepalive argument as specified in:
https://github.com/tuanpmt/ESP8266MQTTClient/blob/master/src/ESP8266MQTTClient.cpp#L72
The example should probably be changed to include the keepalive (& cleansession), so predictable behaviour can be expected with the last will messages. Otherwise, the last will msg seems to be sent and printed in the topic before any other messages, whenever the connection is created.
Hi, I am setting up method with keepalive and cleansession. When I turn off my device I still don't get any msg from lwt.
This is my "begin" configuration, but it doesn't work.
mqtt.begin(mqtt_broker_server, {.lwtTopic = status_topic, .lwtMsg = "offline", .lwtQos = 0, .lwtRetain = 1}, 600, false);
Is it something in common that keepalive here is specified in milliseconds, and default keepalive in mosquitto broker is in seconds. Or I am wrong?
If someone can help, I will be happy.
Hi, I am setting up method with keepalive and cleansession. When I turn off my device I still don't get any msg from lwt.
This is my "begin" configuration, but it doesn't work.
mqtt.begin(mqtt_broker_server, {.lwtTopic = status_topic, .lwtMsg = "offline", .lwtQos = 0, .lwtRetain = 1}, 600, false);
Is it something in common that keepalive here is specified in milliseconds, and default keepalive in mosquitto broker is in seconds. Or I am wrong?
If someone can help, I will be happy.
I strongly recommend checking out PubSubClient
It's much more mature and behaves more predictably for MQTT stuff. If your payload sizes are greater than 128 characters, you'll have to edit this in the header files
I changed PubSubClient lib with this one, because it support all qos levels and wifisecure. I am still searching for the perfect one.
I think I found solution for my problem. I replace this line in ESP8266MQTTClient.cpp
_connect_info.keepalive = _keepalive;
with this one
_connect_info.keepalive = _keepalive / 1000;
I am using mosquitto for broker and i just converting the milliseconds to seconds in connect data.