Skip to content
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

Issue while setting keep alive zero. #1033

Open
kabirwbt opened this issue Nov 12, 2023 · 2 comments
Open

Issue while setting keep alive zero. #1033

kabirwbt opened this issue Nov 12, 2023 · 2 comments

Comments

@kabirwbt
Copy link

kabirwbt commented Nov 12, 2023

On my esp8266, If I set the keep alive parameter to zero and connect to a broker, despite being connected to broker successfully, connected() returns false and my reconnect loop triggers automatically. I compiled the example provided in the following link : https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_esp8266/mqtt_esp8266.ino.

I just added the following line to void setup(), at the absolute bottom: client.setKeepAlive(0);

Attempting MQTT connection...connected Attempting MQTT connection...connected
This message is printed in a rapid manner, infinitely.

Am I doing something wrong? Should connected() not return true in my case?

@kabirwbt
Copy link
Author

kabirwbt commented Nov 12, 2023

My guess is that some other block of code, maybe the ping mechanism is disconnecting the client and causing the connected() to return false.
EDIT:
after some digging:

_client->stop();
is causing the connection to close. Shouldn't the pinging mechanism be disabled via setting the keepalive parameter to 0 ?

@ChuckMash
Copy link

Yep, looks like keepalive 0 is not correctly respected.

Try changing the following line

if ((t - lastInActivity > this->keepAlive*1000UL) || (t - lastOutActivity > this->keepAlive*1000UL)) {

to

if (((t - lastInActivity > this->keepAlive*1000UL) || (t - lastOutActivity > this->keepAlive*1000UL)) && keepAlive != 0) {

I've not done any long term testing, but I'm having no issues with this change so far.

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

2 participants