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

ESP32 connection failed (rc = -2) after 20 minutes aprox and can´t reconnect. #947

Open
IgnacioCipo opened this issue May 12, 2022 · 9 comments

Comments

@IgnacioCipo
Copy link

I'm using ESP32 with Platformio in Arduino code. I am sending information with a SIM800 through MQTT using Pubsubclient and TinyGSM to a .net broker using FreeRTOS. ESP32 starts and all works fine, I have a function to check if the MQTT connection is still ON, and if it disconnects, reconnects it. This is working, but after some time the MQTT connection is lost and it is not able to reconnect anymore. The only way to connect the ESP32 back to MQTT is rebooting it.
I´ve checked if the problem comes from the server side where the MQTT broker is, but it is not. When ESP32 is trying to reconnect, I´ve reset the server and the problem persist.
I´ve checked SIM800 connectivity and it algo is good.
This is my task that checks for MQTT connection each half minute.
image

This are the function calling to check MQTT:
image

image

I´ve been dealing with this problem too much time. I would appreciate any tips. Thanks!

@LaZorraTech
Copy link

Have you tried setting your KeepAlive to somethjng longer? Perhaps 45?

Also, I was having issues with PubSub and the current version of espressif32. In the platformio.ini file, I set my platform to:

platform = espressif32@^3.5.0

and my connection issues resolved. Good luck!

@IgnacioCipo
Copy link
Author

Have you tried setting your KeepAlive to somethjng longer? Perhaps 45?

Also, I was having issues with PubSub and the current version of espressif32. In the platformio.ini file, I set my platform to:

platform = espressif32@^3.5.0

and my connection issues resolved. Good luck!

Hi! I´ve tried setting KeepAlive to bigger values, but not changes. I will try changing my platformio.ini file, thank you for the advice!

@tablatronix
Copy link

Same, will not reconnect..

Oct 3 19:45:35 ESP_env 192.168.20.58 ESP:[INFO]- [MQTT] try client re-connect
Oct 3 19:45:38 ESP_env 192.168.20.58 ESP:[ERROR]- [ERROR] [MQTT] failed, rc=-2

@simogaspa84
Copy link

did you get any news on this @IgnacioCipo ?

@tablatronix
Copy link

Still no idea what the root cause is, really starting to piss me off

Screen Shot 2022-12-02 at 11 21 01 PM

@ZanzyTHEbar
Copy link

Same issue, MQTTBox and my other servers can connect to the broker just fine, esp can not.

@tablatronix
Copy link

tablatronix commented Jun 15, 2023

I have tried to debug this but it seems to be deep in the wificlient library and since these are all abstracted classes, I could not really follow it to where it was failing. I basically gave up as I spent too much time on it. Someone with knowledge of these classes might have better luck tracing it, or have actual debuggers setup.

I have a suspicion its a socket issue in the esp lib

@ZanzyTHEbar
Copy link

ZanzyTHEbar commented Jun 16, 2023

I ended up moving away from PubSubClient in favour of this library https://github.com/paclema/MQTTClient it works very well, and is even async on the ESP32. So far, i am really enjoying working with it, especially since it uses the espressif native mqtt api's.

@tablatronix
Copy link

@ZanzyTHEbar checking it out now, thanks!

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

5 participants