diff options
| author | Filip Wandzio <contact@philw.dev> | 2025-10-14 22:18:55 +0200 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2025-10-14 22:18:55 +0200 |
| commit | 4807e1cfe11dbedd7656e534e3995edb575129a6 (patch) | |
| tree | 48afc894f2b8c0ec1ad82ca433a77e4b247fa774 /firmware/src/wifi_scan.c | |
| parent | 01713bbe20d2cf5aafbe5eb32721d3e4fc5823d8 (diff) | |
| download | e1-4807e1cfe11dbedd7656e534e3995edb575129a6.tar.gz e1-4807e1cfe11dbedd7656e534e3995edb575129a6.zip | |
Optimize mqtt rtt analysis method
Diffstat (limited to 'firmware/src/wifi_scan.c')
| -rw-r--r-- | firmware/src/wifi_scan.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/firmware/src/wifi_scan.c b/firmware/src/wifi_scan.c index e588cfc..02bb451 100644 --- a/firmware/src/wifi_scan.c +++ b/firmware/src/wifi_scan.c | |||
| @@ -19,35 +19,36 @@ | |||
| 19 | * | 19 | * |
| 20 | * @param pvParameter Task parameter (unused). | 20 | * @param pvParameter Task parameter (unused). |
| 21 | */ | 21 | */ |
| 22 | static void wifi_scan_task(void *pvParameter) { | 22 | static void wifi_scan_task(void *pvParameter) |
| 23 | uint16_t ap_count = WIFI_SCAN_MAX_APS; | 23 | { |
| 24 | static wifi_ap_record_t ap_info[WIFI_SCAN_MAX_APS]; | 24 | uint16_t ap_count = WIFI_SCAN_MAX_APS; |
| 25 | wifi_scan_config_t scan_config = { | 25 | static wifi_ap_record_t ap_info[WIFI_SCAN_MAX_APS]; |
| 26 | .ssid = NULL, | 26 | wifi_scan_config_t scan_config = { |
| 27 | .bssid = NULL, | 27 | .ssid = NULL, |
| 28 | .channel = WIFI_SCAN_DEFAULT_CHANNEL, | 28 | .bssid = NULL, |
| 29 | .show_hidden = WIFI_SCAN_SHOW_HIDDEN, | 29 | .channel = WIFI_SCAN_DEFAULT_CHANNEL, |
| 30 | }; | 30 | .show_hidden = WIFI_SCAN_SHOW_HIDDEN, |
| 31 | }; | ||
| 31 | 32 | ||
| 32 | ESP_LOGI("wifi_scan", "Starting Wi-Fi scan..."); | 33 | ESP_LOGI("wifi_scan", "Starting Wi-Fi scan..."); |
| 33 | ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, false)); | 34 | ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, false)); |
| 34 | 35 | ||
| 35 | while (true) { | 36 | while (true) { |
| 36 | uint16_t finished_ap_count = 0; | 37 | uint16_t finished_ap_count = 0; |
| 37 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&finished_ap_count)); | 38 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&finished_ap_count)); |
| 38 | if (finished_ap_count > 0) | 39 | if (finished_ap_count > 0) |
| 39 | break; | 40 | break; |
| 40 | vTaskDelay(pdMS_TO_TICKS(WIFI_SCAN_POLL_INTERVAL_MS)); | 41 | vTaskDelay(pdMS_TO_TICKS(WIFI_SCAN_POLL_INTERVAL_MS)); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_count, ap_info)); | 44 | ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_count, ap_info)); |
| 44 | ESP_LOGI("wifi_scan", "Found %d access points:", ap_count); | 45 | ESP_LOGI("wifi_scan", "Found %d access points:", ap_count); |
| 45 | for (uint16_t ap_index = 0; ap_index < ap_count; ++ap_index) { | 46 | for (uint16_t ap_index = 0; ap_index < ap_count; ++ap_index) { |
| 46 | ESP_LOGI("wifi_scan", "%d: SSID: %s, RSSI: %d", ap_index + 1, | 47 | ESP_LOGI("wifi_scan", "%d: SSID: %s, RSSI: %d", ap_index + 1, |
| 47 | ap_info[ap_index].ssid, ap_info[ap_index].rssi); | 48 | ap_info[ap_index].ssid, ap_info[ap_index].rssi); |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | vTaskDelete(NULL); | 51 | vTaskDelete(NULL); |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | /** | 54 | /** |
| @@ -55,7 +56,9 @@ static void wifi_scan_task(void *pvParameter) { | |||
| 55 | * | 56 | * |
| 56 | * Creates a FreeRTOS task that runs the WiFi scan asynchronously. | 57 | * Creates a FreeRTOS task that runs the WiFi scan asynchronously. |
| 57 | */ | 58 | */ |
| 58 | void wifi_scan_start(void) { | 59 | void wifi_scan_start(void) |
| 59 | xTaskCreate(wifi_scan_task, WIFI_SCAN_TASK_NAME, WIFI_SCAN_TASK_STACK_SIZE, | 60 | { |
| 60 | NULL, WIFI_SCAN_TASK_PRIORITY, NULL); | 61 | xTaskCreate(wifi_scan_task, WIFI_SCAN_TASK_NAME, |
| 62 | WIFI_SCAN_TASK_STACK_SIZE, NULL, WIFI_SCAN_TASK_PRIORITY, | ||
| 63 | NULL); | ||
| 61 | } | 64 | } |
