diff --git a/Firmware/src/main.cpp b/Firmware/src/main.cpp index b085407..662f3ec 100644 --- a/Firmware/src/main.cpp +++ b/Firmware/src/main.cpp @@ -9,7 +9,8 @@ #include #include -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(); }