I'm trying to build a Wifi mesh network of esp32,
I'm using the m5stack-core2 board, the espressif32@3.2.1 version of the platform and espidf.
To be able to use both Wifi and BLE (same phy is used) I set ble window and interval parameters to share the phy.
So for the BLE scanning I've set a window to allow the esp32 to scan for proximity beacon, here is the relevant part:
* BLE scan parameters
* task creation (analyse_data) to analyse the beacons seen, does not matter for this post
Code: Select all
/////////////////////
// main code
/////////////////////
// ...
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
esp_bt_controller_init(&bt_cfg);
esp_bt_controller_enable(ESP_BT_MODE_BLE);
ble_ibeacon_init();
ESP_LOGI(TAG, "heap free size ble init done: %d", esp_get_free_heap_size());
// Enable BLE scanner
static esp_ble_scan_params_t ble_scan_params = {
.scan_type = BLE_SCAN_TYPE_ACTIVE,
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
.scan_interval = 0x3000, // interval is 7,7 seconds
.scan_window = 0x2000, // scanning window is 5,1 seconds
.scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE};
esp_ble_gap_set_scan_params(&ble_scan_params);
ret_create_task = xTaskCreate(analyse_data, /* Task function. */
"Analyse beacons", /* name of task. */
STACK_SIZE, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
NULL
);
Code: Select all
/* tcpip initialization */
ESP_ERROR_CHECK(esp_netif_init());
/* event initialization */
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* crete network interfaces for mesh */
ESP_ERROR_CHECK(mesh_netifs_init(recv_cb));
/* wifi initialization */
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&config));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-power-saving-mode
// Disabling modem sleep entirely is not possible for Wi-Fi and Bluetooth coexist mode.
// set min wifi sleep for nodes
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
ESP_ERROR_CHECK(esp_wifi_start());
/* mesh initialization */
ESP_ERROR_CHECK(esp_mesh_init());
ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));
/* parameter to optimize the mesh for my application:
* - don't care about battery, running on power
* - due to BLE window, node may not be seen as often as expected
*/
ESP_ERROR_CHECK(esp_mesh_disable_ps());
ESP_ERROR_CHECK(esp_mesh_set_ap_assoc_expire(60));
ESP_ERROR_CHECK(esp_mesh_set_announce_interval(600, 3300));
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(wifi_ssid);
memcpy((uint8_t *)&cfg.router.ssid, wifi_ssid, cfg.router.ssid_len);
memcpy((uint8_t *)&cfg.router.password, wifi_pwd, strlen(wifi_pwd));
// /* 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));
ESP_ERROR_CHECK(esp_mesh_start());
ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d, %s<%d>%s, ps:%d\n", esp_get_minimum_free_heap_size(),
esp_mesh_is_root_fixed() ? "root fixed" : "root not fixed",
esp_mesh_get_topology(), esp_mesh_get_topology() ? "(chain)":"(tree)", esp_mesh_is_ps_enabled());
- they see enough beacons for my purposes
- they are able to connect to my cloud server to send the data
However nodes of the layer 3 or more never manage to join the mesh.
I've tried this set of parameters for the BLE window / interval:
Code: Select all
.scan_interval = 0x1800, // interval is 3.840 seconds
.scan_window = 0x1000, // scanning window is 2.560 seconds
If I use a small interval e.g. 50 ms with a BLE scanning window of 30 ms, then I miss too many beacons for my application to work (beacons emit every 1s or possible every 500 ms) and I want to see at least 1 every 5s. And I'm not sure mesh works fine with these parameters
My guess are:
- mesh cannot be formed due to the BLE scan window
- beacons are not seen when forming the mesh
- the mesh creation is "too fast" to cope with the scan window
I don't have the source code (not possible to get an access I guess ?), and I did not find a parameter to slow down the mesh creation process.
- I don't really care if it takes a few minutes to form the network
- All nodes will be plugged, so I'm expecting to lose any and I can cope without network for some time, so it doesn't matter to me if mesh healing time is high (even hours would be enough for me)
I've tried to set longer beacons interval hoping the mesh will cope without receiving beacons,
Code: Select all
// after mesh start
ESP_ERROR_CHECK(esp_mesh_set_beacon_interval(4000));
If I remove the BLE task and thus the window for the phy access, the nodes of layer 3 can join the network and send data to the cloud (not yet tested more layers)
Do you any solutions? suggestions?
Kind regards,
Maxime