How can I trigger the creation of a new mesh network, once a mesh network is full? + how to get IDs of existing networks

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

How can I trigger the creation of a new mesh network, once a mesh network is full? + how to get IDs of existing networks

Postby o.copleston » Thu Feb 27, 2020 12:26 am

(EDIT 21/05/20: This post is getting the so many hits and yet no replies :roll:)

Context:
I have a few hundred devices which are currently connected to a single access point. I'm sending commands, files and OTA updates to these devices, but because they are all connected to the same access point there is a lot of contention and other network issues.

My goal is to use ESP-MDF to create multiple mesh networks with very few layers to reduce the number of devices connected to my access point.

I have configured mWifi with the following parameters:
Number of layers: 2
Number of softAP connections: 3

In my small test network of 7 devices, this produces a single root node with 3 children (as expected). The other 3 nodes remain idle.

I wish for the idle nodes to create their own mesh network with it's own root and child nodes.
I have tried enabling the option to allow multiple roots, but that has made no difference. Is it possible to allow another mesh network to be set up once the current one is full?

Any help would be hugely appreciated!

Below is the serial output of one of the Idle nodes, where it is trying to connect to the full network - and failing.

Code: Select all

I (1295) [mupgrade_subsystem, 36]: MESH is started
I (5195) mesh: [S10]Meme_Net, 44:d9:e7:b5:27:02, channel:6, rssi:-42
I (5195) mesh: find router:[ssid_len:8]Meme_Net, rssi:-42, 44:d9:e7:b5:27:02(encrypted), new channel:6, old channel:0
I (5205) mesh: [S19]Meme_Net, 44:d9:e7:b5:09:73, channel:11, rssi:-64
I (5205) mesh: find router:[ssid_len:8]Meme_Net, rssi:-64, 44:d9:e7:b5:09:73(encrypted), new channel:11, old channel:6
I (5215) mesh: [FIND][ch:0]AP:20, otherID:0, MAP:2, idle:2, candidate:0, root:0[44:d9:e7:b5:27:02]router found
I (5225) mesh: [FIND:1]find a network, channel:6, cfg<channel:0, router:Meme_Net, 00:00:00:00:00:00>

I (5235) wifi: mode : sta (24:6f:28:f4:ae:d8) + softAP (24:6f:28:f4:ae:d9)
W (5245) wifi: <MESH AP>adjust channel:1, secondary channel offset:1(40U)
I (5255) wifi: Total power save buffer number: 8
W (5265) wifi: <MESH AP>adjust channel:6, secondary channel offset:1(40U)
I (5265) wifi: Total power save buffer number: 8
I (5565) mesh: [SCAN][ch:6]AP:10, other(ID:0, RD:0), MAP:2, idle:1, candidate:0, root:1, topMAP:0[c:0,i:0][44:d9:e7:b5:27:02]router found<>
I (5575) mesh: [FAIL][1]root:0, fail:1, normal:0, <pre>backoff:0

I (5875) mesh: [SCAN][ch:6]AP:7, other(ID:0, RD:0), MAP:1, idle:1, candidate:1, root:0, topMAP:0[c:0,i:0][44:d9:e7:b5:27:02]router found<>
I (5885) mesh: 6104[SCAN]init rc[ttl:127/votes:2][24:6f:28:f4:a6:39,-52]
I (5885) mesh: 1250, vote myself, router rssi:-41 > voted rc_rssi:-52
I (5895) mesh: [SCAN:1/10]rc[128][24:6f:28:f4:ae:d9,-41], self[24:6f:28:f4:ae:d8,-41,reason:0,votes:1,idle][mine:1,voter:2(0.50)percent:0.90][128,1,24:6f:28:f4:ae:d9]

I (6205) mesh: [SCAN][ch:6]AP:9, other(ID:0, RD:0), MAP:1, idle:1, candidate:1, root:0, topMAP:0[c:0,i:1][44:d9:e7:b5:27:02]router found<>
I (6215) mesh: [SCAN:2/10]rc[128][24:6f:28:f4:ae:d9,-41], self[24:6f:28:f4:ae:d8,-41,reason:0,votes:1,idle][mine:1,voter:2(0.50)percent:0.90][128,1,24:6f:28:f4:ae:d9]

I (6525) mesh: [SCAN][ch:6]AP:10, other(ID:0, RD:0), MAP:2, idle:1, candidate:0, root:1, topMAP:0[c:0,i:0][44:d9:e7:b5:27:02]router found<>
I (6525) mesh: [FAIL][4]root:2, fail:2, normal:0, <pre>backoff:0
Last edited by o.copleston on Thu May 21, 2020 10:56 am, edited 3 times in total.
Developer at SquidSoup
Person on Twitter | Instagram

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

Re: How can I trigger the creation of a new mesh network, once a mesh network is full?

Postby o.copleston » Mon Mar 09, 2020 11:23 pm

Until someone chimes in with a better solution, here's how I'm currently solving this problem. My main issue here is that the core mesh firmware is closed source and so I'm having to rely on the limited callback returns.

In my event loop event_loop_cb, I create the following case:

Code: Select all

// If a network is full, we must increase the MAC address
        case MDF_EVENT_MWIFI_NO_PARENT_FOUND: {
            MDF_LOGI("No Parent Found -- Changing mesh ID ");
            // Get current mesh ID
            mesh_addr_t old_mesh_id;
            esp_mesh_get_id(&old_mesh_id);
            MDF_LOGI("mesh_id: " MACSTR, MAC2STR(old_mesh_id.addr));
            old_mesh_id.addr[0]++;
            MDF_LOGI("mesh_id: " MACSTR, MAC2STR(old_mesh_id.addr));
            // old_mesh_id[0]++;
            // Set a new mesh ID of OLD_ID+1
            esp_mesh_set_id(&old_mesh_id);
            mwifi_print_config();
            break;
        }
When a node attempts to connect to a network and finds that it is full, it will increment the MESH_ID by one and try and join that network. If that network does not yet exist, it will assume itself as the root node.

Preferably, I would like nodes to evaluate whether a network is full before attempting to join it which would save considerable mesh setup time.
Developer at SquidSoup
Person on Twitter | Instagram

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

Re: How can I trigger the creation of a new mesh network, once a mesh network is full?

Postby o.copleston » Fri Apr 17, 2020 11:03 pm

As this post is getting a lot of views but no answers there's clearly some people having the same issue (hi there if you're just lurking!).

I found this post and I was lead to Espressif's example of manual networking.

-----
I'm still a bit confused by some of the core mesh functionality being left in the IDF as it makes navigating the documentation a bit tricky, I don't think I'm alone thinking this either - I hope Espressif are working to improve this.
-----

I think I've found a potential solution. Here are some of my recent untested findings

esp_wifi_scan_start() will trigger the event MESH_EVENT_SCAN_DONE upon completion. Within the event data itself, we can find the number of nodes that have been discovered.

Code: Select all

case MESH_EVENT_SCAN_DONE: {
        mesh_event_scan_done_t *scan_done = (mesh_event_scan_done_t *)event_data;
        ESP_LOGI(MESH_TAG, "<MESH_EVENT_SCAN_DONE>number:%d",
                 scan_done->number);
        mesh_scan_done_handler(scan_done->number);
}
"scan_done->number" Is a count of the number of IE (Information Elements) that have been returned by the probe requests.

Within the mesh_scan_done_handler() function, we can call the following functions:

Code: Select all

esp_mesh_scan_get_ap_ie_len(&ie_len);
esp_mesh_scan_get_ap_record(&record, &assoc);
The first one gives us the length of the IE (Information Element), the second gives us access to the IE itself.
assoc.mesh_id should give us the Mesh ID of the discovered network.

----

In summary, to find the IDs of existing mesh networks we need to trigger some code in the MESH_EVENT_SCAN_DONE callback to extract the mesh ID returned within the probe requests.
Developer at SquidSoup
Person on Twitter | Instagram

awilkie1
Posts: 2
Joined: Wed Jun 10, 2020 12:45 pm

Re: How can I trigger the creation of a new mesh network, once a mesh network is full? + how to get IDs of existing netw

Postby awilkie1 » Wed Jun 10, 2020 12:56 pm

Found a similar issue with the mesh networking, a huge drawback when you are trying to scale many devices. Hopefully espressif are aware of the issue and could provided an update?. Several people now waiting for this update...

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

Re: How can I trigger the creation of a new mesh network, once a mesh network is full? + how to get IDs of existing netw

Postby o.copleston » Wed Jun 10, 2020 1:05 pm

Upon further investigation, the MESH_EVENT_SCAN_DONE event can only be triggered by esp_wifi_scan_start(), and only when self organised networking has been disabled.
Unfortunately, the Information Elements returned by the scan do not contain any mesh data. This should not be the case, but I cannot figure out why because this piece of functionality is part of the closed-source mesh framework.

I've created a separate post dedicated to this issue.

It would be great if someone from Espressif could chime in on this, there's no doubt you've seen this thread by now...
Developer at SquidSoup
Person on Twitter | Instagram

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

Re: How can I trigger the creation of a new mesh network, once a mesh network is full? + how to get IDs of existing netw

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

Really sorry for so late reply.

Unfortunately, the Information Elements returned by the scan do not contain any mesh data.

The scan returns the non-mesh APs, mesh APs without mesh IE encrypt and mesh APs with mesh IE encrypt. You can always get the non-mesh APs and mesh APs without mesh IE encryt from the scan results. Regarding mesh APs with mesh IE encrypt, you may not get them.

If a node enables the mesh IE encrypt, you can't get its mesh IE unless you also enables the mesh IE encrypt, set the same crypto key and have the same mesh ID.
The mesh IE encrypt is enabled by esp_mesh_set_ie_crypto_funcs or set crypto_funcs field of mesh_config_t when call esp_mesh_set_config.

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

Re: How can I trigger the creation of a new mesh network, once a mesh network is full? + how to get IDs of existing netw

Postby o.copleston » Sun Jun 14, 2020 12:52 am

Hi ESP-QI, thanks for the response. Turning off Mesh IE encryption seems to do the trick - it would have been especially helpful to have that mentioned in the documentation here, given the number of views of this thread I reckon there's a large number of people out there that would find this information useful.

With 4 Root nodes, these are the results I see:

Code: Select all

W (6745) [mupgrade_subsystem, 171]: <MESH_EVENT_SCAN_DONE>number:31
W (6752) [mupgrade_subsystem, 220]: <MESH>[17]ESPM_F08468, layer:1/1, assoc:1/3, 0, 24:6f:28:f0:84:69, channel:11, rssi:-54, ID<02:00:00:00:00:00><IE Unencrypted>
W (6767) [mupgrade_subsystem, 220]: <MESH>[25]ESPM_F0E61C, layer:1/1, assoc:0/3, 0, 24:6f:28:f0:e6:1d, channel:11, rssi:-40, ID<06:00:00:00:00:00><IE Unencrypted>
W (6782) [mupgrade_subsystem, 220]: <MESH>[26]ESPM_F490C8, layer:1/1, assoc:0/3, 0, 24:6f:28:f4:90:c9, channel:11, rssi:-44, ID<07:00:00:00:00:00><IE Unencrypted>
W (6797) [mupgrade_subsystem, 220]: <MESH>[27]ESPM_F06D5C, layer:1/1, assoc:3/3, 0, 24:6f:28:f0:6d:5d, channel:11, rssi:-40, ID<04:00:00:00:00:00><IE Unencrypted>
It would appear that only root nodes appear in the scan.

WIFI_SCAN_TYPE_ACTIVE Yielded very poor results and couldn't reliably find all my root nodes each scan.
I got the best results by setting scan_type to WIFI_SCAN_TYPE_ACTIVE and setting relatively high min & max scan times, 800 & 1200 respectively. If you have any other recommendations to improve my scan results please let me know.

Is it at all possible to turn encryption on after a mesh network has been created, or to at least make it hidden after it has been set up?

I also notice that every time I scan, the previous results are cleared. Is it possible to make the previous results persist so I can run the scan multiple times to get better results?
Developer at SquidSoup
Person on Twitter | Instagram

Who is online

Users browsing this forum: No registered users and 31 guests