Can you explain this error message?

I’m trying to move my ESP Now receiver to the RobotDyn ESP-Mega, because the R32 I want to use doesn’t reach the kitchen. The D1 Mini does, but it only has one analog pin. The R32 has four usable analog pins, and I have three analog sensors.
But this is about the receiver. I haven’t gotten ESP-Now (or really much of anything) to work on this (piece of crap) toy. But it has an antenna. I think it can pick up ESP Now from the R32 with this antenna.
This function is literally pasted in from a the working ESP-32 receiver script.

// Callback function that will be executed when data is received
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len)
{
  char macStr[18];
  Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));

  board["id"] = myData.id;
  board["temperature"] = myData.temperature;
  board["humidity"] = myData.humidity;
  // board["pressure"] = myData.pressure;
  board["counter"] = String(myData.counter);
  String jsonString = JSON.stringify(board);
  events.send(jsonString.c_str(), "new_readings", millis());

  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  Serial.printf("t value: %4.2f \n", myData.temperature);
  Serial.printf("h value: %4.2f \n", myData.humidity);
  Serial.printf("p value: %4.2f \n", myData.pressure);
  Serial.print("ID:");
  Serial.print(myData.counter);
  Serial.println();
}
and later:

// Once ESPNow is successfully Init, we will register for recv CB to

// get recv packer info

esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);

esp_now_register_recv_cb(OnDataRecv);

}

void loop()

How can I get this to work? It's esp_now.h instead of espnow.h.

src\main.cpp: In function 'void setup()':
src\main.cpp:90:28: 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 (*)(unsigned char*, unsigned char*, unsigned char)'} [-fpermissive]       
   90 |   esp_now_register_recv_cb(OnDataRecv);
      |                            ^~~~~~~~~~
      |                            |
      |                            void (*)(const uint8_t*, const uint8_t*, int) {aka void 
(*)(const unsigned char*, const unsigned char*, int)}
In file included from src\main.cpp:14:
C:\Users\joema\.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:50:48: note:   initializing argument 1 of 'int esp_now_register_recv_cb(esp_now_recv_cb_t)'
   50 | int esp_now_register_recv_cb(esp_now_recv_cb_t cb);

It is telling you that it doesn’t like the ‘const’ attribute in the argument definition (which you might get away with) but more importantly it wants the ‘len’ parameter defined as an ‘unsigned char’ (or ‘uint8_t’), not an ‘int’
Susan

1 Like

As it says here your function prototype should instead be

void OnDataRecv(uint8_t *mac_addr, uint8_t *incomingData, uint8_t len)
{
  //..
}

Thank you. It compiled successfully.
But this identical code works like a charm on the ESP32.
This is 8266.

ESP-NOW has different interfaces / APIs between ESP32 and ESP8266. The code is not interchangable.

BAH!
It compiled okay, but on upload got this:
"src\main.cpp: In function ‘void setup()’:
src\main.cpp:90:28: error: invalid conversion from ‘void ()(const uint8_t, const uint8_t*, uint8_t)’ {aka ‘void ()(const unsigned char, const unsigned char*, unsigned char)’} to ‘esp_now_recv_cb_t’ {aka ‘void ()(unsigned char, unsigned char*, unsigned char)’} [-fpermissive]
90 | esp_now_register_recv_cb(OnDataRecv);
| ^~~~~~~~~~
| |
| void ()(const uint8_t, const uint8_t*, uint8_t) {aka void ()(const unsigned char, const unsigned char*, unsigned char)}
In file included from src\main.cpp:14:
C:\Users\joema.platformio\packages\framework-arduinoespressif8266\tools\sdk\include/espnow.h:50:48: note: initializing argument 1 of ‘int esp_now_register_recv_cb(esp_now_recv_cb_t)’
50 | int esp_now_register_recv_cb(esp_now_recv_cb_t cb);
| ~~~~~~~~~~~~~~~~~~^~
Compiling .pio\build\esp12e\lib239\ESP8266WiFi\ESP8266WiFiGeneric.cpp.o
*** [.pio\build\esp12e\src\main.cpp.o] Error 1

You still have not removed const from the first two parameters of your OnDataRecv function – or it’s prototype which might be duplicate.

Yeah, I only changed the len.