I spent many hours on the ESP_ERR_ESPNOW_IF that I can't explain, in my case.
I'm much likely missing the point...
here are the essential chunks of code (the whole project is way too big to be posted)
- wifi init :
Code: Select all
nvs_init();
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap();
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
esp_err_t ret = esp_wifi_set_mode(WIFI_MODE_APSTA);
Code: Select all
ESP_ERROR_CHECK( esp_now_init() );
ESP_ERROR_CHECK( esp_now_register_send_cb(espnow_send_cb) );
ESP_ERROR_CHECK( esp_now_register_recv_cb(espnow_recv_cb) );
Code: Select all
esp_now_peer_info_t *peer = malloc(sizeof(esp_now_peer_info_t));
peer->channel = 0; // Same channel as wifi softAP or station
peer->ifidx = ESP_IF_WIFI_AP; // ESP32 soft-AP interface
peer->encrypt = false; // No LMK set
memcpy(peer->peer_addr, peer_mac_addr, ESP_NOW_ETH_ALEN); // MAC address of new peer
ESP_ERROR_CHECK( esp_now_add_peer(peer) ); // add peer to the list
When the esp32 runs, all goes well, until it tries to send a message to a peer. there comes the error ESP_ERR_ESPNOW_IF, which means that wifi interfaces of peer and espnow process are not the same.
But here are the tests I run to check these parameters..:
Code: Select all
esp_now_peer_info_t peer_struct_temp;
esp_now_get_peer(&peer_debug_mac1, &peer_struct_temp);
printf("channel : %d, IF : %d\n", peer_struct_temp.channel, peer_struct_temp.ifidx);
uint8_t protocol_bitmap_temp;
err = esp_wifi_get_protocol(ESP_IF_WIFI_STA, &protocol_bitmap_temp);
printf("err : %d, interface STA, bitmap : %d\n", err, protocol_bitmap_temp);
err = esp_wifi_get_protocol(ESP_IF_WIFI_AP, &protocol_bitmap_temp);
printf("err : %d, interface AP, bitmap : %d\n", err, protocol_bitmap_temp);
Code: Select all
espnow_send FAILED, err : ESP_ERR_ESPNOW_IF
channel : 0, IF : 1
err : 0, interface STA, bitmap : 7
err : 0, interface AP, bitmap : 7
-peer is correctly set in ESP_IF_WIFI_AP ( = 1)
-both ESP_IF_WIFI_STA and ESP_IF_WIFI_AP are created (otherwise, err would not be equal to ESP_OK)
...??
If someone has got a hint, a suggestion, an idea... it would be of a great help.
Thank you all