ESP32S3 suddenly cant connect to wifi

I have a project with about 20 devices running ESP32S3 connected to our WiFi. The wifi-signal is sometimes a bit weak and I have been working on a good way to make the devices regularly check for connection and reconnect if needed. Now while debugging I have found at least two devices that cant connect at all. It just keeps on scanning. If I just program a new microcontroller with the same program it works as it should. It is like it has been blocked. I'm using Unifi ecosystem and I cant find anywhere that it would be blocked.
During my programming it has been a lot of connection and diskonnections and then it suddenly stopped connect at all. My thought was if there is any limit on how many connection attempts that is allowed.

Any idea of what may cause this? And what is the best way of debugging wifi?

This suggests that your circuit is requiring more current than the powering circuits can manage, rather than any software issue.

I meant i tested connects and disconnects a lot during my programming and testing. It is like it suddenly got blocked. During my testing I am using the bare microcontroller connecting to USB. A simple program that only connects to wifi and outputs to serial console doesnt work om that board either. A new microcontroller from the same batch works as it should. I have a hard time to think that just the wifi-part of the microcontroller suddenly got faulty. I can still program the chip and serial output works as it should.

You did ask:-

and I told you.

If you don't appreciate free advice I will gladly refund what you paid for it.

I am sorry if I offended you. May I rephrase my reply then and ask what you mean by that my "cirquit is requiring more current than the powering cirquits can manage"? I have nothing connected to the board at all.

Ofcause there is a chance that the board is faulty, but bricking just the wifi-part of the ESP32S3 board just by connecting and disconnecting to wifi is something I havent see before.

It was a serious question and I am sorry I offended you by the way you responded.

1 Like

The most power hungry part of the board is the WiFi radio. Also, there is a phenomena that a WiFi device located in a place where there is a lot of WiFi does not connect. I don't know why but I had it happen with my new hearing aids. At the store they would not connect due to the presence of many other WiFi signals. I then had to leave for a hospital visit and while in the waiting room they suddenly connected since there was very little competing wifi there. Some devices just may not be able, buy more and cross your fingers.

so we also have ESP32S3 WiFi.h issues ON ONE NETWORK
( that special thing might be related to router / DNS / fixIP by MAC / OR NOT )
and sorry we also not find a good answer to that.
hope your not fed up with this responses here
may i ask if you have any news?

No real news. This problem have been with a handful of devices that we use. Usually I just swap the esp32s3 and it works again. Next time a problem occur I program the "faulty one" and it works again. Our 20+ machines that are monitored by this devices is reporting as it should, and suddenly it just tries to connect and fails over and over. A powercycle usually gets it online again, and a few times it wont come online again at all. Trying the same board a few days later and it works.

The whole system has been up and running for weeks now without problem so it isnt very easy to find the solution. :wink:

1 Like

Just a thought, can you check the logs of your UniFi devices to see what is happening on the router/AP side ?

By any chance, do you have multiple AP with same SSID, and your non-working devices might be trying to latch on to a distant AP?

1 Like

I have tried that but the logs doesnt say much useful. Just that it is disconnected. We have 9 accesspoints in the network and most of the devices is in reach of 2 or 3 accesspoints. The problem can occur when it looses connection to one AP and it tries to reconnect to another one. Like when rebooting the current AP.

So, I am somewhat happy with the stability as it is right now, but you always want to make the system better and more stable. :wink:

1 Like

I had a somewhat similar situation with one location with three AP's. What I did was to loop through all the same SSID's, and choose the one with the strongest signal.

1 Like

You mean letting the ESP scan and choose? Is there a way to do that from the ESP? isnt it in the wifi protocol that it connects to the strongest signal?

As it is right now the devices usually take the strongest one, but sometimes they stick to the one with weaker signal. I have then just locked it to the IP from within the Unifi interface and that works pretty good.

As far as my knowledge goes, it doesn't pick the one with strongest signal, it takes the first pick matching the SSID. What I have done is loop through all the set of SSID matching the network I want, sort it by signal strength, and the use its BSSID to connect to the strongest one.

I only have experience using Nano ESP32 using Arduino framework, so if you are using Espressif framework, your case might be different.

Im using the Arduino framework. Do you have any example code? That sounds like a possible solution for me that at least could address some of my other problems at least. :wink:

1 Like
// Scan for networks to get the BSSID with the strongest signal
    uint8_t bestBSSID[6];
    int32_t bestRSSI = -1000; // Initialize with a very low RSSI value
    bool bssidFound = false;
    int numNetworks = WiFi.scanNetworks();
    for (int i = 0; i < numNetworks; ++i) {
        if (WiFi.SSID(i) == networkSSID && WiFi.RSSI(i) > bestRSSI) {
            //WiFi.BSSID(i, bestBSSID);
            memcpy(bestBSSID, WiFi.BSSID(i), 6);
            bestRSSI = WiFi.RSSI(i);
            bssidFound = true;
        }
    }

    if (!bssidFound) {
        Serial.println(F("Failed to find BSSID for the specified SSID"));
        return -1;
    }

    // Connect to the WiFi network using the BSSID with the strongest signal
    WiFi.begin(networkSSID.c_str(), networkPassword.c_str(), 0, bestBSSID);
    unsigned long startAttemptTime = millis();

    // Wait for connection with timeout
    while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 30000) {
        delay(500);
        Serial.print(".");
    }

    if (WiFi.status() != WL_CONNECTED) {
        Serial.println("Failed to connect to WiFi within 30 seconds");
        return -1;
    }

    Serial.println("Connected to WiFi");
    return 0;

networkSSID & networkPassword are of String type and contain the SSID and password for the wifi network.

1 Like

I will definately try this in my project. Thankyou. It is not the solution for the initial problem but it might be related. If connecting to the best AP first the disconnects should be a lot fewer.

Thanks again.

update info from our ESP32S3 network problem:
our code allows also to burn
PICO (2)W
and test yesterday on that specific network
show instant connection / web-server and MQTT OK,
?NTP unusual slow?

do i have correct understanding that even both use
#include <WiFi.h>
that is a very different software for that 2 devices ESP32S3 and PICO 2W?

@amitabhkant
your SSID strong signal select code
we will test later

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.