Feat: add timeout to restart on wifi failed connection

This commit is contained in:
Bertrand Benjamin 2022-08-19 06:50:32 +02:00
parent eee30401a8
commit 11cf1cf782

View File

@ -3,6 +3,7 @@
#include "WiFi.h"
#include "Audio.h"
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26
@ -10,6 +11,8 @@
#define POWERBUTTON GPIO_NUM_33
#define VOLUMERES 34
Audio audio;
#define CONNECTION_TIMEOUT 10 // 10 seconds
wifi_config_t wifi_config = {0};
String ssid = WIFI_SSID;
@ -78,12 +81,18 @@ void wifi_init() {
Serial.print("Connexion au reseau ");
Serial.println(ssid);
int timeout_counter = 0;
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(STATUSLED, LOW);
delay(500);
Serial.print(".");
digitalWrite(STATUSLED, HIGH);
delay(500);
timeout_counter++;
if (timeout_counter > CONNECTION_TIMEOUT){
ESP.restart();
}
}
WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(192,168,2,1));