EPS32 IDF WiFi Mesh: Can my MESH_ROOT scan for Access Points

MichaelS
Posts: 46
Joined: Mon Jul 08, 2024 12:08 am

EPS32 IDF WiFi Mesh: Can my MESH_ROOT scan for Access Points

Postby MichaelS » Tue Jul 01, 2025 7:25 am

Is there a way for a MESH_ROOT to scan for Access points? I have read WiFi API functions should not be used while WiFi Mesh is active.

Is what I am trying to do below possible? Or maybe there is a better way to meet my requirement.

My requirement is to have 2 APs on site; a primary and a backup. If the primary goes down, I get a disconnected event and switch to the backup. So far so good.

But while running on the backup AP, I would like to detect if the primary AP is running again and if so, then switch back to it. I have tried scaning as follows:

Code: Select all

esp_wifi_scan_stop();
wifi_scan_config_t scan_config = { 0 }; // mesh softAP is hidden
scan_config.show_hidden = 1;
scan_config.scan_type = WIFI_SCAN_TYPE_PASSIVE;
// scan_config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
esp_wifi_scan_start(&scan_config, 0);
In my mesh_event_handler case MESH_EVENT_SCAN_DONE I call a function to process the scan results.

Code: Select all

    case MESH_EVENT_SCAN_DONE: {
        mesh_event_scan_done_t *scan_done = (mesh_event_scan_done_t *)event_data;
        ESP_LOGI(TAG, "<MESH_EVENT_SCAN_DONE>number:%d", scan_done->number);
        examineScanResults(scan_done->number);
    }
    break;

Code: Select all

void examineScanResults(int num) { // after a WiFi scan
    ESP_LOGW(TAG, "examineScanResults");
    int ie_len = 0;
    mesh_assoc_t assoc; // for holding scan node records
    wifi_ap_record_t record;

    for (auto i = 0; i < num; i++) { // iterate through scan records looking for eligible closer parent node
        ESP_ERROR_CHECK(esp_mesh_scan_get_ap_ie_len(&ie_len));
        ESP_ERROR_CHECK(esp_mesh_scan_get_ap_record(&record, &assoc));
        ESP_LOGD(TAG, "ie_len: %d  sizeof(assoc): %d", ie_len, sizeof(assoc));
        if (ie_len == sizeof(assoc)) {
            ESP_LOGI(TAG, "LenSame [%d]%s, "MACSTR", channel:%u, rssi:%d", i, record.ssid, MAC2STR(record.bssid), record.primary, record.rssi);

        } else {
            ESP_LOGI(TAG, "LenDiff [%d]%s, "MACSTR", channel:%u, rssi:%d", i, record.ssid, MAC2STR(record.bssid), record.primary, record.rssi);
        }
    }
}
But most of the time I only get a couple of the other ESP32 MESH_NODEs and occasionally my MESH_ROOTs (which did the scan) currently connected AP.

Code: Select all

W (02:44:15.603) aWifiMesh: examineScanResults
I (02:44:15.604) aWifiMesh: LenSame [0]ESPM_9B5D20, 48:ca:43:9b:5d:21, channel:1, rssi:-23
I (02:44:15.607) aWifiMesh: LenSame [1]ESPM_9B5C68, 48:ca:43:9b:5c:69, channel:1, rssi:-18
I (02:44:15.609) aWifiMesh: LenSame [2]ESPM_DE8EE8, 24:58:7c:de:8e:e9, channel:1, rssi:-21
I have tried both Passive and Active scanning.

Who is online

Users browsing this forum: ChatGPT-User, Google [Bot], PerplexityBot, PetalBot, Qwantbot, Semrush [Bot] and 11 guests