esp-now: ESPNOW stops receiving when ESP32-S3 in STA mode connects to WiFi AP (AEGHB-94)
I created a minimalist code to show the issue. Yes I disabled power saving and it is not about setting the channel on the sender. I took the new channel that was set by the AP of my router and put it in the sender. Then the espnow stops arriving once the esp is connected to AP. I even made a sender that keeps sending over all WiFi channels. You can use your sender example and then my code on the receiver to witness the issue.
IDF 5.0 and 5.0.1
/*
This example shows how to use ESPNOW.
Prepare two device, one for sending ESPNOW data and another for receiving
ESPNOW data.
*/
#include <stdlib.h>
#include "nvs_flash.h"
#include "esp_random.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_now.h"
static const char *TAG = "espnow_example";
static void wifi_event_handler(void* arg, esp_event_base_t event_base,int32_t event_id, void* event_data){
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
esp_wifi_connect(); // <------ 2- comment this line to get ESPNOW to work, uncomment to break ESPNOW. ( Sender is using the new channel yes)
}
}
static void example_wifi_init(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL));
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
esp_wifi_set_ps(WIFI_PS_NONE);// <------ it is set
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
wifi_config_t wifi_config = {
.sta = {
.ssid = "", // <------ 1- set your AP so esp can connect to
.password = "",
.sae_pwe_h2e = WPA3_SAE_PWE_UNSPECIFIED,
},
};
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK( esp_wifi_start());
}
static void example_espnow_send_cb(const uint8_t *mac_addr, esp_now_send_status_t status)
{
}
static void example_espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data, int len)
{
ESP_LOGE(TAG, "Got ESPNOW msg");
}
static esp_err_t example_espnow_init(void)
{
ESP_ERROR_CHECK( esp_now_init() );
ESP_ERROR_CHECK( esp_now_register_send_cb(example_espnow_send_cb) );
ESP_ERROR_CHECK( esp_now_register_recv_cb(example_espnow_recv_cb) );
/* Set primary master key. Disable in sender for simplicity, even though it does not matter for this bug */
//ESP_ERROR_CHECK( esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK) );
return ESP_OK;
}
void app_main(void)
{
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 );
example_wifi_init();
example_espnow_init();
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 22
Commits related to this issue
- change addr3 to broadcast for ESPNOW Closes https://github.com/espressif/esp-now/issues/57 — committed to hardycheng-github/esp8266_rtos_sdk by zhangyanjiaoesp a year ago
@lhespress Yes now it works with the RTOS_sdk! Thanks! Could you port the fix to NonOS too? Majority of users still use Arduino/NonOS and plarformio to develop on esp8266. It is also big task for me to port the code to RTOS_sdk, I might face new issues or non-matching APIs. Then there would be more work to power profile the new firmware, as the old one went through that testing already. All those delays in production will have really bad impact on our company.
@AmirHmZz @ramiws The fix is under the internal reviewing, you can replace the library and check again. libnet80211.a.zip