Hello,
I use an Arduino Giga R1 board as the main brain of an automated system. I am trying to connect the system to the Internet via WiFi, and if the WiFi is disconnected, the board will try to reconnect. When it tries to reconnect, it takes about 36 sec and freezes the whole loop. I tried the same sketch below with ESP32; the reconnection took less than a second.
#include <WiFi.h>
const char* ssid = "Sparky"; // Replace with your network SSID (name)
const char* password = "HAYDER098123"; // Replace with your network password
void setup() {
Serial.begin(115200);
delay(1000);
}
void loop() {
// Check the status of the WiFi connection
Serial.println("I am in the loop");
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connection lost. Attempting to reconnect...");
WiFi.disconnect();
Serial.println("Before WiFi.begin");
WiFi.begin(ssid, password);
Serial.println("After WiFi.begin");
}
Serial.println("");
Serial.println("Reconnected to WiFi.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(100); // This is just a placeholder delay for the example
}
And here are the serial monitor prints
4:44:34.598 -> I am in the loop
14:44:34.598 -> WiFi connection lost. Attempting to reconnect...
14:44:34.598 -> Before WiFi.begin
14:45:10.371 -> After WiFi.begin
14:45:10.371 ->
14:45:10.371 -> Reconnected to WiFi.
14:45:10.371 -> IP address:
14:45:10.371 -> 0.0.0.0
14:45:10.441 -> I am in the loop
14:45:10.441 -> WiFi connection lost. Attempting to reconnect...
14:45:10.441 -> Before WiFi.begin
Would you please help find out where the problem is?