Compilation error after switching to Arduino IDE 2.3.3

I just updated from Arduino IDE 1x to 2.3.3 and wading through the various compilation errors. I don't have a theory about this one though, anyone have any idea?

Snippet:

class ButtonsCallbacks : public BLECharacteristicCallbacks
{
    void onWrite(BLECharacteristic *pCharacteristic)
    {
      
      std::string rxValue = pCharacteristic->getValue();

      if (rxValue.length() > 0)
      {

Gives the error:

Compilation error: conversion from 'String' to non-scalar type 'std::string' {aka 'std::__cxx11::basic_string<char>'} requested

That's referring to the line that starts with " std::string". Any theory by chance?

I think that this change is what happened.

https://github.com/espressif/arduino-esp32/pull/8724

BREAKING CHANGE! Changed API return and parameter type from std::string to Arduino style String.

This should compile and run

 //std::string rxValue = pCharacteristic->getValue();
 String rxValue = pCharacteristic->getValue();
1 Like

Thanks for that. But doesn't that define rxValue as a String instead of a string as before?

This also compiles and runs. Do you see any disadvantage?

std::string rxValue = pCharacteristic->getValue().c_str();

I will add only one thing: if you have ESP32, you can still use std::string and full C++20(vectors, iterators, coroutines, smart ptrs, etc.)

if you have ESP32, you can still use std::string

I'm using ESP32, and I was getting the error above. Board was set to "ESP32 Dev Module".

Yes, the return value set for the function by the library was changed from std::string to String.

This also compiles and runs. Do you see any disadvantage?

std::string rxValue = pCharacteristic->getValue().c_str();

I think that there are conversions going on behind the scenes and probably takes more instructions than the the return of the String to wind up in the same place.

With an esp32, there is no real need to eliminate Strings or std::string from your code and use c-strings like on the smaller memory arduinos.

In my opinion, I would use what the library has been coded to do, and not find a work around which gets to the same place.

I agree generally and use String when needed, but the issue here is that the rest of my code expects rxValue to be a string (small s), so changing it's variable type to the radically different String type causes other issues that I'd rather avoid.

the issue here is that the rest of my code expects rxValue to be a string (small s)

If that was the case, then why were you typing the rxValue as std::string which is a String object, and not a string(small s) which is the typical nomenclature for a c-string or null terminated character array.

It's your code, and I don't think there is any issue with what you are doing.
I don't think the error is related to 1.8.19 or 2.3.3, but rather a change in the esp32 BLE library.

2 Likes

Ak thanks for that, I thought std::string was casting a string (lowercase).

@wrybread i need to contact you regarding the old discussion of the nfc you had .can you provide me any way i can talk to you

Sure, my username @ gmail.com

@a3ya and @wrybread

Why don't you people use the messaging functionality on the forum?

@a3ya, publishing your email address on a forum is a reasonably sure way to receive unwanted spam.

1 Like

@sterretje thanks for your concern and suggestions but i am actually new to this forum so i didnt knew if there was any message functionality in the forum else i would have used that but thank you now i will search how can i access it and get in touch with @wrybread

It's my username on this forum @ gmail.com.

1 Like

Click on wrybread's user name and you will see a message button. Click it and you will be able to compose a m,essage.

1 Like

thank you .i deleted my thread containing my mail id .I couldnt get the message or inbox thing but that i will learn later .i have mailed my query to wrybread .but thanks to you for making me learn this thing.

Click on the avatar next to the user name or on the user name.

Click on Message at the right.

i dont have that option @sterretje :slight_smile:
can you message me ,i wanna see how i get the inbox type

Ah, you're too new and your trust level is "new user". You'll have to hang around a little longer, read some topics etc (not sure what exactly). Once you get promoted to "basic user", you can send PMs.

1 Like

@sterretje can you help me with the problem i am encountering ...
i want to send data or write from phone's nfc and want to read it using pn532 .all this using SPI on the esp32.