From b4f71f60fa043ced84a5ba613caecaf8360adfb9 Mon Sep 17 00:00:00 2001 From: Daan Meijer Date: Fri, 24 Jan 2025 22:53:18 +0100 Subject: [PATCH] wifi working async --- src/Hanglamp.cpp | 2 +- src/Wifi.cpp | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Hanglamp.cpp b/src/Hanglamp.cpp index 7abf699..625bdb4 100644 --- a/src/Hanglamp.cpp +++ b/src/Hanglamp.cpp @@ -9,7 +9,7 @@ #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only // #define ENABLE_MQTT -// #define ENABLE_WIFI +#define ENABLE_WIFI // #define ENABLE_FS // #define ENABLE_PINFINDER #define ENABLE_COLORS diff --git a/src/Wifi.cpp b/src/Wifi.cpp index 01b53a4..5672a22 100644 --- a/src/Wifi.cpp +++ b/src/Wifi.cpp @@ -20,21 +20,32 @@ void Wifi_setup_softap(){ } -void Wifi_setup(){ +void Wifi_loop(void* params){ + Serial.println("Wifi_setup()"); + WiFi.mode(WIFI_STA); + //TODO: + WiFi.begin(WIFI_ESSID, WIFI_PASSWORD); - Serial.println("Wifi_setup()"); - WiFi.mode(WIFI_STA); - //TODO: - WiFi.begin(WIFI_ESSID, WIFI_PASSWORD); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); + while (true) + { + while (WiFi.status() != WL_CONNECTED) + { + vTaskDelay(500 / portTICK_PERIOD_MS); + Serial.println("Wifi waiting..."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); + + vTaskDelay(60*1000 / portTICK_PERIOD_MS); + } +} + +void Wifi_setup(){ + + TaskHandle_t taskWifi = NULL; + xTaskCreate(Wifi_loop, "Wifi_loop", 10000, NULL, tskIDLE_PRIORITY, &taskWifi); } \ No newline at end of file