Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

DougMcK
Posts: 4
Joined: Fri Aug 13, 2021 8:21 pm

Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby DougMcK » Fri Aug 13, 2021 8:39 pm

Hello!
Is there some sort of configuration that's needed to help the ESP32 to connect easily? I can easily get the ESP8266 to connect to my network, but multiple ESP32 boards have difficulty. I've tried two Sparkfun ESP32 Things, and also a couple of Heltec WiFi Kit32 boards. They can *sometimes* connect, so there's nothing grossly wrong with the code, and scanning for networks yields similar signal strengths that the ESP8266 sees (about -55).

The example below ( simplified from the Arduino WiFiClientBasic example) will connect sometimes, but not very often... This seems to me like a software, or configuration problem.

Any suggestions are gratefully received.
Doug

  1. #include <WiFi.h>
  2. #include <WiFiMulti.h>
  3.  
  4. WiFiMulti WiFiMulti;
  5.  
  6. void setup()
  7. {
  8.     Serial.begin(115200);
  9.     delay(10);
  10.  
  11.     // We start by connecting to a WiFi network
  12.     WiFiMulti.addAP("Correct_SSID", "Correct_Password");
  13.  
  14.     Serial.println();
  15.     Serial.println();
  16.     Serial.print("Waiting for WiFi... ");
  17.  
  18.     while(WiFiMulti.run() != WL_CONNECTED) {
  19.         Serial.print(".");
  20.         delay(500);
  21.     }
  22.  
  23.     Serial.println("");
  24.     Serial.println("WiFi connected");
  25.     Serial.println("IP address: ");
  26.     Serial.println(WiFi.localIP());
  27.  
  28.     delay(500);
  29. }
  30.  
  31.  
  32. void loop()
  33. {
  34.  
  35. }

khoih-prog
Posts: 53
Joined: Sat Feb 22, 2020 8:16 pm

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby khoih-prog » Tue Aug 17, 2021 12:38 am

Try this code. You don't need to call WiFiMulti.run() repetitively

Code: Select all

#include <WiFi.h>
#include <WiFiMulti.h>

WiFiMulti WiFiMulti;

#if ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_ESP32S2_THING_PLUS || ARDUINO_MICROS2 || \
      ARDUINO_METRO_ESP32S2 || ARDUINO_MAGTAG29_ESP32S2 || ARDUINO_FUNHOUSE_ESP32S2 || \
      ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM || ARDUINO_ESP32C3_DEV )
  #define WIFI_MULTI_1ST_CONNECT_WAITING_MS           500L
#else
  // For ESP32, must be >= 500
  #define WIFI_MULTI_1ST_CONNECT_WAITING_MS           800L
#endif

#define WIFI_MULTI_CONNECT_WAITING_MS                   500L

void setup()
{
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network
  WiFiMulti.addAP("Correct_SSID", "Correct_Password");

  Serial.println();
  Serial.println();
  Serial.print("Waiting for WiFi... ");

  int i = 0;

  uint8_t status = WiFiMulti.run();

  delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS);

  while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) )
  {
    status = WiFi.status();

    if ( status == WL_CONNECTED )
      break;
    else
      delay(WIFI_MULTI_CONNECT_WAITING_MS);
  }

  if ( status == WL_CONNECTED )
  {
    Serial.print(F("WiFi connected after time: ")); Serial.println(i);
    Serial.print(F("SSID: ")); Serial.print(WiFi.SSID()); Serial.print(F(", RSSI: ")); Serial.println(WiFi.RSSI());
    Serial.print(F("Channel: ")); Serial.print(WiFi.channel()); Serial.print(F(", IP address: ")); Serial.println(WiFi.localIP());
  }
  else
  {
    Serial.println(F("WiFi not connected"));
  }
}


void loop()
{

}

DougMcK
Posts: 4
Joined: Fri Aug 13, 2021 8:21 pm

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby DougMcK » Thu Aug 19, 2021 8:38 pm

Thanks for the reply.
I tried the code you posted, but unfortunately, I couldn't get the board to connect even once in the 12 resets I tried.

It's peculiar. I found the place in the building where the signal was strongest (about -39) and that didn't seem to help. The same router runs an open network (no password) and the ESP32 will connect to that quite easily.

The password is definitely correct, as proved by occasionally being able to connect to the network so it doesn't seen that the SSID or password are wrong, but that security might be involved somehow. Ok, now I am struggling to connect to the open network. This is too much of a time sink and quite frustrating. I'm close to giving up ad looking for a different platform.

One more thing. I'm powering from USB, but monitoring that voltage. It is good at 5.04V. Current consumption only seems to jump to 150mA briefly after reset. Mostly it is around 50mA while it is trying to connect.

khoih-prog
Posts: 53
Joined: Sat Feb 22, 2020 8:16 pm

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby khoih-prog » Fri Aug 20, 2021 5:38 pm

That's really strange as you said. I'm afraid there is something wrong with either your boards, WiFi router or noisy / overcrowded 2.4GHz bands. Also be sure the password is longer than 8 chars.

Please try to isolate.

I've tried here without any issue at all. You can try with different settings and see which is working better/faster for you, certainly after you've found out and fixed your WiFi culprit.

I'm using ESP32 core 2.0.0-rc1, ESP32 core 1.0.6 on ESP32_DEV

1) With

Code: Select all

#define WIFI_MULTI_1ST_CONNECT_WAITING_MS    2000L
#define WIFI_MULTI_CONNECT_WAITING_MS        1000L

Code: Select all

Waiting for WiFi... WiFi connected after time: 1
SSID: HueNet1, RSSI: -39
Channel: 2, IP address: 192.168.2.107
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13472
load:0x40080400,len:3668
entry 0x400805f0

#### Reset here

Waiting for WiFi... WiFi connected after time: 1
SSID: HueNet1, RSSI: -37
Channel: 2, IP address: 192.168.2.107
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13472
load:0x40080400,len:3668
entry 0x400805f0

#### Reset here

Waiting for WiFi... WiFi connected after time: 1
SSID: HueNet1, RSSI: -37
Channel: 2, IP address: 192.168.2.107
2) With

Code: Select all

#define WIFI_MULTI_1ST_CONNECT_WAITING_MS    800L
#define WIFI_MULTI_CONNECT_WAITING_MS        1000L

Code: Select all

Waiting for WiFi... WiFi connected after time: 2
SSID: HueNet1, RSSI: -43
Channel: 2, IP address: 192.168.2.107
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13472
load:0x40080400,len:3668
entry 0x400805f0

#### Reset here

Waiting for WiFi... WiFi connected after time: 2
SSID: HueNet1, RSSI: -38
Channel: 2, IP address: 192.168.2.107
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13472
load:0x40080400,len:3668
entry 0x400805f0

#### Reset here

Waiting for WiFi... WiFi connected after time: 2
SSID: HueNet1, RSSI: -35
Channel: 2, IP address: 192.168.2.107

DougMcK
Posts: 4
Joined: Fri Aug 13, 2021 8:21 pm

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby DougMcK » Fri Aug 20, 2021 9:50 pm

I haven't had too much time to spend on this but I did try a different ESP32 board. This board uses a ESP32-WROOM-32D module, and is branded Hiletgo ESP-32S.

Running the same code, this board connects *immediately* and reliably to this network.

So I can connect to the network easily with
1) several different ESP8266 boards.
2) the ESP32-WROOM-32D based board.

I cannot connect, except on rare occasions, connect using
1) Sparkfun ESP32 Thing boards (two of them)
2) Heltec ESP32 "WiFi Kit 32" boards (two of them)

I wonder if the module-in-a-can hardware is just much better, in certain circumstances, than the chip-on-a-board versions.

One thing I forgot to mention. I've tried both the most recent stable Arduino ESP32 board package and the most recent development board package. I couldn't see any difference.

khoih-prog
Posts: 53
Joined: Sat Feb 22, 2020 8:16 pm

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby khoih-prog » Sat Aug 21, 2021 2:41 am

module-in-a-can hardware is just much better, in certain circumstances, than the chip-on-a-board versions.
That's for sure and is the real culprit, especially in the noisy environment.

ullixesp
Posts: 83
Joined: Wed Oct 16, 2019 9:34 am
Location: Germany

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby ullixesp » Sat Aug 21, 2021 8:40 am

Are you by any chance being effected by the WiFi "Double-Hitting" issue? Lengthy discussion here: https://github.com/espressif/arduino-esp32/issues/2501

Are you using a FritzBox by any chance?

In short: under certain routers - new FritzBoxes in particular, but a few others also - and using the ESP32, not the ESP8266, you need 2 subsequent connection attempts to succeed in a WiFi connection. It should be gone with Arduino ESP32 code 1.0.6.

DougMcK
Posts: 4
Joined: Fri Aug 13, 2021 8:21 pm

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby DougMcK » Mon Aug 23, 2021 10:03 pm

I don't think it's the "double-hitter" problem, and I'm not using a FritzBox.

tfmeier
Posts: 1
Joined: Tue Nov 09, 2021 11:31 am

Re: Multiple ESP32 boards scan network, but struggle to connect. Configuration problem??

Postby tfmeier » Tue Nov 09, 2021 11:36 am

I struggle to connect on my ESP-WROOM-32 board (ESP32_Devkitc_v4) and get the following message. Sometimes it connects and sometimes it doesn't. No issue with ESP8266 boards so the network/AP is good.

Code: Select all

Connecting to WiFi AP
[E][WiFiMulti.cpp:55] addAP(): [WIFI][APlistAdd] no ssid or ssid too long
[E][WiFiMulti.cpp:55] addAP(): [WIFI][APlistAdd] no ssid or ssid too long
[E][WiFiMulti.cpp:187] run(): [WIFI] Connecting Failed (6).
.
 WiFi connected

 IP Address: 192.168.2.156
Is there any configuration for Wifimulti to adjust this? Given the chip connects sometimes makes me think this may be a timeout issue...

Who is online

Users browsing this forum: Bing [Bot] and 75 guests