ESPMesh and smart config

leenowell
Posts: 142
Joined: Tue Jan 15, 2019 1:50 pm

ESPMesh and smart config

Postby leenowell » Fri Jan 10, 2025 7:06 pm

Hi All,

I am trying to integrate smart config into my mesh project. I am essentially using the smart config example but kicking off the smart config task when I get a MESH_EVENT_NO_PARENT_FOUND in the mesh handler. The log is
I (21552) mesh: <MESH_NWK_LOOK_FOR_NETWORK>need_scan:0x3, need_scan_router:0x1, look_for_nwk_count:60
I (21682) wifi_node: WIFINodeEvent: Unknown WiFi event [1]
I (21682) mesh: [S1]Lounge, f0:86:20:13:b4:33, channel:11, rssi:-39
I (21682) mesh: find router:[ssid_len:6]Lounge, rssi:-39, f0:86:20:13:b4:33(encrypted), new channel:11, old channel:0
I (21692) mesh: [S1]ignore Lounge, channel:11 due to different auth mode(3) from mine(open)
I (21702) mesh: [FIND][ch:11]AP:1, otherID:0, MAP:0, idle:0, candidate:0, root:0[00:00:00:00:00:00]<scan router>
I (21712) mesh: [FIND:60]fail to find a network, channel:0, cfg<channel:11, router:Lounge, 00:00:00:00:00:00>

I (21722) mesh: <MESH_NWK_LOOK_FOR_NETWORK>need_scan:0x3, need_scan_router:0x0, look_for_nwk_count:61
I (21732) mesh: <MESH_NWK_LOOK_FOR_NETWORK>no parent found, set ROOTLESS, scan times:60, heap:176296
I (21742) mesh: <MESH_NWK_LOOK_FOR_NETWORK>router<cfg:00:00:00:00:00:00> is allowed to switch, find routers with SSID:Lounge
I (21742) mesh_node: MeshNodeEvent: <MESH_EVENT_NO_PARENT_FOUND>scan times:60
I (21752) mesh: <MESH_NWK_PARENT_DISCONNECTED>non-root, need_reselect:1
I (21762) HomeIoT: cbOnMeshNoParent: Parent has gone setting Meshconnected to false
I (21762) wifi_node: wifi_node_smart_config_task: setting SC type
I (21782) wifi_node: wifi_node_smart_config_task: starting SC
I (21782) smartconfig: smartconfig errno -1@sc_sniffer.c 573
I (21792) wifi_node: WIFINodeEvent: Unknown WiFi event [1]
I (21792) mesh: <WIFI_EVENT_SCAN_DONE>status:fail, num:1, id:188
I (21802) mesh: [FIND][ch:11]AP:1, otherID:0, MAP:0, idle:0, candidate:0, root:0[00:00:00:00:00:00]
I (21812) mesh: [FIND:61]fail to find a network, channel:0, cfg<channel:11, router:Lounge, 00:00:00:00:00:00>

I (21822) mesh: <MESH_NWK_LOOK_FOR_NETWORK>need_scan:0x3, need_scan_router:0x1, look_for_nwk_count:62
I (21842) smartconfig: SC version: V3.0.2
I (21842) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (21842) smartconfig: scan status 1
I (21892) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (21892) smartconfig: scan status 4
I (21942) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (21942) smartconfig: scan status 1
I (21992) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (21992) smartconfig: scan status 4
I (22042) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (22042) wifi_node: WIFINodeEvent: Unknown WiFi event [1]
I (22042) mesh: [FIND][ch:11]AP:0, otherID:0, MAP:0, idle:0, candidate:0, root:0[00:00:00:00:00:00]<scan router>
I (22042) mesh: [FIND:62]fail to find a network, channel:0, cfg<channel:11, router:Lounge, 00:00:00:00:00:00>

I (22052) mesh: <MESH_NWK_LOOK_FOR_NETWORK>need_scan:0x3, need_scan_router:0x0, look_for_nwk_count:63
I (22112) wifi_node: WIFINodeEvent: Unknown WiFi event [1]
I (22112) mesh: [FIND][ch:11]AP:1, otherID:0, MAP:0, idle:0, candidate:0, root:0[00:00:00:00:00:00]
I (22112) mesh: [FIND:63]fail to find a network, channel:0, cfg<channel:11, router:Lounge, 00:00:00:00:00:00>
Has anyone managed to get this working? I managed to get it working before (http://esp32.io/viewtopic.php?f=21&t=90 ... 9be3a1b4ba) but that was some time ago and on a much earlier version.

Many thanks

Lee.

leenowell
Posts: 142
Joined: Tue Jan 15, 2019 1:50 pm

Re: ESPMesh and smart config

Postby leenowell » Sat Jan 11, 2025 9:42 am

Hi,

Quick update. I finally found something that said that you can't use wifi commands whilst the mesh is in self organise mode. So I turned this off first but it didn't make any difference.

new code for the smart config task

Code: Select all

void wifi_node_smart_config_task (void *parm)
{
	// disable mesh self organise to prevent mesh and SC conflicting
	esp_mesh_set_self_organized(0, 0);// LEE this was to try and fix smart config in Mesh compatibility
    EventBits_t uxBits;
ESP_LOGI(WIFI_NODE_TAG, "wifi_node_smart_config_task: setting SC type");
    ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
    smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
ESP_LOGI(WIFI_NODE_TAG, "wifi_node_smart_config_task: starting SC");
    ESP_ERROR_CHECK( esp_smartconfig_start(&cfg) );
    while (1) {
        uxBits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
        if(uxBits & CONNECTED_BIT) {
            ESP_LOGI(WIFI_NODE_TAG, "WiFi Connected to ap");
        }
        if(uxBits & ESPTOUCH_DONE_BIT) {
            ESP_LOGI(WIFI_NODE_TAG, "smartconfig over");
            esp_smartconfig_stop();
			// reenable mesh self organise to prevent mesh and SC conflicting
            esp_mesh_set_self_organized(1, 1);  // LEE this was to try and fix smart config in Mesh compatibility
            vTaskDelete(NULL);
        }
    }
	
}

The new log is
I (21752) mesh_node: MeshNodeEvent: <MESH_EVENT_NO_PARENT_FOUND>scan times:60
I (21762) mesh: <MESH_NWK_PARENT_DISCONNECTED>non-root, need_reselect:1
I (21762) HomeIoT: cbOnMeshNoParent: Parent has gone setting Meshconnected to false
I (21772) mesh: [IO]disable self-organizing<stop reconnect>
I (21782) wifi_node: wifi_node_smart_config_task: setting SC type
I (21792) wifi_node: wifi_node_smart_config_task: starting SC
I (21792) smartconfig: smartconfig errno -1@sc_sniffer.c 573
I (21802) wifi_node: WIFINodeEvent: Unknown WiFi event [1]
I (21802) mesh: <WIFI_EVENT_SCAN_DONE>status:fail, num:0, id:188
I (21852) smartconfig: SC version: V3.0.2
I (21852) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (24262) smartconfig: smartconfig errno -1@sc_sniffer.c 535
I (26682) wifi:ic_enable_sniffer
I (26682) smartconfig: Start to find channel...
I (26682) wifi_node: WIFINodeEvent: Unknown WiFi event [43]
I (26682) wifi_node: SmartConfigEvent: Scan done
I (26832) wifi_node: WIFINodeEvent: Unknown WiFi event [43]
I (26982) wifi_node: WIFINodeEvent: Unknown WiFi event [43]
Really appreciate any help on this

Thanks

Lee.

leenowell
Posts: 142
Joined: Tue Jan 15, 2019 1:50 pm

Some success: ESPMesh and smart config

Postby leenowell » Sat Jan 11, 2025 12:43 pm

Hi All,

I have had some success. If I stop the mesh first then start smart config then it correctly gets the SSID/ Password from smart config and wifi connects to the router with the new credentials. So far so good. When I receive a WIFI_EVENT_STA_CONNECTED event, I try to restart the mesh but it fails.

If I call esp_mesh_start I get an ESP_ERR_MESH_NOT_INIT error. Calling esp_mesh_init before esp_mesh_start I then get ESP_ERR_MESH_NOT_CONI.

So I think the sequence should be
esp_mesh_init
esp_mesh_set_config
esp_mesh_start

However, now I get ESP_ERR_MESH_NOT_ALLOWED when I call esp_mesh_set_config.

Firstly do I need to stop the mesh before starting smart config? If so, how do I then correctly restart the mesh?

Thanks

Lee.

leenowell
Posts: 142
Joined: Tue Jan 15, 2019 1:50 pm

BUG Workaround: ESPMesh and smart config

Postby leenowell » Mon Jan 13, 2025 8:11 pm

Hi,

I have tried a variety of things to try and get this working properly but still can't get past the issues above. I believe there is a bug somewhere.

To try and get my project up and running I have created a workaround which isn't great but at least works. Hoping it might help others whilst we wait for someone to look at this. Having started the mesh, if I get a MESH_EVENT_NO_PARENT_FOUND event I start a new task to run the smart config. This stops the mesh and kicks off the smart config process. Once the smart config gets the credentials I store them in nvs and restart the device. On startup I look for the config in nvs and if it is there use that in the mesh config and start the mesh.

The other thing I discovered is that if the channel is set to 0 (I had defaulted the struct I was using to { 0 } and there is no channel info in smartconfig_event_got_ssid_pswd_t so it never got reset) it takes forever to try to connect to the router each time. So in smart config I got the channel and stored that with the SSID/ Password. You could default it to 1 or something which seems to resolve it too and then wifi I guess scans for the actual channel.

Thanks

Lee.

Who is online

Users browsing this forum: No registered users and 5 guests