BLECharacteristic.value() with Strings

Hi all,

I am using an Arduino Nano 33 IoT and HC-06 Bluetooth module, and the ArduinoBLE library. I am trying to transmit 2 strings from my phone to my Arduino, and I defined my BLECharacteristics like so:

BLECharacteristic speedCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, "SPEED_TEST");
BLECharacteristic angleCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, "ANGLE_TEST");

However, when I try to read the values into String variables below:

    String tmpStr1 = speedCharacteristic.value();
    String tmpStr2 = angleCharacteristic.value();

I get this error:

invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'const char*' [-fpermissive]

Is there any way to resolve this? Thank you.

the value() method returns a pointer (const uint8_t *)

if you are sure this is a properly formatted cstring, try

String tmpStr1 = reinterpret_cast<const char *> speedCharacteristic.value();
String tmpStr2 = reinterpret_cast<const char *> angleCharacteristic.value();

The HC-06 Bluetooth is a classic BT module (slave only) using SPP it's not compatible with BLE so I'm not sure what it has to do with this...

You seem to be mixing BLE and Classic Bluetooth (and perhaps WiFi for the IoT)
Check out my tutorial on Arduino NANO 33 Made Easy and also
Custom BLE controls
HC-06 is just Classic Bluetooth via a Serial connection
All my BLE projects just use a BLE Uart service (usually the Nordic nRF UART service)
see the example sketches in Arduino NANO 33 Made Easy for how to set up a UART connection that looks like a serial connection.
Then you can use Nordic nRF android apps (or my paid pfodApp) to connect and send/receive commands.
See Nordic nRF UART V2.0 app and Nordic nRF Toolbox app (which lets you assign cmds to buttons)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.