100 case WIFI_EVENT_SCAN_DONE: |
100 case WIFI_EVENT_SCAN_DONE: |
101 { |
101 { |
102 /* Get the results so the memory used is freed. */ |
102 /* Get the results so the memory used is freed. */ |
103 ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records)); |
103 ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records)); |
104 ESP_LOGI(TAG, "Event wifi Scane done, %d records", ap_num); |
104 ESP_LOGI(TAG, "Event wifi Scane done, %d records", ap_num); |
|
105 _wifi_BetterAP = false; |
105 for (int i = 0; i < ap_num; i++) { |
106 for (int i = 0; i < ap_num; i++) { |
106 wifi_ap_record_t ap = accessp_records[i]; |
107 wifi_ap_record_t ap = accessp_records[i]; |
107 ESP_LOGI(TAG, "AP:%d bssid:%02x:%02x:%02x:%02x:%02x:%02x ssid:%s ch:%d rssi:%d", |
108 ESP_LOGI(TAG, "AP:%d bssid:%02x:%02x:%02x:%02x:%02x:%02x ssid:%s ch:%d rssi:%d", |
108 i, ap.bssid[0], ap.bssid[1], ap.bssid[2], ap.bssid[3], ap.bssid[4], ap.bssid[5], |
109 i, ap.bssid[0], ap.bssid[1], ap.bssid[2], ap.bssid[3], ap.bssid[4], ap.bssid[5], |
109 ap.ssid, ap.primary, ap.rssi); |
110 ap.ssid, ap.primary, ap.rssi); |
112 ESP_LOGI(TAG, "AP:%d is a better AP", i); |
113 ESP_LOGI(TAG, "AP:%d is a better AP", i); |
113 } |
114 } |
114 } |
115 } |
115 _wifi_Scanned = ap_num; |
116 _wifi_Scanned = ap_num; |
116 _wifi_ScanDone = true; |
117 _wifi_ScanDone = true; |
|
118 if (_wifi_BetterAP) { |
|
119 ESP_LOGI(TAG, "Disconnect current AP"); |
|
120 disconnect_WiFi(); |
|
121 } |
117 break; |
122 break; |
118 } |
123 } |
119 |
124 |
120 case WIFI_EVENT_STA_START: |
125 case WIFI_EVENT_STA_START: |
121 { |
126 { |