Implement WiFi connection timeout
This commit is contained in:
parent
baa19d730b
commit
9f7e20c807
1 changed files with 19 additions and 6 deletions
|
@ -9,7 +9,8 @@
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <Credentials/Credentials.h>
|
#include <Credentials/Credentials.h>
|
||||||
|
|
||||||
int STEPS = 5;
|
const int STEPS = 5;
|
||||||
|
const int WIFI_TIMEOUT = 20;
|
||||||
|
|
||||||
BluetoothSerial bt;
|
BluetoothSerial bt;
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
@ -40,29 +41,41 @@ void registerTasks()
|
||||||
xTaskCreate(websocketTask, "websocketTask", 10000, NULL, 1, NULL);
|
xTaskCreate(websocketTask, "websocketTask", 10000, NULL, 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void connectWifi()
|
void connectWifi(int timeout)
|
||||||
{
|
{
|
||||||
|
int secondsPassed = 0;
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PW);
|
WiFi.begin(WIFI_SSID, WIFI_PW);
|
||||||
Serial.print("Connecting to WiFi");
|
Serial.print("Connecting to WiFi");
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
Serial.print(".");
|
if (secondsPassed < timeout)
|
||||||
delay(1000);
|
{
|
||||||
|
Serial.print(".");
|
||||||
|
delay(1000);
|
||||||
|
secondsPassed++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("WiFi timed out");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
int bjtCount = 4;
|
const int bjtCount = 4;
|
||||||
const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B};
|
const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B};
|
||||||
computer = new SerialCommunicator(Serial, 9600, 5, 50);
|
computer = new SerialCommunicator(Serial, 9600, 5, 50);
|
||||||
phone = new BluetoothCommunicator(bt, 5, 50);
|
phone = new BluetoothCommunicator(bt, 5, 50);
|
||||||
light = new LightController(bjtPin, bjtCount);
|
light = new LightController(bjtPin, bjtCount);
|
||||||
websocket = new WebsocketCommunicator(ws, server, 50);
|
websocket = new WebsocketCommunicator(ws, server, 50);
|
||||||
|
|
||||||
connectWifi();
|
connectWifi(WIFI_TIMEOUT);
|
||||||
server.begin();
|
server.begin();
|
||||||
registerTasks();
|
registerTasks();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue