esp_wifi_scan_start() does not return mesh Information Elements

o.copleston
Posts: 21
Joined: Fri Aug 09, 2019 7:02 pm
Contact:

esp_wifi_scan_start() does not return mesh Information Elements

Postby o.copleston » Tue Jun 09, 2020 12:55 am

Environment

- Hardware: Custom board (similar to LyraT)
- Core (if using chip or module): ESP32-Wrover-B 16MB
- MDF version: 3ece464
- IDF Version: `6c9c253ed`
- Development Env: Make
- Operating System: MacOS
- Power Supply: external 3.3V
---------

I'm trying to encorporate a scanning function into a project based off the Wireless Debug and Manual Networking examples. However, I seem to be unable to manually detect any nearby mesh devices.
I have 30 active mesh devices and one device which I'm trying to detect them with using my scanning function.

I initialize the WiFI mesh as per the MWifi example. Following the call to mwifi_start() I do the following:

Code: Select all

//Disable self organized networking
esp_mesh_set_self_organized(0, 0);
//Stop any scans already in progress
esp_wifi_scan_stop();
// Remove any scan results that have been obtained (just in case)
esp_mesh_flush_scan_result();
//Manually start scan. Will automatically stop when run to completion
wifi_scan_config_t scan_config = {
    .show_hidden = true,
    .scan_type   = WIFI_SCAN_TYPE_ACTIVE,
};
esp_wifi_scan_start(&scan_config, true);
Upon completion of the scan, the MDF_EVENT_MWIFI_SCAN_DONE occurs:

Code: Select all

case MDF_EVENT_MWIFI_SCAN_DONE: {
    // Get event info
    mesh_event_scan_done_t *scan_done = (mesh_event_scan_done_t *) event_info;
    // Number of APs that have been found
    MDF_LOGW("<MESH_EVENT_SCAN_DONE>number:%d", scan_done->number);
    // Process the the Information Elements (IE) that have been retrieved, passing the function the number of IEs
    mesh_scan_done_handler(scan_done->number);
    break;
}
The scan handler function then iterates over each Information Element and prints its attributes to the serial port:

Code: Select all

/**
 * @brief Scan local APs to identify existing mesh networks and their IDs
 */
void mesh_scan_done_handler(int num) {
    int ie_len = 0;                     // length of Information Element (IE)
    mesh_assoc_t assoc;                 // Mesh networking IE
    wifi_ap_record_t ap_record;            // Description of the WiFi AP (SSID, RSSI, Channel etc.)
    mesh_type_t my_type = MESH_IDLE;

    for (int i=0; i<num; i++) {
        // Reset variables ready to read next mesh IE
        ie_len = 0;
        memset(&ap_record, 0, sizeof(wifi_ap_record_t));
        memset(&assoc, 0, sizeof(mesh_assoc_t));

        esp_mesh_scan_get_ap_ie_len(&ie_len);
        esp_mesh_scan_get_ap_record(&ap_record, &assoc);
        // check if this is a mesh IE
        if (ie_len == sizeof(mesh_assoc_t)) {
            MDF_LOGW("<MESH>[%d]%s, layer:%d/%d, assoc:%d/%d, %d, "MACSTR", channel:%u, rssi:%d, ID<"MACSTR"><%s>",
                i, ap_record.ssid, assoc.layer, assoc.layer_cap, assoc.assoc,
                assoc.assoc_cap, assoc.layer2_cap, MAC2STR(ap_record.bssid),
                ap_record.primary, ap_record.rssi, MAC2STR(assoc.mesh_id), assoc.encrypted ? "IE Encrypted" : "IE Unencrypted");
        
        } 
        else {
            MDF_LOGI("Router, ssid: %s, bssid: " MACSTR ", channel: %u, rssi: %d",
                     ap_record.ssid, MAC2STR(ap_record.bssid),
                     ap_record.primary, ap_record.rssi);
        }
    }
}
if (ie_len == sizeof(mesh_assoc_t)) Should trigger for each mesh Information Element, however it never does. So I removed it to try to get more results. In my console, I can see Information Elements for nearby routers interspersed with IEs without any SSID:

Code: Select all

W (8360) [mupgrade_subsystem, 220]: <MESH>[17]BTWifi-with-FON, layer:0/0, assoc:0/0, 0, 6a:a2:22:79:c3:22, channel:11, rssi:-59, ID<00:00:00:00:00:00><IE Unencrypted>
W (8376) [mupgrade_subsystem, 220]: <MESH>[18]BTWifi-X, layer:0/0, assoc:0/0, 0, 6a:a2:22:79:c3:23, channel:11, rssi:-59, ID<00:00:00:00:00:00><IE Unencrypted>
W (8585) [mupgrade_subsystem, 220]: <MESH>[32], layer:0/0, assoc:0/0, 0, 24:6f:28:f0:6f:4d, channel:11, rssi:-55, ID<00:00:00:00:00:00><IE Unencrypted>
W (8599) [mupgrade_subsystem, 220]: <MESH>[33], layer:0/0, assoc:0/0, 0, 24:6f:28:f0:84:69, channel:11, rssi:-61, ID<00:00:00:00:00:00><IE Unencrypted>
If these IEs with no SSID are meant to be other mesh devices then
A: there doesn't seem to be enough of these IEs to represent the number of devices I have active and
B: these entries contain no mesh data like "ID".

I don't understand why I'm not getting any mesh Information Elements. Any ideas if this is a bug with ESP-MDF or I am doing something I am doing wrong?

Any help would be massivly appreciated, Thanks.
Developer at SquidSoup
Person on Twitter | Instagram

ESP_yudong
Posts: 68
Joined: Wed May 16, 2018 12:31 pm

Re: esp_wifi_scan_start() does not return mesh Information Elements

Postby ESP_yudong » Thu Jun 11, 2020 3:29 am

It looks like this device failed to parse the mesh ie of others.
Have you set those 30 active devices and this one device to the same mesh_id and ie encryption method?

o.copleston
Posts: 21
Joined: Fri Aug 09, 2019 7:02 pm
Contact:

Re: esp_wifi_scan_start() does not return mesh Information Elements

Postby o.copleston » Thu Jun 11, 2020 2:57 pm

Hi ESP_yudong, thanks for getting back to me!

These 30 devices are all either a root node, child node or idle (and actively searching for a network to join). Num-layers is set to 2 and max children is set to 4, resulting in a maximum mesh network size of 5. There are 6 different mesh ID's in use to allow all 30 devices to be part of a mesh network.

Currently during startup, they attempt to join a mesh network and if full, increment the ID and try again until they are either a root node or a child node. This is a slow process and I would like to speed it up by first scanning and seeing what mesh networks are nearby and then choosing a suitable mesh ID value.
Developer at SquidSoup
Person on Twitter | Instagram

ESP-QI
Posts: 4
Joined: Wed May 22, 2019 3:44 am

Re: esp_wifi_scan_start() does not return mesh Information Elements

Postby ESP-QI » Fri Jun 12, 2020 3:39 am

One question:

W (8360) [mupgrade_subsystem, 220]: <MESH>[17]BTWifi-with-FON, layer:0/0, assoc:0/0, 0, 6a:a2:22:79:c3:22, channel:11, rssi:-59, ID<00:00:00:00:00:00><IE Unencrypted>
W (8376) [mupgrade_subsystem, 220]: <MESH>[18]BTWifi-X, layer:0/0, assoc:0/0, 0, 6a:a2:22:79:c3:23, channel:11, rssi:-59, ID<00:00:00:00:00:00><IE Unencrypted>
W (8585) [mupgrade_subsystem, 220]: <MESH>[32], layer:0/0, assoc:0/0, 0, 24:6f:28:f0:6f:4d, channel:11, rssi:-55, ID<00:00:00:00:00:00><IE Unencrypted>
W (8599) [mupgrade_subsystem, 220]: <MESH>[33], layer:0/0, assoc:0/0, 0, 24:6f:28:f0:84:69, channel:11, rssi:-61, ID<00:00:00:00:00:00><IE Unencrypted>

why "assoc:0/0"? it seems a problem there. if a node is "assoc:0/0", even it can be scanned, it will not be a parent candidate due to the assoc_cap=0. assoc_cap=0 represents it can't be connected to.

ESP_yudong
Posts: 68
Joined: Wed May 16, 2018 12:31 pm

Re: esp_wifi_scan_start() does not return mesh Information Elements

Postby ESP_yudong » Mon Jun 15, 2020 6:36 am

why "assoc:0/0"?
Because if (ie_len == sizeof(mesh_assoc_t)) was deleted.
This is a slow process and I would like to speed it up by first scanning and seeing what mesh networks are nearby and then choosing a suitable mesh ID value.
You can find other mesh id devices only when mesh IE is unencrypted on both sides. Use:

Code: Select all

cfg.crypto_funcs = NULL;
// or 
esp_mesh_set_ie_crypto_funcs(NULL);

o.copleston
Posts: 21
Joined: Fri Aug 09, 2019 7:02 pm
Contact:

Re: esp_wifi_scan_start() does not return mesh Information Elements

Postby o.copleston » Wed Jun 17, 2020 9:12 pm

Thank you ESP_yudong and ESP-QI for your help on the matter. Disabling encryption on both sides does indeed do the trick!

How do I then go about re-enabling encryption again?
Developer at SquidSoup
Person on Twitter | Instagram

Who is online

Users browsing this forum: No registered users and 8 guests