i would like to ask you for help.
I am using two ESP32C3 and i want them to change data via esp_now.
So i tried to follow up this tutorial, but when i want to compile the responder sketch. I get this error:
"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]?
If you can help to determine what cause the problem, i would be grateful.
The responder code:
// Include Libraries
#include <esp_now.h>
#include <WiFi.h>
// Define a data structure
typedef struct struct_message {
char a[32];
int b;
float c;
bool d;
} struct_message;
// Create a structured object
struct_message myData;
// Callback function executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Data received: ");
Serial.println(len);
Serial.print("Character Value: ");
Serial.println(myData.a);
Serial.print("Integer Value: ");
Serial.println(myData.b);
Serial.print("Float Value: ");
Serial.println(myData.c);
Serial.print("Boolean Value: ");
Serial.println(myData.d);
Serial.println();
}
void setup() {
// Set up Serial Monitor
Serial.begin(115200);
// Set ESP32 as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Initilize ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Register callback function
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
}
I moved your topic to a more appropriate forum category @whosye.
The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.
In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.
You should post the error messages as code, because sometimes they have symbols that end up formatting your message, like asterisks making things italic: (char *) abc, char* xyz
becomes
(char ) abc, char xyz
From the full compiler error, you are using (wrapped for clarity)
You are using version 5 of ESP-IDF, where esp_now_recv_cb_t expects a esp_now_recv_info_t as the first argument. However, the latest release version of Arduino-ESP32 still uses version 4, where the first argument is const uint8_t * as the MAC address, just like you have it in your code, and what the tutorial is targeting.
The packages are related to your Board. So you can try updating your code to match v5, or pick a different board that is still compatible but uses the v4 API. Or maybe an earlier version of the same board.