esp32-snippets icon indicating copy to clipboard operation
esp32-snippets copied to clipboard

Getting sings instead of value from characteristic

Open miag676 opened this issue 4 years ago • 7 comments

Hello, I'm trying to read a value from my Inkbird BLE temperature sensor using an esp32. I'm using the BLEClient code, however, the problem is that I get the following output: "The characteristic value was: ⸮ ⸮⸮". The code characteristic value is always a bit different, but it contains signs every time. If I look at the value on the BLE scanner app on my phone, everything works correctly. Does anyone know what could be causing this problem?

Thanks in advance!

miag676 avatar Jul 08 '21 11:07 miag676

The problem is that you are trying to print as string non printable values. https://www.encyklopedialesna.pl/foto/hasla/0/0/ascii-001.jpg

chegewara avatar Jul 08 '21 11:07 chegewara

Thank you for your quick reply. I'm trying to get the a hexadecimal number(see the screenshot below). Do you maybe know a way to solve this, so that I could use the value further in the code? image

miag676 avatar Jul 08 '21 11:07 miag676

You have to know protocol used by this sensor to interpret each value. Without it it is just a bunch of bytes without meaning. Its like i would say it is now temperature of 22 in here, but you dont know if its K or C or F.

chegewara avatar Jul 08 '21 11:07 chegewara

Yes, I this case the first 4 bytes represent the temperature, however, how could I extract this hexadecimal number in my code. Currently this is how I get it: std::string value = pRemoteCharacteristic->readValue(); Serial.print("The characteristic value was: "); Serial.println(value.c_str());

But I'm not sure how to change the pRemoteCharacteristic to a string.

miag676 avatar Jul 08 '21 11:07 miag676

https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/src/BLECharacteristic.h#L64

chegewara avatar Jul 08 '21 11:07 chegewara

I'm new to programming in arduino, so I'm struggling with implementing the code you sent. I tired changing it to the following: uint8_t* value = pRemoteCharacteristic->getData(); Serial.print("The characteristic value was: "); Serial.println(value.c_str()); But I am getting this error: 'class BLERemoteCharacteristic' has no member named 'getData'. Could you provide me with a bit more information on how to use it? Thanks for your help!

miag676 avatar Jul 08 '21 13:07 miag676

You have great tool you can use, it is google. Try to search arduino print bytes array

chegewara avatar Jul 08 '21 17:07 chegewara