Fix for ESPNow error mentioning issue with "esp_now_register_recv_cb(OnDataRecv)"

I recently started playing with ESP32 boards for the ESPNow features, and i quickly ran into problems using examples posted all over the internet that it turns out were written using the older version of the arduino-esp32 board library (the espressif one you need to install in the Arduino IDE).

Changes made between V 2.0.27 and the V3.x.x versions break a few things, so if you try to compile code written for V2.0.27 (which most code posted in youtube videos and elsewhere seems to be for) when you have V3.x.x installed, you'll get an error like:

Compilation error: invalid conversion from 'void (*)(const uint8_t*, const uint8_t*, int)' {aka 'void (*)(const unsigned char*, const unsigned char*, int)'} to 'esp_now_recv_cb_t' {aka 'void (*)(const esp_now_recv_info*, const unsigned char*, int)'} [-fpermissive]

I've seen loads of posts on the net and on this forum asking how to fix this on this, and all the english ones i've found so far end up with the OP reverting to V2.0.27 of the esp32 library to get the code to work,

I did this myself until after 2 days of searching i found what i was missing in a non english post.

.
The fix for this error turns out to be pretty simple, allowing you to keep using the latest V3.x.x version of the esp library.

Replace esp_now_register_recv_cb(OnDataRecv);
With esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));

And it should work.

3 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.