(2299) ESPNOW: Peer interface is invalid

pat92fr
Posts: 2
Joined: Wed Mar 10, 2021 4:24 pm

(2299) ESPNOW: Peer interface is invalid

Postby pat92fr » Wed Mar 10, 2021 5:34 pm

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.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: (2299) ESPNOW: Peer interface is invalid

Postby boarchuz » Wed Mar 10, 2021 6:26 pm

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.

pat92fr
Posts: 2
Joined: Wed Mar 10, 2021 4:24 pm

Re: (2299) ESPNOW: Peer interface is invalid

Postby pat92fr » Wed Mar 10, 2021 11:46 pm

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.

Who is online

Users browsing this forum: No registered users and 113 guests