Skip to content

mqtt keep alive timer is not correct #1553

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

Closed
lepass7 opened this issue Oct 22, 2016 · 6 comments
Closed

mqtt keep alive timer is not correct #1553

lepass7 opened this issue Oct 22, 2016 · 6 comments

Comments

@lepass7
Copy link

lepass7 commented Oct 22, 2016

Expected behavior

When the esp8266 loses wifi communication it should activate the m:on("offline" ... after 120 Seconds (according to the following example)

Actual behavior

The offline event activates randomly and after 10-15 minutes

Test code

-- init mqtt client with keepalive timer 120sec
m = mqtt.Client("clientid", 120, "user", "password")

-- setup Last Will and Testament (optional)
-- Broker will publish a message with qos = 0, retain = 0, data = "offline" 
-- to topic "/lwt" if client don't send keepalive packet
m:lwt("/lwt", "offline", 0, 0)

m:on("connect", function(client) print ("connected") end)
m:on("offline", function(client) print ("offline") end)

NodeMCU version

master
powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)

Hardware

esp8266-12e

@NicolSpies
Copy link

I experience the same and I link this to the method used in #1555 to determine if a MQTT connection is present before trying to publish a message.

@pjsg
Copy link
Member

pjsg commented Oct 23, 2016

From looking at the code, it appears that the timeout handling is missing. After the keepalive time it sends the PINGREQ -- which should the cause the server to send PINGRESP. The client is supposed to wait for up to keepalive time for the PINGRESP and abort the connection if nothing is received. However, I can't see the code that does this...

@pjsg
Copy link
Member

pjsg commented Oct 23, 2016

If somebody can try this fix #1557 in their test environment, that would be great. It appeared to work with a simple test case....

@NicolSpies
Copy link

@pjsg, I have 3 units in the field connected via 3G that experience MQTT disconnects due to the connection. I will test on the units. Unfortunately can only get to them in a few days to upload new build.
Agh!!, I forgot, you now my challenge, I will only be able to test after a merge to dev enabling me to do a custom build.

@marcelstoer
Copy link
Member

Agh!!, I forgot, you now my challenge, I will only be able to test after a merge to dev enabling me to do a custom build.

Sounds vaguely familiar...For some reason the Docker image doesn't work for you? I'll send you an email with firmware of the PR.

@lepass7
Copy link
Author

lepass7 commented Nov 15, 2016

@pjsg I tried fix #1557 but unfortunately the keep alive timer is still not working correct.
With this fix I noticed that esp is disconnecting and reconnecting all the time with a period of 41-42 secs

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

4 participants