Notifications
Clear all

Problem compiling esp now code

17 Posts
4 Users
0 Reactions
245 Views
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2142
Topic starter  

Working my way through Bill's tutorial.

https://dronebotworkshop.com/esp-now/

Succeeded in getting the MAC address.

Now a problem with compiling ...

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]

 

To enlarge image, right click image and select Open link in new window.

ESP NOW ERROR

Code being compiled:

:

/*
  ESP-NOW Demo - Receive
  esp-now-demo-rcv.ino
  Reads data from Initiator
  
  DroneBot Workshop 2022
   https://dronebotworkshop.com 
*/

// 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() {

}

 


   
Quote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2142
Topic starter  

Found a utube video ESP NOW tutorial with Arduino IDE and ESP32
from RoboCircuits
It made reference to the examples that came with the ArduinoIDE
File > Examples > ESP_NOW
> ESP_NOW_Broadcast_Master
> ESP_NOW_Broadcast_Slave
> ESP_NOW_Network
> ESP_NOW_Serial

They all compiled without error so hopefully in the next few days I can work through the tutorial and see how I go.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7590
 

@robotbuilder I read the error message and gave the compiler what it wants to make the error GO AWAY. I did NOT dig deeper to see if the underlying data structure is in fact correct. I even compiled with error level of ALL and no messages.

  // Register callback function
  esp_now_register_recv_cb((esp_now_recv_cb_t)OnDataRecv);

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7590
 

@robotbuilder  I found some documents that may be useful including the API manual. Below is a screen grab of the code that tripped your compile error. Manual at HERE and something I have not seen before can be found at here.

 

Screenshot 2024 08 31 at 09.59.22

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 months ago
Posts: 127
 

Posted by: @robotbuilder

Now a problem with compiling ...

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]

As @zander notes as well, this is due to the changes made from 2.x to 3.x. The api for two callback functions changed the first argument to the function from a pointer to a mac address to a pointer to a struct. This changes the function signature. That's what the compiler is complaining about.

Note that the first argument to the callback is never used in Bill's code.

There are two ways to fix the code.  The "quick fix" is to simply cast the function pointer used in the function call

esp_now_register_recv_cb(OnDataRecv);

To the expected type esp-now_recv_cb_t, which looks like what you've done

esp_now_register_recv_cb((esp_now_recv_cb_t)OnDataRecv);

The second method would change the type of the first parameter of the callback function from a pointer to a mac address to the new type const esp_now_recv_info pointer. Since the argument is never used, it won't affect the code and the compiler will be satisfied the function signatures match.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7590
 

@tfmccarthy @robotbuilder Ah, did not notice the V3 part. Yes the cast makes the compiler happy, but the code likely won't actually work. I think I did say that. The 'proper' fix is to find out what the API requires in terms of the parameter(s)/argument(s) and re-code to the correct API spec.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2142
Topic starter  

@tfmccarthy
@zander

Thank you for your feedback.

As an aside this is my viewpoint:

We all operate at different levels of understanding from the beginner to the professional programmer.

ArduinoC++ and the ArduinoIDE are made simple so anyone can easily learn to program the microcontroller using the Arduino development board. It does rely on professionals providing a simple programming environment for those without the in depth understanding and knowledge of modern API's, advanced C++ programming techniques and so on. So to be useful a library has to be as easy to use as for example the Servo library. In order for a wider audience to be able to utilize the hardware to achieve some desired outcome it has to work without having to worry about all these changes and need to consult an API manual.

Fortunately the software/hardware professionals have provided plenty of tools and online tutorials and explanations that those without a professional background can use to implement their hardware ideas using a microcontroller.

It is just important to make sure the material is up to date 🙂


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 months ago
Posts: 127
 

 

@zander

Posted by: @zander

but the code likely won't actually work. I think I did say that.

Why do you think the code won't work?

Posted by: @zander

The 'proper' fix is to find out what the API requires in terms of the parameter(s)/argument(s) and re-code to the correct API spec.

The function esp_now_register_recv_cb takes a pointer to a function. The function pointer used is OnDataRecv.

In esp32 v2.x library, the function OnDataRecv should have the API

void OnDataRecv(const uint8_t* mac, const uint8_t* incomingData, int len)

in the v3.x library the API have been changed to

void OnDataRecv(const esp_now_recv_info_t* esp_now_info, const uint8_t* data, int data_len)

In both versions the first argument is a pointer. The data pointed to is different in each version.

However, since the pointer is never dereferenced in OnDataRecv, the function will be unaffected.

So we can simply coerce the call to esp_now_register_recv_cb to accept the pointer to the older API.

If you change OnDataRecv to use the v3.x API then the code will be coupled to that version of the library. But that is the "proper" fix.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7590
 

@tfmccarthy Just off the top of my head. I think the reason I said that is because the 'thing (struct?)' the cast 'fixes' does not contain the fields the V3 API needs.

Sorry, I am learning something I always wanted to learn (astrophotography) so my mind isn't focused on esp32s.

I am sure @robotbuilder will let us know if the simple cast fix works or not. I don't have the time at the moment to build a test.

Back to learning something I never thought I would be able to.

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 months ago
Posts: 127
 

@zander

Posted by: @zander

Just off the top of my head. I think the reason I said that is because the 'thing (struct?)' the cast 'fixes' does not contain the fields the V3 API needs.

The cast is for a function pointer. The fields are the data that will be passed to that function when the function is called by the OS.

Does anyone here understand what I'm saying?

Or is it all coming across as techno-babble?

This issue has come up three times with same answer given; it's been successfully implemented at least twice.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7590
 

@tfmccarthy I have no idea what you are going on about. The 'fix' I offered was to cast the OnDataRecv parameter/Argument (can't remember which is which) as esp_now_recv_cb_t. I did not dig into that typedef to see what it looked like. If you say it's a function ptr, then fine.

I am sure @robotbuilder will let us know what is what at the appropriate time.

BTW, I am self taught in C and have NO real understanding of C++ a language I consider evil. So when you say 

The cast is for a function pointer.

I don't really understand what you are saying.

AND I do NOT need to. If @robotbuilder needs to understand what you are trying to say, please address your remarks to him. I have NO dog in the fight, couldn't care less, I just made the compiler error go away.

Zander OUT!

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 months ago
Posts: 127
 

@zander 

You may be right.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2142
Topic starter  

@tfmccarthy 

Does anyone here understand what I'm saying?
Or is it all coming across as techno-babble?

It is not techno-babble for me. I did spend some time, a long time ago, learning C++. Much is forgotten although your C++ coding is familiar to me. I used to use TurboC++ on the MSDOS machines and later bought many teach yourself C++ books. However up until the first Windows came along I was an Assembler only, hit the hardware directly, kind of guy. Although my Amiga had a multitasking OS I turned it off and relied on the Amiga hardware manual alone. Computers were much simpler in those days 🙂 My first home built computer kit was this mini-scamp which is now, like me, a museum piece 🙂

https://www.oldcomputermuseum.com/mini_scamp.html

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2142
Topic starter  

@zander
@tfmccarthy

Thanks for the input guys!

Last night I finally got the code compiling without error!

Hopefully will soon have my version of working code for @imillard project and then do some other things with the setup.

One glitch was my wireless mouse pointer went crazy when I plugged in the second esp2 circuit. Looks like I will have to use the mouse pad or a wired mouse.

Nope. When I removed the wireless mouse usb thingy, turned off/on the laptop and then plugged in the two esp32 boards to their own usb port the mouse pointer went crazy again!!

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2142
Topic starter  

@zander
@tfmccarthy

The erratic mouse behavior has vanished.

Maybe it had something to do with the printer plugged into one of the USB ports. 

It all seems to be working as explained in Bill's tutorial.

 


   
ReplyQuote
Page 1 / 2