ESPNOW
Posted: Thu Oct 05, 2023 2:41 am
Good evening, I have been facing problems on some devices in my ESPNOW deployment. The devices communicate for a while and only lock the ESPNOW side and communication only returns after the chip is reset. Here is a snippet of my Wifi initialization code and the espnow stack:
Code: Select all
void wifi_init()
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); //configutações padrão do wifi
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); //inicia com as configurações padrões
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); //amarzena configuração na memória
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); //modo STA
ESP_ERROR_CHECK(esp_wifi_start()); //inicia Wifi
}
/* inicia esp_now */
esp_err_t espnow_init(void)
{
/* Initialize ESPNOW and register sending and receiving callback function. */
ESP_ERROR_CHECK(esp_now_init());
ESP_ERROR_CHECK(esp_now_register_recv_cb(OnDataRecv));
/* Seta chave primaria */
ESP_ERROR_CHECK(esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK));
/* adiciona dispositivo a lista */
esp_now_peer_info_t *peer = malloc(sizeof(esp_now_peer_info_t));
if (peer == NULL)
{
esp_now_deinit();
return ESP_FAIL;
}
memset(peer, 0, sizeof(esp_now_peer_info_t));
peer->channel = CONFIG_ESPNOW_CHANNEL;
peer->ifidx = ESP_IF_WIFI_STA;
peer->encrypt = false;
memcpy(peer->peer_addr, MACCONTROLE, ESP_NOW_ETH_ALEN);
ESP_ERROR_CHECK(esp_now_add_peer(peer));
free(peer);
return ESP_OK;
}