Notifications
Clear all

error: invalid conversion from 'void...

18 Posts
4 Users
6 Reactions
229 Views
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1046
Topic starter  

Trying to use the example code from Bill's ESP-Now video from 2022 and get an error about invalid conversion, as in the topic title, when trying to compile the ino files with the receive call back function. The transmit only ino's compile with no error.

I had run these examples back when the video first came out and didn't have any issues. I'm guessing some libraries have changed since then.

Anyone that has run into this error as well?

SteveG


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

This is for the one way responder sketch, yes?

What is the line of the error?

I do have a note and a correction, but I want to be sure it's the same one.


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

I just checked this in my version and this is what I have

The ESP-NOW API changed. I haven't been able to track the version it changed yet

In ESP32 2.0.14, the function signature for esp_now_register_recv_cb is

typedef void (*esp_now_recv_cb_t)(
    const uint8_t *mac_addr
    , const uint8_t *data
    , int data_len
    );

esp_err_t esp_now_register_recv_cb(
    esp_now_recv_cb_t cb
    );

This matches the signature for the function OnDataRecv

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

The sketch compiles without warning.

For esp32 3.0.4 the API signature changed

typedef struct esp_now_recv_info {
    uint8_t * src_addr;             /**< Source address of ESPNOW packet */
    uint8_t * des_addr;             /**< Destination address of ESPNOW packet */
    wifi_pkt_rx_ctrl_t * rx_ctrl;   /**< Rx control info of ESPNOW packet */
} esp_now_recv_info_t;

typedef void (*esp_now_recv_cb_t)(
    const esp_now_recv_info_t * esp_now_info
    , const uint8_t *data
    , int data_len
    );

esp_err_t esp_now_register_recv_cb(
    esp_now_recv_cb_t cb
    );

This is a mismatch with OnDataRecv

The sketch compile now produces a conversion error

...\one_way_responder.cpp(69,50): error GBF214317:
    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]
   69 | esp_now_register_recv_cb(OnDataRecv);

There are two ways to fix this: explicit cast or benign refactor.

The function OnDataRecv doesn't use the first argument, const uint8_t* mac; the remaining arguments didn't change, so we can "safely" cast the function pointer in the new API call

esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));

The refactoring method would change the signature of OnDataRecv to match

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

My confidence in the Espressif toolchain is so low that I've taken to adding a version check in the code to save myself the grief of these constant upgrade issues:

#if ESP_ARDUINO_VERSION != ESP_ARDUINO_VERSION_VAL(2, 0, 14)
#error esp32 v 2.0.14 required
#endif

   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1046
Topic starter  

@tfmccarthy

Yikes, that's more info than my 78 year old gray matter can absorb all at once. It's like drinking from a fire hose, but I want to thank you for your quick response while it will take me a week or more to digest it.

Long story short is that I should step back to version 2.0.14?

Not quite sure how to accomplish that as the Arduino library has been a bug-a-boo for me from the beginning. What exactly should I be searching for in the Library Manager?

Again, thanks loads!

SteveG


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

@codecage 

Shorter long story: Take the easy path and when you're comfortable with how to revert the  library, come back and do it.

Replace the line

esp_now_register_recv_cb(OnDataRecv);

with

// todo: implicit cast callback pointer
//esp_now_register_recv_cb(OnDataRecv);
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));

and trust that McCarthy guy knows what he's doing.


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

@codecage 

BTW, when were you drinking out of a fire hose?


   
ReplyQuote
(@aliarifat)
Member
Joined: 1 month ago
Posts: 28
 

Posted by: @codecage

Trying to use the example code from Bill's ESP-Now video from 2022 and get an error about invalid conversion, as in the topic title, when trying to compile the ino files with the receive call back function. The transmit only ino's compile with no error.

I had run these examples back when the video first came out and didn't have any issues. I'm guessing some libraries have changed since then.

Anyone that has run into this error as well?

I think you will get more help if you copy-paste the error messages here.

 


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

@codecage 

I failed to mention...you want to change the version using board manager, not the library manager. There's a "How to ... " document on this somewhere.

And keep away from those fire hoses!


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

@tfmccarthy It's at https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html

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.


   
codecage reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1046
Topic starter  

@zander What language is that written in? Something pre-Latin? It seem to just be about deleted and changed APIs! I saw nothing about anything that referred to my error.

SteveG


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

@codecage @tfmccarthy Tim had mentioned that your error was fixed by reverting the esp32 BOARDS back from the new 3.x to 2.0.14. NOT a library change.

I don't see anything in the migration document, but apparently, Tim has experience with it.

I was simply posting the document he was referring 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.


   
codecage reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1046
Topic starter  

@tfmccarthy 

SUCCESS! I uninstalled the esp32 by Espressif Systems version 3.0.4 and installed version 2.0.17. Now I get a successful compile.

So many words for such a simple fix. That's what I meant when I said "like drinking from a firehose!"

Thank you kind sir for helping a old codger get something through his thick skull!

 

SteveG


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1046
Topic starter  

@zander

Thanks Ron! I wasn't trying to send a dig your way at all. Just made my reply thinking that document was coming from the the same firehose I referred to earlier. And I found nothing in that document that jumped out at me that pointed me in the right direction.

My failure was chasing down the library rabbit hole in the first place thinking it was a library issue and not a board issue.

But we seem to be good now. Again, thanks for you comments.

 

SteveG


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

@codecage No problem. The lesson here is that if you are 100% sure your code or your usage of library code is correct (this is where the sample sketches prove their worth yet again) then suspect a library update. Of course, it was a board update in this case, but that is part of the library system, level 2, I believe. I am not positive, but I think level 1 is 'builtin', level 2 is board, and level 3 is the libraries you manage with the library manager. The board's manager handles the level 2 libs, and if level 1 ever fails, it's time to make a prepper a friend.

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.


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

@codecage 

Excellent!

(Psst! The fire hose bit? I'm pulling your leg. One of my failings is my irrepressible sense of humor. And a tendency to over-explain. ...

...Two of my failings are my irrepressible sense of humor and a tendency to over-explain and fondness for movie references ...

My three failings are ...)

[Paraphrased quote from "Monty Python's Flying Circus"]


   
codecage reacted
ReplyQuote
Page 1 / 2