[SOLVED] Error when sending char array via BLEPeripheral

Hello,

I’m trying to send a string (converted to char array) via BLE, but receive an error “invalid conversion from ‘char*’ to ‘const unsigned char*’ [-fpermissive]”. Googled a lot, but can’t understand what is wrong.

This code works:

#include <BLEPeripheral.h>
...
BLECharacteristic DataToSendCharacteristic("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", BLERead | BLENotify,5);
...
const unsigned char DataToSend[] = {0x54,0x65,0x73,0x74}; // Test in HEX
...
DataToSendCharacteristic.setValue(DataToSend, sizeof(DataToSend)/sizeof *(DataToSend));

This code throws an error “invalid conversion from ‘char*’ to ‘const unsigned char*’ [-fpermissive]”:

#include <BLEPeripheral.h>
...
BLECharacteristic DataToSendCharacteristic("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", BLERead | BLENotify,5);
...
unsigned char DataToSend[5];
...
tempStr = "Test";
tempStr.toCharArray(DataToSend, 5);
DataToSendCharacteristic.setValue(DataToSend, sizeof(DataToSend)/sizeof *(DataToSend));

Try this:

DataToSendCharacteristic.setValue((const unsigned char*) DataToSend, sizeof(DataToSend)/sizeof *(DataToSend));

Thanks! It works!

You’re welcome!