Create a stable ESP-NOW connection
Posted: Tue Aug 29, 2023 5:04 pm
Hello everyone,
I'm currently working on a project with multiple ESP32s communicating via ESP-NOW. I need some guidance regarding the consistent reception of sent messages, and I hope the community can assist me.
Issue: In my setup, I have several ESP32s exchanging messages every 5 seconds. However, I've noticed that the message reception isn't always as reliable as expected. There are instances where there's a delay in devices connecting, and sometimes, there are gaps of 10, 20, or even 60 seconds without any received messages.
I've done some research and tried tweaking both the code and menuconfig settings, but I haven't been able to achieve the desired level of message reception reliability.
If anyone has faced similar challenges or has advice on improving the reception of ESP-NOW messages, I would greatly appreciate your insights. Any practical tips or suggestions would be incredibly helpful as I continue to refine my project.
Thank you in advance for your expertise and assistance.
Code for sending:
I'm currently working on a project with multiple ESP32s communicating via ESP-NOW. I need some guidance regarding the consistent reception of sent messages, and I hope the community can assist me.
Issue: In my setup, I have several ESP32s exchanging messages every 5 seconds. However, I've noticed that the message reception isn't always as reliable as expected. There are instances where there's a delay in devices connecting, and sometimes, there are gaps of 10, 20, or even 60 seconds without any received messages.
I've done some research and tried tweaking both the code and menuconfig settings, but I haven't been able to achieve the desired level of message reception reliability.
If anyone has faced similar challenges or has advice on improving the reception of ESP-NOW messages, I would greatly appreciate your insights. Any practical tips or suggestions would be incredibly helpful as I continue to refine my project.
Thank you in advance for your expertise and assistance.
void init_esp_now() {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
esp_wifi_init(&cfg);
esp_wifi_set_mode(WIFI_MODE_STA);
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR);
esp_wifi_start();
esp_wifi_set_ps(WIFI_PS_NONE);
esp_now_init();
esp_wifi_set_max_tx_power(20);
esp_now_register_recv_cb(espnow_recv_cb);
esp_now_register_send_cb(espnow_send_cb);
esp_now_peer_info_t peer_info;
memset(&peer_info, 0, sizeof(peer_info));
for (int i = 0; i < 6; ++i) {
peer_info.peer_addr = 0xFF;
}
peer_info.channel = 0;
peer_info.encrypt = false;
esp_err_t add_peer_status = esp_now_add_peer(&peer_info);
if (add_peer_status != ESP_OK) {
ESP_LOGE(TAG, "Fout bij het toevoegen van peer, status: %d", add_peer_status);
return;
}
}
Code for sending:
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
const char *msg = "test";
esp_now_send(broadcast_mac, (uint8_t *)msg, strlen(msg));