better handle matching AP during scan

This commit is contained in:
Morgan 'ARR\!' Allen 2018-10-11 13:41:53 -07:00
parent cdaa2e9132
commit ccffb2229f

View file

@ -79,6 +79,8 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) {
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
if(ap_count > 0) {
ap_store.last = -1;
records = malloc(ap_count * sizeof(wifi_ap_record_t));
ESP_LOGI(TAG, "Found %d APs", ap_count);
@ -100,11 +102,15 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) {
}
found:
if(ap_store.last != -1) {
ESP_LOGI(TAG, "Got matching ESSID: %s", ap_store.aps[ap_store.last].ssid);
xEventGroupClearBits(wm_event_group, WIFI_SCANNING);
xEventGroupSetBits(wm_event_group, WIFI_IDLE);
wifi_manager_connect();
} else {
ESP_LOGI(TAG, "No matching APs found");
}
} else {
ESP_LOGI(TAG, "No APs found");
}