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

MQTT connection not always working #79

Closed
lucwuyts opened this issue Feb 18, 2017 · 14 comments
Closed

MQTT connection not always working #79

lucwuyts opened this issue Feb 18, 2017 · 14 comments
Labels
bug Type - Confirmated Bug enhancement Type - Enhancement that will be worked on

Comments

@lucwuyts
Copy link

When i restart the sonoff, the MQTT connection is immediately ok.

But after a few seconds i often see these messages:

MQTT: Attempting connection...
MQTT: CONNECT FAILED, rc -2. Retry in 10 seconds

Return code 2 is Connection Refused, identifier rejected

during this experiment there was only ESP device active

Is this a configuration issue on the broker ?

@lucwuyts
Copy link
Author

I recompiled with version 3.9.17 and used the same user_config.h and it is working as it should!

@lucwuyts
Copy link
Author

Today, I've seen this errors again.
My MQTT broker is mosquitto (on windows)

Error messages on the sonoff device:
14:56:23 MQTT: Attempting connection...
14:56:29 MQTT: CONNECT FAILED, rc -2. Retry in 10 seconds

Firmware is not changed.

@lucwuyts lucwuyts reopened this Feb 20, 2017
@lucwuyts
Copy link
Author

I think the keep-alive pings are sometimes not sent

This is what i see on the broker side

Client DVES_82579D has exceeded timeout, disconnecting.
Socket error on client DVES_82579D, disconnecting.

@lucwuyts
Copy link
Author

And when the connection is accepted on the broker, the sonoff dos not always respond

1487600218: New connection from 10.0.250.72 on port 1883.
1487600218: New client connected from 10.0.250.72 as DVES_82579D (c1, k15, u'mqtt-user').
1487600218: Sending CONNACK to DVES_82579D (0, 0)
1487600239: Client DVES_82579D has exceeded timeout, disconnecting.
1487600239: Socket error on client DVES_82579D, disconnecting.

@arendst
Copy link
Owner

arendst commented Feb 21, 2017

Still need to investigate but did you make any changes to pubsubclient.h define MQTT_SOCKET_TIMEOUT?

I used it as set to 2 seconds for a while to satisfy non MQTT users but I will now set it back to 15.

Can you verify your compiles did use the 15 second value and still observe the problem you see?

@lucwuyts
Copy link
Author

The library defines it to 15.
And according to the mosquitto-verbose output, it is indeed every 15 seconds.

This problem is not constant, and i begin to think actions in the web interface of the sonoff sometimes are causing this.

arendst added a commit that referenced this issue Feb 24, 2017
3.9.21 20170224
* Add ajax to web root page and web console (#79)
* Add commands SwitchMode1..4 and enable user switches 2, 3 and 4 (#84,
#88)
* Fix MQTT upgrade when webserver is active
@arendst
Copy link
Owner

arendst commented Feb 24, 2017

I think it is webserver related too. Did a rewrite of the page refresh using ajax. Let's see if it was for the good.

Implemented in version 3.9.21 just released.

@arendst arendst added bug Type - Confirmated Bug enhancement Type - Enhancement that will be worked on labels Feb 24, 2017
@lucwuyts
Copy link
Author

Yes, I think it is better now.
Tried a few times: reboot and have the web-console screen open.
After a few attempts to connect (with the same error message as before), it now succeeds, and looks (for now) a stable connection.

@arendst arendst closed this as completed Mar 9, 2017
@Sunrise17
Copy link

Is it possible to increase MQTT_KEEPALIVE from 15secs to 60secs from Web-Console with MQTT command?

@Sunrise17
Copy link

i need to increase MQTT_KEEPALIVE to 60 secs, which is arranged 15secs in Sonoff Basic Tasmota FW?

@Sunrise17
Copy link

My MQTT broker (on Pi) MQTT_KEEPALIVE's setting is already 60secs

@ghost
Copy link

ghost commented Jan 4, 2018

@Sunrise17 Please open your own thread so it can be discussed in there.

ascillato added a commit that referenced this issue Jun 5, 2018
curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 6, 2018
3.9.21 20170224
* Add ajax to web root page and web console (arendst#79)
* Add commands SwitchMode1..4 and enable user switches 2, 3 and 4 (arendst#84,
arendst#88)
* Fix MQTT upgrade when webserver is active
curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 7, 2018
arendst pushed a commit that referenced this issue May 25, 2020
@careyer
Copy link

careyer commented Jun 17, 2020

I am sorry to re-activate this issue @arendst but I am seeing the exact same problems like @lucwuyts on my Sonoff-Tasmota 6.6.0 (which from what I can tell is way newer than 2017).

09:45:45 WIF: Checking connection...
09:45:45 WIF: Connected
09:45:47 MQT: Attempting connection...
09:45:52 MQT: Connect failed to 192.168.68.112:1883, rc -2. Retry in 10 sec

After reboot the system will work well for some hours and then continuously fail with these errors.
What does the return code rc -2 exactly mean?

Any ideas how to solve this?
Thanks!
Best regards
Thomas

@ascillato
Copy link
Contributor

Please, address this to the Tasmota Support Chat. The chat is a better and more dynamic channel for helping you. Github issues are meant for Tasmota Software Bug Reporting.

Please check the Contributing Guideline and Policy and the Support Guide.

Thanks.


Support Information

See Wiki for more information.
See FAQ for common questions/answers and links if none of your question is in the list
See Chat for more user experience.
See Community for forum.
See Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type - Confirmated Bug enhancement Type - Enhancement that will be worked on
Projects
None yet
Development

No branches or pull requests

5 participants