diff options
| author | Filip Wandzio <contact@philw.dev> | 2025-10-29 13:29:27 +0100 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2025-10-29 13:29:27 +0100 |
| commit | a27af14e815ef993e9a0c94e5bc8b32dbf989a94 (patch) | |
| tree | fed25911f251f95c7f2c71d1d770a5013452664c /firmware/src/wifi_scan.c | |
| parent | 4698910f842c322b80ebd1cf19a4e32c0fb2249d (diff) | |
| download | e1-a27af14e815ef993e9a0c94e5bc8b32dbf989a94.tar.gz e1-a27af14e815ef993e9a0c94e5bc8b32dbf989a94.zip | |
Solve baud detection bug, fix wifi searching task scheduling bug, improve documentation, implement additional mqtt topicsHEADmaster
Diffstat (limited to 'firmware/src/wifi_scan.c')
| -rw-r--r-- | firmware/src/wifi_scan.c | 19 |
1 files changed, 14 insertions, 5 deletions
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 @@ | |||
| 12 | #define WIFI_SCAN_TASK_NAME "wifi_scan_task" | 12 | #define WIFI_SCAN_TASK_NAME "wifi_scan_task" |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * @brief Task to perform WiFi scanning asynchronously. | 15 | * @brief Asynchronous WiFi scanning task for ESP32 with FreeRTOS. |
| 16 | * | 16 | * |
| 17 | * Starts a WiFi scan, polls for scan completion, | 17 | * Configures and initiates a non-blocking WiFi scan on the specified or all |
| 18 | * retrieves and logs the found access points, then deletes itself. | 18 | * channels, including hidden networks if enabled. Periodically polls for scan |
| 19 | * completion without blocking other tasks, retrieves discovered access points | ||
| 20 | * up to a defined maximum, and logs each AP's SSID and signal strength (RSSI). | ||
| 19 | * | 21 | * |
| 20 | * @param pvParameter Task parameter (unused). | 22 | * After logging, the task self-deletes to free system resources. |
| 23 | * | ||
| 24 | * This design ensures WiFi scanning runs in the background, preserving system | ||
| 25 | * responsiveness and maintaining real-time operation in embedded applications. | ||
| 26 | * | ||
| 27 | * @param pvParameter Pointer to task parameters (unused). | ||
| 21 | */ | 28 | */ |
| 22 | static void wifi_scan_task(void *pvParameter) | 29 | static void wifi_scan_task(void *pvParameter) |
| 23 | { | 30 | { |
| @@ -36,13 +43,15 @@ static void wifi_scan_task(void *pvParameter) | |||
| 36 | while (true) { | 43 | while (true) { |
| 37 | uint16_t finished_ap_count = 0; | 44 | uint16_t finished_ap_count = 0; |
| 38 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&finished_ap_count)); | 45 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&finished_ap_count)); |
| 39 | if (finished_ap_count > 0) | 46 | if (finished_ap_count > 0) { |
| 40 | break; | 47 | break; |
| 48 | } | ||
| 41 | vTaskDelay(pdMS_TO_TICKS(WIFI_SCAN_POLL_INTERVAL_MS)); | 49 | vTaskDelay(pdMS_TO_TICKS(WIFI_SCAN_POLL_INTERVAL_MS)); |
| 42 | } | 50 | } |
| 43 | 51 | ||
| 44 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_count, ap_info)); | 52 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_count, ap_info)); |
| 45 | ESP_LOGI("wifi_scan", "Found %d access points:", ap_count); | 53 | ESP_LOGI("wifi_scan", "Found %d access points:", ap_count); |
| 54 | |||
| 46 | for (uint16_t ap_index = 0; ap_index < ap_count; ++ap_index) { | 55 | for (uint16_t ap_index = 0; ap_index < ap_count; ++ap_index) { |
| 47 | ESP_LOGI("wifi_scan", "%d: SSID: %s, RSSI: %d", ap_index + 1, | 56 | ESP_LOGI("wifi_scan", "%d: SSID: %s, RSSI: %d", ap_index + 1, |
| 48 | ap_info[ap_index].ssid, ap_info[ap_index].rssi); | 57 | ap_info[ap_index].ssid, ap_info[ap_index].rssi); |
