From a27af14e815ef993e9a0c94e5bc8b32dbf989a94 Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Wed, 29 Oct 2025 13:29:27 +0100 Subject: Solve baud detection bug, fix wifi searching task scheduling bug, improve documentation, implement additional mqtt topics --- firmware/src/wifi_scan.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'firmware/src/wifi_scan.c') diff --git a/firmware/src/wifi_scan.c b/firmware/src/wifi_scan.c index 02bb451..07f3dc7 100644 --- a/firmware/src/wifi_scan.c +++ b/firmware/src/wifi_scan.c @@ -12,12 +12,19 @@ #define WIFI_SCAN_TASK_NAME "wifi_scan_task" /** - * @brief Task to perform WiFi scanning asynchronously. + * @brief Asynchronous WiFi scanning task for ESP32 with FreeRTOS. * - * Starts a WiFi scan, polls for scan completion, - * retrieves and logs the found access points, then deletes itself. + * Configures and initiates a non-blocking WiFi scan on the specified or all + * channels, including hidden networks if enabled. Periodically polls for scan + * completion without blocking other tasks, retrieves discovered access points + * up to a defined maximum, and logs each AP's SSID and signal strength (RSSI). * - * @param pvParameter Task parameter (unused). + * After logging, the task self-deletes to free system resources. + * + * This design ensures WiFi scanning runs in the background, preserving system + * responsiveness and maintaining real-time operation in embedded applications. + * + * @param pvParameter Pointer to task parameters (unused). */ static void wifi_scan_task(void *pvParameter) { @@ -36,13 +43,15 @@ static void wifi_scan_task(void *pvParameter) while (true) { uint16_t finished_ap_count = 0; ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&finished_ap_count)); - if (finished_ap_count > 0) + if (finished_ap_count > 0) { break; + } vTaskDelay(pdMS_TO_TICKS(WIFI_SCAN_POLL_INTERVAL_MS)); } ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_count, ap_info)); ESP_LOGI("wifi_scan", "Found %d access points:", ap_count); + for (uint16_t ap_index = 0; ap_index < ap_count; ++ap_index) { ESP_LOGI("wifi_scan", "%d: SSID: %s, RSSI: %d", ap_index + 1, ap_info[ap_index].ssid, ap_info[ap_index].rssi); -- cgit v1.2.3