espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.75k stars 7.3k forks source link

ESP MESH - Cannot connect to router after self organizing disabled and then reenabled (IDFGH-5733) #7450

Closed mvarchdev closed 8 months ago

mvarchdev commented 3 years ago

Environment

Problem Description

The problem is simple but really annoying and cannot work with it. When the router is disconnected, the root will automatically switch to self organised disabled. When the router is found by the external task, the message of router found is broadcasted over the mesh (via esp_mesh_send() func.) and thereafter all nodes recognize this message and this code is executed on all nodes including root:

if (esp_mesh_is_root())
                    {
                        ESP_ERROR_CHECK_WITHOUT_ABORT(esp_mesh_disconnect());
                        ESP_ERROR_CHECK_WITHOUT_ABORT(esp_mesh_connect());
                    }
                    ESP_ERROR_CHECK_WITHOUT_ABORT(esp_mesh_set_self_organized(1, 1));

Expected Behavior

It should just connect to router.

Actual Behavior

It just scanning and trying to connect infinitely.

Steps to reproduce

  1. Create example of mesh internal communication
  2. Wait for the router is connected. then disable self organizing from mesh event callback - handler.
  3. wati appr. 10 sec. (vtaskdelay)
  4. then reenable the self organiziing:
    ESP_ERROR_CHECK_WITHOUT_ABORT(esp_mesh_set_self_organized(1, 1));

Debug Logs

logmesh.log

vinicius-smartme commented 2 years ago

I am having the same problem. I am following the example described here esp-wifi-mesh.

What I am doing is to disable the auto wifi scan when I cannot find a router. I have a timer where I try to re-enable it after 10 seconds.

To stop/disable the auto scan I am doing:

//Disable self organized networking
esp_mesh_set_self_organized(0, 0);

//Stop any scans already in progress
esp_wifi_scan_stop();

To re-enable the auto scan I am doing:

esp_wifi_scan_start();

//At the SCAN_DONE event
//Re-enable self organized networking if root and disconnected
esp_mesh_set_self_organized(1, 0);  //Don't select new parent
vinicius-smartme commented 2 years ago

It seems another issue that when there is no router (manual mesh networking), the root keeps scanning for the router and it causes the mesh to have a poor performance, once the scanning is "occupying" the wifi. This is causing the mesh to loose lots of packets.

shenjun7 commented 2 years ago

If the manual networking node cannot find the parent, it will always scan. Setting up a network without a router can be achieved by setting fix-root esp_mesh_fix_root(true) esp_mesh_set_type().

vinicius-smartme commented 2 years ago

The esp_mesh_fix_root(true) doesn't apply to my case, as I don't want to manually define the root, but to use the self organized feature. The esp_mesh_set_type() is defined as IDLE at the initialization.

vinicius-smartme commented 2 years ago

If the manual networking node cannot find the parent, it will always scan. Setting up a network without a router can be achieved by setting fix-root esp_mesh_fix_root(true) esp_mesh_set_type().

@shenjun7, why did I receive the same response for a different issue here ?

shenjun7 commented 2 years ago

The self-organized network will elect a new root after the root leaves within a specific time. You can increase the disconnection detection time so that root does not re-elect by esp_mesh_set_ap_assoc_expire().

vinicius-smartme commented 2 years ago

The self-organized network will elect a new root after the root leaves within a specific time. You can increase the disconnection detection time so that root does not re-elect by esp_mesh_set_ap_assoc_expire().

The esp_mesh_set_ap_assoc_expire() does not affect the the problem, as I can wait many minutes and no root is setup. The default value for esp_mesh_set_ap_assoc_expire() is 10 seconds and works in normal router disconnection.

Alvin1Zhang commented 8 months ago

Thanks for reporting, feel free to reopen. Thanks.

kieennt13 commented 1 week ago

If the manual networking node cannot find the parent, it will always scan. Setting up a network without a router can be achieved by setting fix-root esp_mesh_fix_root(true) esp_mesh_set_type().

Hi @shenjun7 , How should I setting mesh_config.router in the no router manual networking scenario? If I use a dummy SSID for mesh_config.router, set esp_mesh_set_type(MESH_ROOT) and comment out the Wifi scan functions, root is just showing this and nothing else:

I (23768) wifi:Set ps type: 0

I (23778) wifi:mode : sta (ac:67:b2:c8:b3:70) + softAP (ac:67:b2:c8:b3:71)
I (23778) wifi:Total power save buffer number: 16
I (23778) wifi:Init max length of beacon: 752/752
I (23778) wifi:Init max length of beacon: 752/752
I (23788) mesh: <nvs>read layer:0, err:0x1102
I (23788) mesh: <nvs>read assoc:0, err:0x1102
I (23798) mesh: [IO]disable self-organizing<reconnect>
I (23808) wifi:Total power save buffer number: 16
I (23958) wifi:state: run -> init (0)
I (23958) wifi:pm stop, total sleep time: 15558382 us / 22060505 us

I (23958) wifi:<ba-del>idx
I (23958) wifi:<ba-del>idx
I (23958) wifi:new:<1,0>, old:<1,0>, ap:<1,1>, sta:<1,0>, prof:1
wifi_reconnect_task: 0
I (23968) wifi station: connect to the AP fail
I (23978) mesh_main: <MESH_EVENT_STARTED>ID:77:77:77:77:77:76
I (23978) mesh: [CONFIG]connect to router:XXLL, 00:00:00:00:00:00
-------------------SUCCESS
I (23978) mesh_main: mesh starts successfully, heap:83240

I (24018) mesh: [IO]disable self-organizing<stop reconnect>
I (24038) mesh: <MESH_NWK_PARENT_DISCONNECTED>already disconnected, ignore it
I (26858) wifi station: connect to the AP fail
I (26858) mesh_main: <MESH_EVENT_PARENT_DISCONNECTED>reason:201
I (26858) mesh: [wifi]disconnected reason:201(), continuous:1/max:12, root, vote(,)<><>
I (26868) mesh: <mesh_nwk_task_main,4587>parent is set<stop reconnect>g_is_wifi_connecting:0, g_is_wifi_disconnecting:0, g_mesh_stop_reconnection:1

Does this mean I've succeed? Or if not, what kind of log it should printed out?

Also, when I turn on a manual designed idle node and scan for APs, the root node appeared like this:

I (16557) mesh_main: [0], ac:67:b2:c8:b3:71, channel:1, rssi:-31

and as the result, idle node keeps scanning and so on. Why there's no SSID for root node and how to fix it, so the idle node can connects to it?