I have ESP32's that I got from amazon here: https://amzn.to/3QRS0Sn
I started with one 3 pack.
Working on a project for a while. Not important to the issue, but it controls a hacked electronic dog door, reads motion sensors inside and outside, an rfid tag to let the dog in and out and based on the pattern of what sensors trigger in what order - it knows if the dog actually went in or out or if the door just opened. With the ESP32, wifi access and twilo, it texts me status of the dog going in and out. And also has a little web server so I can log in to see status, open the door remotely, etc.
For weeks it was connecting to my network, getting the time, texting my phone, etc. No problem.
I'm not great with electronics and more of a software guy and I accidentally blew a couple of the ESPs. Dumb stuff. I test on the fly, plug in jumper cables, etc. One time I think pins touched each other. But anyway I fried 2 of them. But the 3rd one only has a bad RX2/TX2 because.. well.. I plugged them into the RFID 5v serial accidentally. It happens. But otherwise that one can still be programmed and run code.
Ok.. so I ordered a couple more 3 packs. And these just will not connect to wifi. I run the same code on them and they won't connect. But if I run the code on that 3rd one from the first batch - it connects fine right away. Same code.
I've been fighting with it all day. I reduced my code to just a simple Wifi connect. Actually because I was trying to figure out why it's happening, this code scans for networks, prints out when it sees my network name, then connects to a network with that name. The scanning is because the status I was getting after a fail was 1 which is WL_NO_SSID_AVAIL. So I did a scan to see if the SSIDs are available. Here's the test code:
#include "WiFi.h"
// Replace with your network credentials
const char* ssid = "Kermit";
const char* password = "password";
void setup() {
Serial.begin(9600);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
if(WiFi.SSID(i) == "Kermit")
{
Serial.println("Found Kermit");
}
}
}
Serial.println("Setup done");
}
void loop() {
if(WiFi.status() != WL_CONNECTED) {
initWiFi();
}
}
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
}
And here is what is output when I run it on that 3rd ESP32 from the first batch:
11 networks found
Found Kermit
Found Kermit
Found Kermit
Setup done
Connecting to WiFi ...192.168.124.201
It connects right away no problem - every time.
But if I use one of the newer ESP's:
19 networks found
Found Kermit
Found Kermit
Found Kermit
Setup done
Connecting to WiFi ............................
Notice that a different number of networks is found.. 11 on the old ESP vs 19 on the newer one. But actually every time I run it there's a different number of networks. So that might not mean anything.
And also that it finds my network 3 times because it is a mesh network and I have 3 nodes.
I tried 6 or 7 of the new boards and none of them will connect to my network. But if I load the sketch on the older one it connects fine. And this is with any of my test apps or even my full sketch that controls the dog door.
I tried connecting to my iPhone hot spot and that works fine on all of them.
So it would seem that it's something to do with my network but if so why does one ESP connect fine?
