Detecting valid WiFi Connection

charleslinquist
Posts: 2
Joined: Thu May 16, 2019 9:09 pm

Detecting valid WiFi Connection

Postby charleslinquist » Mon Jan 17, 2022 11:34 pm

I followed the web server example (STation Mode) given by
https://randomnerdtutorials.com/esp32-w ... duino-ide/

My goal is to turn the on-board LED ON when a WiFi connection is established, and turn it back OFF
when the connection drops or disappears.

I have no trouble turning on the LED when the WiFi connects, but it will not shut off when the connection
is no longer valid.

My code:

in the MAIN loop,

// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server

LEDinternal = ON; <------------------------------------------- I added this command

Serial.println("");
Serial.println("WiFi connected.");
...

Then, in the main loop, I added the following:

if (WiFi.status() != WL_CONNECTED) {
LEDinternal = OFF;
}


But it doesn't work. Please tell me how I might fix this.

Who is online

Users browsing this forum: No registered users and 39 guests