ESP32 WiFi Connection Fails every other re-boot

My very simple Blynk examples always fail to connect to my wifi network every other time of re-booting. It is quite consistent. First the connection dialogue stalls at connecting to DAVETT (my SSID). Re-booting repeats and connects correctly. Re-booting again repeats the failure, and so on. It’s too consistent to be a random connection issue. Am I missing something?

Serial Dialogue:
13:26:19.022 -> ets Jun 8 2016 00:22:57
13:26:19.022 ->
13:26:19.022 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
13:26:19.022 -> configsip: 0, SPIWP:0xee
13:26:19.022 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
13:26:19.022 -> mode:DIO, clock div:1
13:26:19.069 -> load:0x3fff0018,len:4
13:26:19.069 -> load:0x3fff001c,len:1216
13:26:19.069 -> ho 0 tail 12 room 4
13:26:19.069 -> load:0x40078000,len:9720
13:26:19.069 -> ho 0 tail 12 room 4
13:26:19.069 -> load:0x40080400,len:6352
13:26:19.069 -> entry 0x400806b8
13:26:19.303 -> [33] Connecting to DAVETT
STALLS HERE - SO RE-BOOT*******
13:26:26.133 -> ets Jun 8 2016 00:22:57
13:26:26.133 ->
13:26:26.133 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
13:26:26.133 -> configsip: 0, SPIWP:0xee
13:26:26.133 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
13:26:26.181 -> mode:DIO, clock div:1
13:26:26.181 -> load:0x3fff0018,len:4
13:26:26.181 -> load:0x3fff001c,len:1216
13:26:26.181 -> ho 0 tail 12 room 4
13:26:26.181 -> load:0x40078000,len:9720
13:26:26.181 -> ho 0 tail 12 room 4
13:26:26.181 -> load:0x40080400,len:6352
13:26:26.181 -> entry 0x400806b8
13:26:26.415 -> [33] Connecting to DAVETT
13:26:26.977 -> [608] Connected to WiFi
13:26:26.977 -> [608] IP: 192.168.1.33
13:26:26.977 -> [608]
13:26:26.977 -> ___ __ __
13:26:26.977 -> / _ )/ /_ _____ / /__
13:26:26.977 -> / _ / / // / _ / '/
13:26:26.977 -> /
//_, /////_
13:26:26.977 -> /
__/ v0.6.1 on ESP32
13:26:26.977 ->
13:26:26.977 -> [613] Connecting to blynk-cloud.com:80
13:26:27.071 -> [704] Ready (ping: 39ms).

Are you using Blynk.begin in your sketch?

Pete.

I am indeed Pete:

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  //Pullup on IP34 (not by default)
  pinMode(34,INPUT_PULLUP);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

You could try enabling verbose debugging in the IDE, and see what you get regarding WiFi when the first attempt fails.

Pete.

How is it enabled Pete?

Many thanks. Will try.

Okay - tried and doesn’t reveal a great deal.

Here’s a successfull connect:

And a failure:
image

Just noticed that on the failed dialogue, it goes WIFI_READY, STA_START, STA_DISCONNECTED, AUTH_FAIL.
On the successful dialogue, it goes WIFI_READY, STA_START, STA_CONNECTED, STA_GOT_IP.
Could it simply be that because I’m not properly disconnecting each time I re-boot, the next STA_START results in the AP toggling to disconnect?
Is there some sort of routine I could include in startup that ensure a proper disconnection, before re-connection?
Or simply a repeated attempt on receipt of the AUTH_FAIL response?

I don’t think so.

It doesn’t look like a Blynk issue to me, more like either a hardware or WiFi router issue.
Have you tried rebooting your router?

Pete.

I can try that. Currently looking at Blynk.begin to see if I can trap the AUTH_FAIL and force a re-try.
Dave

I realise I haven’t read the documentation well enough (RTFM!), so will do some more bedtime reading. The clue is to break down my use of the Blynk.begin into Blynk.connect, etc, so can trap failures. Also use the server connect and disconnect functions so that the internet activity only occurs when I’m running the app. This should sort me, once I fully understand it.

Okay, have just returned to this after completing the original project using an ESP2866. This worked perfectly and would connect faultlessly with my WiFi network on every reset - so not a router issue. I loaded the very basic ESP32_WiFi sketch from the Blynk library and the problem is back.
Here’s the failed dialogue:
12:16:45.425 -> ets Jun 8 2016 00:22:57
12:16:45.425 ->
12:16:45.425 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
12:16:45.472 -> configsip: 0, SPIWP:0xee
12:16:45.472 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
12:16:45.472 -> mode:DIO, clock div:1
12:16:45.472 -> load:0x3fff0018,len:4
12:16:45.472 -> load:0x3fff001c,len:1216
12:16:45.472 -> ho 0 tail 12 room 4
12:16:45.472 -> load:0x40078000,len:9720
12:16:45.472 -> ho 0 tail 12 room 4
12:16:45.472 -> load:0x40080400,len:6352
12:16:45.472 -> entry 0x400806b8
12:16:45.706 -> [32] Connecting to DAVETT

It stops at this point , seeming to get no response from the router.
Pressing reset then produces the correct connection:

12:17:42.981 -> ets Jun 8 2016 00:22:57
12:17:42.981 ->
12:17:42.981 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
12:17:42.981 -> configsip: 0, SPIWP:0xee
12:17:42.981 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
12:17:42.981 -> mode:DIO, clock div:1
12:17:42.981 -> load:0x3fff0018,len:4
12:17:42.981 -> load:0x3fff001c,len:1216
12:17:42.981 -> ho 0 tail 12 room 4
12:17:42.981 -> load:0x40078000,len:9720
12:17:42.981 -> ho 0 tail 12 room 4
12:17:42.981 -> load:0x40080400,len:6352
12:17:42.981 -> entry 0x400806b8
12:17:43.215 -> [32] Connecting to DAVETT
12:17:43.825 -> [608] Connected to WiFi
12:17:43.825 -> [608] IP: 192.168.1.33
12:17:43.825 -> [608]
12:17:43.825 -> ___ __ __
12:17:43.825 -> / _ )/ /_ _____ / /__
12:17:43.825 -> / _ / / // / _ / '/
12:17:43.825 -> /
//_, /////_
12:17:43.825 -> /
_/ v0.6.1 on ESP32
12:17:43.825 ->
12:17:43.825 -> [613] Connecting to blynk-cloud.com:80
12:17:43.872 -> [679] <[1D|00|01|00] UlmMOwmt5fGF
**********************
12:17:43.918 -> [711] >[00|00|01|00|C8]
12:17:43.918 -> [711] Ready (ping: 31ms).
12:17:43.918 -> [711] >[14|00|01|00|08]
12:17:43.918 -> [712] >pm[00]0[00]out
12:17:43.965 -> [778] <[11|00|02|00]Fver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]ESP32[00]build[00]Feb 15 2021 12:14:31[00]
12:17:44.012 -> [817] >[00|00|02|00|C8]
12:17:54.005 -> [10781] <[06|00|03|00|00]

There is no difference in the pre-fail dialogue. Interestingly, while working with the ESP2866, I noted ‘open’ and ‘close’ commands embedded in the heartbeat data when the app is opened and closed on the 'phone. No such commands with the ESP32.
The ESP32 is a Chinese clone ‘ESP32-DevKitC 32U’ of the usual Espressif thing. It has the Wroom and an antenna socket - I have fitted the correct Molex antenna.