espressif / esp-mdf

Espressif Mesh Development Framework, limited maintain, recommend to use https://github.com/espressif/esp-mesh-lite
Other
779 stars 253 forks source link

esp_wifi_scan_start() does not return mesh Information #148

Open copleston opened 4 years ago

copleston commented 4 years ago

Environment

Problem Description

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:

//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:

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:

/**
 * @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:

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

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 massively appreciated, Thanks.

EspHuifeng commented 4 years ago

I use you code for testing and got these log. So are these what you want?

I (1529) [mwifi, 221]: MESH is started
I (1532) [router_example, 356]: event_loop_cb, event: 0
I (1538) [router_example, 360]: MESH is started
I (1544) mesh: [IO]disable self-organizing<stop reconnect>
I (1549) mesh: <WIFI_EVENT_SCAN_DONE>status:fail, num:4, id:128
I (3609) mesh: 3467<scan>self-organized is disabled, users shall read out scan results by themselves.
I (3610) [router_example, 356]: event_loop_cb, event: 19
W (3614) [router_example, 393]: <MESH_EVENT_SCAN_DONE>number:52
I (3620) [router_example, 341]: Router, ssid: HAPPYBOY, bssid: bc:5f:f6:1b:28:5e, channel: 1, rssi: -60
I (3630) [router_example, 341]: Router, ssid: ESP_69EC2D, bssid: d8:a0:1d:69:ec:2d, channel: 1, rssi: -71
I (3641) [router_example, 341]: Router, ssid: TP-LINK_8A30, bssid: 60:3a:7c:4d:a4:54, channel: 1, rssi: -58
I (3651) [router_example, 341]: Router, ssid: , bssid: ec:56:23:e9:7e:f1, channel: 1, rssi: -76
I (3660) [router_example, 341]: Router, ssid: esp-office-2.4G, bssid: 70:3a:73:04:6c:fb, channel: 1, rssi: -54
I (3671) [router_example, 341]: Router, ssid: Test_Week, bssid: ac:22:0b:d2:ee:58, channel: 1, rssi: -71
I (3681) [router_example, 341]: Router, ssid: ASUS_Guest1, bssid: ae:22:0b:d2:ee:59, channel: 1, rssi: -70
I (3692) [router_example, 341]: Router, ssid: ASUS_Guest2, bssid: ae:22:0b:d2:ee:5a, channel: 1, rssi: -72
I (3702) [router_example, 341]: Router, ssid: touch-pannel, bssid: 7c:df:a1:01:79:5f, channel: 1, rssi: -65
I (3712) [router_example, 341]: Router, ssid: Yafeng_test_2.4G, bssid: 20:a6:80:98:dc:b4, channel: 1, rssi: -57
I (3723) [router_example, 341]: Router, ssid: XYWORK, bssid: b8:3a:08:78:a6:90, channel: 1, rssi: -50
I (3733) [router_example, 341]: Router, ssid: IODATA-b2e088-2G, bssid: 34:76:c5:b2:e0:88, channel: 1, rssi: -73
I (3744) [router_example, 341]: Router, ssid: esp-office-2.4G, bssid: 70:3a:73:04:6c:d1, channel: 1, rssi: -68
I (3754) [router_example, 341]: Router, ssid: 360WiFi-Multi, bssid: a4:56:02:47:30:07, channel: 1, rssi: -38
I (3765) [router_example, 341]: Router, ssid: MERCURY_fae, bssid: f4:ee:14:10:e7:56, channel: 1, rssi: -71
I (3775) [router_example, 341]: Router, ssid: , bssid: 30:ae:a4:80:56:6d, channel: 1, rssi: -60
I (3785) [router_example, 341]: Router, ssid: HUAWEI-U5LXKT, bssid: d0:ff:98:de:3a:2c, channel: 1, rssi: -65
I (3795) [router_example, 341]: Router, ssid: esp-guest, bssid: 70:3a:73:0c:6c:fb, channel: 1, rssi: -54
I (3805) [router_example, 341]: Router, ssid: DLH_TEST, bssid: b0:95:8e:03:5f:05, channel: 1, rssi: -61
I (3815) [router_example, 341]: Router, ssid: esp123456, bssid: 3e:33:00:90:11:24, channel: 3, rssi: -70
I (3826) [router_example, 341]: Router, ssid: CZWWORK_2.4G, bssid: 08:60:6e:21:48:e8, channel: 3, rssi: -70
I (3836) [router_example, 341]: Router, ssid: ESP-Audio, bssid: d4:ee:07:2e:c9:ea, channel: 4, rssi: -66
I (3846) [router_example, 341]: Router, ssid: mali-test, bssid: 30:a2:c2:70:27:88, channel: 5, rssi: -78
I (3856) [router_example, 341]: Router, ssid: zztest, bssid: 20:6b:e7:34:f5:36, channel: 6, rssi: -45
I (3866) [router_example, 341]: Router, ssid: steven, bssid: b0:95:8e:17:94:a5, channel: 6, rssi: -64
I (3876) [router_example, 341]: Router, ssid: 测试, bssid: 4a:7d:2e:55:aa:a6, channel: 6, rssi: -65
I (3886) [router_example, 341]: Router, ssid: AAA_TEST, bssid: fc:2f:ef:ab:db:70, channel: 6, rssi: -64
I (3896) [router_example, 341]: Router, ssid: CU_gdQj, bssid: 44:f4:36:ee:d2:3a, channel: 6, rssi: -69
I (3906) [router_example, 341]: Router, ssid: esp-liyin, bssid: bc:46:99:2b:2f:93, channel: 6, rssi: -48
I (3916) [router_example, 341]: Router, ssid: miio, bssid: 48:7d:2e:45:aa:a6, channel: 6, rssi: -69
I (3926) [router_example, 341]: Router, ssid: TP-LINK_945D, bssid: 48:7d:2e:07:94:5d, channel: 6, rssi: -63
I (3936) [router_example, 341]: Router, ssid: DLH_TEST, bssid: b0:4e:26:8a:03:f6, channel: 9, rssi: -72
I (3946) [router_example, 341]: Router, ssid: esp-office-2.4G, bssid: 70:3a:73:04:6c:c6, channel: 9, rssi: -66
I (3957) [router_example, 341]: Router, ssid: esp-guest, bssid: 70:3a:73:0c:6c:c6, channel: 9, rssi: -65
I (3967) [router_example, 341]: Router, ssid: 360WiFi-Multi, bssid: a4:56:02:e1:d9:92, channel: 10, rssi: -56
W (3978) [router_example, 335]: <MESH>[35]ESPM_F00D70, layer:3/13, assoc:0/6, 6, 24:6f:28:f0:0d:71, channel:10, rssi:-40, ID<00:11:22:33:44:55><IE Encrypted>
I (3993) [router_example, 341]: Router, ssid: AE-mesh-s, bssid: 34:97:f6:5f:2b:08, channel: 10, rssi: -62
W (4003) [router_example, 335]: <MESH>[37]ESPM_F067E0, layer:3/13, assoc:0/6, 6, 24:6f:28:f0:67:e1, channel:10, rssi:-52, ID<00:11:22:33:44:55><IE Encrypted>
W (4018) [router_example, 335]: <MESH>[38]ESPM_F01008, layer:3/13, assoc:0/6, 7, 24:6f:28:f0:10:09, channel:10, rssi:-47, ID<00:11:22:33:44:55><IE Encrypted>
W (4032) [router_example, 335]: <MESH>[39]ESPM_F008F4, layer:3/13, assoc:0/6, 7, 24:6f:28:f0:08:f5, channel:10, rssi:-40, ID<00:11:22:33:44:55><IE Encrypted>
W (4047) [router_example, 335]: <MESH>[40]ESPM_F00FD0, layer:2/14, assoc:6/6, 7, 24:6f:28:f0:0f:d1, channel:10, rssi:-61, ID<00:11:22:33:44:55><IE Encrypted>
W (4062) [router_example, 335]: <MESH>[41]ESPM_F00DB0, layer:3/13, assoc:0/6, 7, 24:6f:28:f0:0d:b1, channel:10, rssi:-64, ID<00:11:22:33:44:55><IE Encrypted>
I (4077) [router_example, 341]: Router, ssid: NETGEAR, bssid: b0:7f:b9:cf:4f:18, channel: 11, rssi: -53
I (4087) [router_example, 341]: Router, ssid: TP-LINK_8C81, bssid: 94:d9:b3:80:8c:81, channel: 11, rssi: -39
I (4097) [router_example, 341]: Router, ssid: TP-740-W-22, bssid: 48:7d:2e:7c:a1:91, channel: 11, rssi: -59
I (4108) [router_example, 341]: Router, ssid: NETGEAR24, bssid: a0:63:91:81:c0:c6, channel: 11, rssi: -73
I (4118) [router_example, 341]: Router, ssid: , bssid: b4:e6:2d:eb:58:72, channel: 11, rssi: -70
I (4127) [router_example, 341]: Router, ssid: , bssid: 30:ae:a4:80:55:29, channel: 11, rssi: -54
I (4137) [router_example, 341]: Router, ssid: TP-LINK_7CD5, bssid: 48:7d:2e:07:7c:d5, channel: 11, rssi: -71
I (4147) [router_example, 341]: Router, ssid: #!/bin/test, bssid: ac:9e:17:7e:31:40, channel: 11, rssi: -78
I (4158) [router_example, 341]: Router, ssid: myssid, bssid: 48:7d:2e:c9:a0:a5, channel: 11, rssi: -71
I (4168) [router_example, 341]: Router, ssid: ASUS_N66U_TT111, bssid: 60:a4:4c:ef:2d:88, channel: 12, rssi: -68
I (4179) [router_example, 223]: NODE task is running
I (4184) [router_example, 193]: Note read task is running