SEEED ESP-NOW Sender example code for arduino does not compile

Arduino IDE: 2.3.10; esp board: 3.3.0 (also tried 3.3.12). Preference: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

I tried to compile the Sender example and here is the result:

C:\Users\gesch\AppData\Local\Temp.arduinoIDE-unsaved2026913-122112-1eb23om.sfl7f\sketch_oct13a\sketch_oct13a.ino: In function ‘void setup()’:
C:\Users\gesch\AppData\Local\Temp.arduinoIDE-unsaved2026913-122112-1eb23om.sfl7f\sketch_oct13a\sketch_oct13a.ino:54:30: error: invalid conversion from ‘void ()(const XIAO, esp_now_send_status_t)’ {aka ‘void ()(const unsigned char, esp_now_send_status_t)’} to ‘esp_now_send_cb_t’ {aka ‘void ()(const wifi_tx_info_t, esp_now_send_status_t)’} [-fpermissive]
54 | esp_now_register_send_cb(SenderXIAOS3_Send_Data_cb);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| |
| void ()(const XIAO, esp_now_send_status_t) {aka void ()(const unsigned char, esp_now_send_status_t)}
In file included from C:\Users\gesch\AppData\Local\Temp.arduinoIDE-unsaved2026913-122112-1eb23om.sfl7f\sketch_oct13a\sketch_oct13a.ino:3:
C:\Users\gesch\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.5-b66b5448-v1\esp32s3/include/esp_wifi/include/esp_now.h:185:54: note: initializing argument 1 of ‘esp_err_t esp_now_register_send_cb(esp_now_send_cb_t)’
185 | esp_err_t esp_now_register_send_cb(esp_now_send_cb_t cb);
| ~~~~~~~~~~~~~~~~~~^~
exit status 1

Compilation error: invalid conversion from ‘void ()(const XIAO, esp_now_send_status_t)’ {aka ‘void ()(const unsigned char, esp_now_send_status_t)’} to ‘esp_now_send_cb_t’ {aka ‘void ()(const wifi_tx_info_t, esp_now_send_status_t)’} [-fpermissive]

Help

I use platformio, so I’m pretty sure I can’t help much with this.

But I would make sure you have a peer added correctly. Perhaps the peer’s address is corrupted or wrong type?

To be much more help I’d have to see the code. I use ESP-NOW a bit, but I’m by no means an expert at it.

Thank you for responding! I have discovered that the header file <esp_now.h> and <ESP32_NOW.h> have been confusing me for several days. Apparently, both can work but the <esp_now.h> is the standard. the <ESP32_NOW.h> is Newer / wrapper: higher-level convenience layer for ESP32 only. I chose the <esp_now.h> and finally found a solution to the compile error many others have stumbled with - esp_now_register_send_cb(OnDataSent); : basically, the solution is simple change to: esp_now_register_send_cb((esp_now_send_cb_t)OnDataSent); the code below includes an actual working example. Hopefully, this will help others with similar frustration.

/*

*/

#include <esp_now.h>

#include <WiFi.h>

//MAC

uint8_t MAC1[] = {0x10, 0x91, 0xa8, 0x02, 0x5a, 0xac}; //XIAO-ESP32C3 “red 21”

typedef struct struct_message {

char a[16];

int b;

float c;

bool d;

} struct_message;

struct_message sendData;

struct_message recvData;

esp_now_peer_info_t peerInfo;

//SCallback when data is sent

void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {

if(status == ESP_NOW_SEND_SUCCESS){

Serial.println("Send_Success");

}else{

Serial.println("Send_Fail");

}

}

//Callback when data is received

void OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *Data, int len) {

memcpy(&recvData, Data, sizeof(recvData));

Serial.print("Bytes received: ");

Serial.println(len);

Serial.println(recvData.a);

Serial.println(recvData.b);

Serial.println(recvData.c);

Serial.println(recvData.d);

Serial.println(“---------”);

}

void setup() {

Serial.begin(115200);

WiFi.mode(WIFI_STA);

//Init ESP-NOW

if (esp_now_init() != ESP_OK) {

Serial.println("Error initializing");

return;

}

//Register callback on data sent

//esp_now_register_send_cb(OnDataSent); // board version 2; NOT WORK

//Change esp_now_register_send_cb(OnDataSent); to

esp_now_register_send_cb((esp_now_send_cb_t)OnDataSent); //brd ver 3 - This works!! 101426

peerInfo.channel = 0;

peerInfo.encrypt = false;

//Register MAC1 Device

memcpy(peerInfo.peer_addr, MAC1, 6);

if (esp_now_add_peer(&peerInfo) != ESP_OK){

Serial.println("Failed to add peer");

return;

}

//Register callback on data received

esp_now_register_recv_cb(OnDataRecv);

}

void loop() {

strcpy(sendData.a, “DFRobot”);

sendData.b = 10;

sendData.c = 9.9;

sendData.d = true;

esp_err_t result = esp_now_send(MAC1, (uint8_t *)&sendData, sizeof(sendData));

if (result == ESP_OK) {

Serial.println("Send success");

}

else {

Serial.println("Send Fail");

}

delay(2000);

}