Implement WiFi connection timeout

This commit is contained in:
GHOSCHT 2022-04-10 17:56:23 +02:00
parent baa19d730b
commit 9f7e20c807

View file

@ -9,7 +9,8 @@
#include <ESPAsyncWebServer.h>
#include <Credentials/Credentials.h>
int STEPS = 5;
const int STEPS = 5;
const int WIFI_TIMEOUT = 20;
BluetoothSerial bt;
AsyncWebServer server(80);
@ -40,29 +41,41 @@ void registerTasks()
xTaskCreate(websocketTask, "websocketTask", 10000, NULL, 1, NULL);
}
void connectWifi()
void connectWifi(int timeout)
{
int secondsPassed = 0;
WiFi.begin(WIFI_SSID, WIFI_PW);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(1000);
if (secondsPassed < timeout)
{
Serial.print(".");
delay(1000);
secondsPassed++;
}
else
{
Serial.println("");
Serial.println("WiFi timed out");
return;
}
}
Serial.println("");
Serial.println(WiFi.localIP());
}
void setup()
{
int bjtCount = 4;
const int bjtCount = 4;
const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B};
computer = new SerialCommunicator(Serial, 9600, 5, 50);
phone = new BluetoothCommunicator(bt, 5, 50);
light = new LightController(bjtPin, bjtCount);
websocket = new WebsocketCommunicator(ws, server, 50);
connectWifi();
connectWifi(WIFI_TIMEOUT);
server.begin();
registerTasks();
}