Page 1 of 1

(2299) ESPNOW: Peer interface is invalid

Posted: Wed Mar 10, 2021 5:34 pm
by pat92fr
Hello,

I am using ESP-NOW on a M5StickC and I have this error when I try to add a peer. The peer is a M5Stack Fire.

I started with the following code (that works) and when I change a little bit this code, I got this error (2299).

What does it mean ? Where can I find a workaround ?

Code: Select all

uint8_t broadcastAddress[] = {0xF0, 0x08, 0xD1, 0xC7, 0x3E, 0xF8};
WiFi.mode(WIFI_STA);
if (esp_now_init() == 0) {
	Serial.println("ESPNow Init Success");
}
else {
	Serial.println("ESPNow Init Failed");
	ESP.restart();
}
esp_now_register_send_cb(OnDataSent);
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;  
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) == ESP_OK) {
	Serial.println("Pair success");
}
else
{
	Serial.println("Pair failed");
}
Kind regards,
Patrick.

Re: (2299) ESPNOW: Peer interface is invalid

Posted: Wed Mar 10, 2021 6:26 pm
by boarchuz
You haven't initialised the peerInfo struct so peerInfo.ifidx contains junk:
https://github.com/espressif/esp-idf/bl ... _now.h#L78

eg.
esp_now_peer_info_t peerInfo = {};
Or
memset(&peerInfo, 0, sizeof(peerInfo));

STA will then be the default, so set ifidx to WIFI_IF_AP if necessary.

Re: (2299) ESPNOW: Peer interface is invalid

Posted: Wed Mar 10, 2021 11:46 pm
by pat92fr
Hello boarchuz,

I have missed the initialisation. Thank you for your help. That works well now. I tried without

Code: Select all

peerInfo.ifidx=WIFI_IF_AP;
, and that works too.

Kind regards.