I'm using this code on an ESP32 to connect to my home WiFi network:
#include <Arduino.h>
#include <WiFi.h>
char text[80];
uint8_t connectTCP(void) {
char ctr = 0;
const char *ssid= "*********";
const char *pwd = "*********";
WiFi.begin(ssid, pwd);
Serial.print("Connecting to WiFi: ***");
// Wait for connection or time-out in 5 sec
while (WiFi.status() != WL_CONNECTED && ctr < 10) {
delay(500);
Serial.print(" *");
ctr++;
}
if (ctr > 9) {
sprintf(text, "\nWIFI connection time out. Failed to connect to network '%s'.\n", ssid);
Serial.println(text);
return 0;
}
sprintf(text, "\nConnected ESP32 to WIFI network '%s' with IP ", ssid);
Serial.print(text);
Serial.print(WiFi.localIP());
Serial.println(" on Port 80");
return 1;
}
void setup() {
if(!connectTCP(void)) {
Serial.println("WiFi failed. Terminate program");
while(1) {}
}
}
void loop() {
}
The program sometimes connects (yeah!!!). But in most cases it generates a Core dump and reboots. It might run thru 5-10 reboot cycles before finally making a connection. The output that I'm showing is the typical output when the Wifi connection fails. Sometimes the 'Connecting to WiFi: ***' is printed too. Any suggestions of what might be going on??
RC controller Status: 1
CH1: 1488 CH2: 1494 CH3: 1030 CH4: 1030 CH5: 1960 CH6: 1030
Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)
Core 1 register dump:
PC : 0x400d1708 PS : 0x00060034 A0 : 0x800813d8 A1 : 0x3ffbe790
A2 : 0x00000000 A3 : 0x00000018 A4 : 0x8008984a A5 : 0x3ffbe790
A6 : 0x3ffbe7d8 A7 : 0x00000001 A8 : 0x80081001 A9 : 0x00000001
A10 : 0x00000002 A11 : 0x0000001b A12 : 0x8008af57 A13 : 0x3ffbe760
A14 : 0x00000008 A15 : 0x00000001 SAR : 0x00000016 EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x40001609 LEND : 0x4000160d LCOUNT : 0x00000000
Core 1 was running in ISR context:
EPC1 : 0x400877bb EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400d1708
Backtrace: 0x400d1708:0x3ffbe790 0x400813d5:0x3ffbe7b0 0x40085345:0x3ffbe7d0 0x400877b8:0x3ffb1890 0x40087f11:0x3ffb18b0 0x400e9eb1:0x3ffb1920 0x400e8781:0x3ffb1940 0x400e8bcf:0x3ffb1960 0x400e7565:0x3ffb19d0 0x400e79b6:0x3ffb1a20 0x400e7a98:0x3ffb1aa0 0x400e6b62:0x3ffb1b00 0x400e7095:0x3ffb1b40 0x4013377e:0x3ffb1b60 0x40133972:0x3ffb1bb0 0x401339c5:0x3ffb1be0 0x400ea35f:0x3ffb1c00 0x400ea4b2:0x3ffb1c20 0x400dd6ad:0x3ffb1c40 0x400d4699:0x3ffb1c60 0x400d4755:0x3ffb1d60 0x400d4833:0x3ffb1d80 0x400d2b4d:0x3ffb1eb0 0x400d2e2f:0x3ffb1f70 0x400da3bf:0x3ffb1fb0 0x40089751:0x3ffb1fd0
Rebooting...
User contributions licensed under CC BY-SA 3.0