ESP-MESH without a router

daniweb
Posts: 6
Joined: Fri Feb 16, 2024 9:12 am

Re: ESP-MESH without a router

Postby daniweb » Wed Mar 13, 2024 10:36 am

I found that an approach is to use the MESH-LITE

nicoDHX
Posts: 2
Joined: Mon Jul 29, 2024 4:25 pm

Re: ESP-MESH without a router

Postby nicoDHX » Mon Jul 29, 2024 4:31 pm

Snedig wrote:
Sat Apr 04, 2020 3:31 pm
Hi,

I am trying to set up a WiFi MESH-network without a router (root node will transmit information via onboard 4G), and I am using ESP-IDF to support chain topology.

I have managed to make the mesh connect nicely, nodes are recognized and the root is set based on external criteria (currently just a strap on a GPIO).

However, none of my messages seem to be received on any of the devices whatever I do.

The relevant parts of my code are:
Mesh init (all router settings commented out):

Code: Select all

mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
    /* mesh ID */
    memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
    /* router */
    //cfg.channel = CONFIG_MESH_CHANNEL;
    //cfg.router.ssid_len = strlen(CONFIG_MESH_ROUTER_SSID);
    //memcpy((uint8_t *) &cfg.router.ssid, CONFIG_MESH_ROUTER_SSID, cfg.router.ssid_len);
    //memcpy((uint8_t *) &cfg.router.password, CONFIG_MESH_ROUTER_PASSWD,
           //strlen(CONFIG_MESH_ROUTER_PASSWD));*/
    /* mesh softAP */
    ESP_ERROR_CHECK(esp_mesh_set_ap_authmode(CONFIG_MESH_AP_AUTHMODE));
    cfg.mesh_ap.max_connection = CONFIG_MESH_AP_CONNECTIONS;
    memcpy((uint8_t *) &cfg.mesh_ap.password, CONFIG_MESH_AP_PASSWD,
           strlen(CONFIG_MESH_AP_PASSWD));
    ESP_ERROR_CHECK(esp_mesh_set_config(&cfg));
This returns " mesh: [MANUAL]designated as root and router is not set".

My mesh_send commands look like this:

Code: Select all

//node send to root
err = esp_mesh_send(NULL, &data, MESH_DATA_P2P, NULL, 0);

//root send to nodes
for (i = 0; i < route_table_size; i++) {
err = esp_mesh_send(&route_table[i], &data, MESH_DATA_P2P, NULL, 0);
}
This all works perfectly fine when a router is connected, but not at all when I do not have a router connected.

I would be thankful for any tips as I'm banging my head against the wall at the moment.. :)
Hellow, how you manage to set a mesh without router in automode with this? i did this an i get:

Code: Select all

I (941) mesh: [CONFIG]invalid router settings, ssid_len:0, ssid:, bssid:00:00:00:00:00:00
ESP_ERROR_CHECK failed: esp_err_t 0x4008 (ESP_ERR_MESH_ARGUMENT) at 0x42009fdc
file: "./main/mesh_main.c" line 469
func: app_main
expression: esp_mesh_set_config(&cfg)

TRUEcabbage
Posts: 1
Joined: Fri Aug 16, 2024 9:01 am

Re: ESP-MESH without a router

Postby TRUEcabbage » Thu Aug 22, 2024 10:01 am

Hello there, here is the answer... Yes it is possible to setup esp-wifi-mesh without a router, but Self-organized network, wont work for ROOT node, ie the mesh network cant set root because there is no router to connect to.. so we have to set root esp and node esp manually, here is the code snippet for root esp
  1.     ESP_ERROR_CHECK(nvs_flash_init());
  2.     /*  tcpip initialization */
  3.     ESP_ERROR_CHECK(esp_netif_init());
  4.     /*  event initialization */
  5.     ESP_ERROR_CHECK(esp_event_loop_create_default());
  6.     /*  create network interfaces for mesh (only station instance saved for further manipulation, soft AP instance ignored */
  7.     ESP_ERROR_CHECK(esp_netif_create_default_wifi_mesh_netifs(&netif_sta, NULL));
  8.     /*  wifi initialization */
  9.     wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
  10.     ESP_ERROR_CHECK(esp_wifi_init(&config));
  11.  
  12.  
  13.     ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
  14.     ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
  15.     // ESP_ERROR_CHECK(esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_LR));
  16.     // ESP_ERROR_CHECK(esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_LR));  
  17.     ESP_ERROR_CHECK(esp_wifi_start());
  18.     ESP_ERROR_CHECK(esp_wifi_set_max_tx_power(80));  // Set TX power to 20.5 dBm (maximum)
  19.     /*  gets this esp mac address, to prevent sending message to itself */
  20.     esp_wifi_get_mac(WIFI_IF_STA, my_address.addr);
  21.  
  22.     /*  mesh initialization */
  23.     ESP_ERROR_CHECK(esp_mesh_init());
  24.     ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));
  25.     /*  set mesh topology */
  26.     ESP_ERROR_CHECK(esp_mesh_set_topology(MESH_TOPO_TREE));
  27.     /*  set mesh max layer according to the topology */
  28.     ESP_ERROR_CHECK(esp_mesh_set_max_layer(6));
  29.     ESP_ERROR_CHECK(esp_mesh_set_vote_percentage(1));
  30.     ESP_ERROR_CHECK(esp_mesh_set_xon_qsize(128));
  31.  
  32.     /* Disable mesh PS function */
  33.     ESP_ERROR_CHECK(esp_mesh_disable_ps());
  34.     ESP_ERROR_CHECK(esp_mesh_set_ap_assoc_expire(10));
  35.  
  36.     /* set this esp as root node*/
  37.     ESP_ERROR_CHECK(esp_mesh_set_type(MESH_ROOT));
  38.    
  39.     mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
  40.     /* mesh ID */
  41.     memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
  42.     /* router */
  43.     cfg.channel = 0;
  44.  
  45.     /* mesh softAP */
  46.     ESP_ERROR_CHECK(esp_mesh_set_ap_authmode(WIFI_AUTH_WPA_WPA2_PSK));
  47.     cfg.mesh_ap.max_connection = 6;
  48.     cfg.mesh_ap.nonmesh_max_connection = 0;
  49.     memcpy((uint8_t *) &cfg.mesh_ap.password, CONFIG_MESH_AP_PASSWD,
  50.            strlen(CONFIG_MESH_AP_PASSWD));
  51.     ESP_ERROR_CHECK(esp_mesh_set_config(&cfg));
  52.  
  53.     /* mesh start */
  54.     ESP_ERROR_CHECK(esp_mesh_start());
  55.     ESP_LOGE("MESH", "mesh starts successfully, heap:%" PRId32 ", %s<%d>%s, ps:%d",  esp_get_minimum_free_heap_size(),
  56.              esp_mesh_is_root_fixed() ? "root fixed" : "root not fixed",
  57.              esp_mesh_get_topology(), esp_mesh_get_topology() ? "(chain)":"(tree)", esp_mesh_is_ps_enabled());
  58.    
  59.     #if (ENABLE_TCP_DISABLE_SERIAL == 1)
  60.         server.begin();
  61.         server.setNoDelay(true);
  62.     #else
  63.         serialFlushRx();
  64.     #endif
  65.     esp_mesh_comm_p2p_start();
node esp
  1.     ESP_ERROR_CHECK(nvs_flash_init());
  2.     /*  tcpip initialization */
  3.     ESP_ERROR_CHECK(esp_netif_init());
  4.     /*  event initialization */
  5.     ESP_ERROR_CHECK(esp_event_loop_create_default());
  6.     /*  create network interfaces for mesh (only station instance saved for further manipulation, soft AP instance ignored */
  7.     ESP_ERROR_CHECK(esp_netif_create_default_wifi_mesh_netifs(&netif_sta, NULL));
  8.     /*  wifi initialization */
  9.     wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
  10.     ESP_ERROR_CHECK(esp_wifi_init(&config));
  11.  
  12.     /* Set the maximum Wi-Fi TX power */
  13.     //ESP_ERROR_CHECK(esp_wifi_set_max_tx_power(80));  // Set TX power to 20.5 dBm (maximum)
  14.     ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
  15.     ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
  16.  
  17.     ESP_ERROR_CHECK(esp_wifi_start());
  18.     ESP_ERROR_CHECK(esp_wifi_set_max_tx_power(80));  // Set TX power to 20.5 dBm (maximum)
  19.    
  20.     /*  mesh initialization */
  21.     ESP_ERROR_CHECK(esp_mesh_init());
  22.     ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));
  23.     /*  set mesh topology */
  24.     ESP_ERROR_CHECK(esp_mesh_set_topology(MESH_TOPO_TREE));
  25.     //ESP_ERROR_CHECK(esp_mesh_set_topology(MESH_TOPO_CHAIN));
  26.     /*  set mesh max layer according to the topology */
  27.     ESP_ERROR_CHECK(esp_mesh_set_max_layer(6));
  28.     ESP_ERROR_CHECK(esp_mesh_set_vote_percentage(1));
  29.     ESP_ERROR_CHECK(esp_mesh_set_xon_qsize(128));
  30.  
  31.     /* Disable mesh PS function */
  32.     ESP_ERROR_CHECK(esp_mesh_disable_ps());
  33.     ESP_ERROR_CHECK(esp_mesh_set_ap_assoc_expire(10));
  34.  
  35.     /* set this esp as node*/
  36.     ESP_ERROR_CHECK(esp_mesh_set_type(MESH_IDLE));
  37.  
  38.     mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
  39.     /* mesh ID */
  40.     memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
  41.     /* router */
  42.     cfg.channel = 0;
  43.     /* informs this esp that root is already set */
  44.     ESP_ERROR_CHECK(esp_mesh_fix_root(true));
  45.  
  46.     /* mesh softAP */
  47.     ESP_ERROR_CHECK(esp_mesh_set_ap_authmode(WIFI_AUTH_WPA_WPA2_PSK));
  48.     cfg.mesh_ap.max_connection = 6;
  49.     cfg.mesh_ap.nonmesh_max_connection = 0;
  50.     memcpy((uint8_t *) &cfg.mesh_ap.password, CONFIG_MESH_AP_PASSWD,
  51.            strlen(CONFIG_MESH_AP_PASSWD));
  52.     ESP_ERROR_CHECK(esp_mesh_set_config(&cfg));
  53.  
  54.  
  55.  
  56.     /* mesh start */
  57.     ESP_ERROR_CHECK(esp_mesh_start());
  58.     ESP_LOGE("MESH", "mesh starts successfully, heap:%" PRId32 ", %s<%d>%s, ps:%d",  esp_get_minimum_free_heap_size(),
  59.              esp_mesh_is_root_fixed() ? "root fixed" : "root not fixed",
  60.              esp_mesh_get_topology(), esp_mesh_get_topology() ? "(chain)":"(tree)", esp_mesh_is_ps_enabled());
  61.    
  62.     serialFlushRx();
and also mesh event handler when MESH_EVENT_PARENT_CONNECTED didnt get trigger on root

Who is online

Users browsing this forum: No registered users and 138 guests