Wifi stops connecting after a while

I am running a sketch on Arduino Wifi. It connects via SSL to a website every ten minutes or so to update the status. After an indeterminate time and number of connections, it stops being able to connect. OK, so there's a resource leak somewhere.

Here's where it gets strange. I first ran this sketch on a version R2 Uno. In that version, I found that if I kept track of the number of unsuccessful connections in a row, I could just reset the the Arduino and the Wifi would start working again. In R2 I could jump to address zero and the Arduino would reboot.

In R4 that no longer works. There is a new function to reboot the Arduino,
NVIC_SystemReset();

However, that doesn't reset the Wifi, once I start having connection issues the only solution is to power off the Arduino and power it on again. Since I'm trying to use it for remote monitoring that's kind of a problem.

Very similar to what's happening in this thread:

However, in that thread he found that calling WiFiClass::end() would reset the Wifi and allow it to connect again. I have not found that to be the case.

I've been tracking this for almost two years and it's pretty frustrating. At this point I'm thinking the best solution may be to plug the power supply into a wall timer and turn it off for ten minutes every 24 hours.

1 Like

For the UNO R4, try to downgrade and then upgrade the connectivity firmware following Update the connectivity module firmware on UNO R4 WiFi. After this, try connecting the board to the IoT cloud to test it.

Well that was a merry adventure.

So I tried to downgrade the firmware. The upload failed and my board stopped being recognized as a USB device. I had to follow the instructions here: https://support.arduino.cc/hc/en-us/articles/9670986058780-Update-the-connectivity-module-firmware-on-UNO-R4-WiFi to manually reload the connectivity firmware.

When I got it back working the firmware version was back to 3.0. The unit had been 2.1 when I acquired it, I had updated it to 3.0.

Is the purpose of the downgrade/upgrade to insure that the upgrade is in fact the most recent version and not being mis-reported?

If you have recovered the board following the guide you mentioned, then use only 2.4Ghz wifi and do not use SSID or password that is too long or have special characters.
Try connecting it to the IoT cloud, if it connects, then the issue is your initial sketch or your wifi settings.

Reading that, I don't think you read closely what I wrote. It's not a simple binary on/off connect or not connect. I can have thousands of successful connections in a row, but once it starts having connection issues the only solution is a power-off reset.

I think the issue is that there is a separate ESP32 co-processor just for WiFi, and resetting the main processor doesn't reset that.

So an update, kind of. I got tired of messing around with the Uno R4 and bought a Giga Wifi. I uploaded the same code. It was much more reliable, but after banging a server every 30 seconds for a few days I figured out that if the server unexpectedly disconnected -- WiFiSSLClient::connected() returns false when you're expecting more -- you have to call WiFiSSLClient::stop() to free up the socket. Otherwise you run out of sockets. I made that change and my code ran for days with no problems.

On the Giga that is. I uploaded that same code to the Uno R4 and still experienced problems with refused connections. My change may have helped the Uno -- that's why I'm posting this, to help anyone who comes along following me -- but I'm done with the Uno. I know the Giga is $45 dollars more, but it works. The Uno is just too flaky.

1 Like