nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.35k stars 710 forks source link

Print Characteristic Value to Serial Monitor #596

Closed kirawadden closed 5 years ago

kirawadden commented 6 years ago

I'm using the BLEClient example sketch with my ESP32 in the arduino IDE, and I'm trying to read the value of my characteristic and print to the serial monitor, but I'm getting this:

screen shot 2018-07-06 at 4 14 19 pm

this is the code I'm using: std::string value = pRemoteChar2->readValue(); const char *val = value.c_str(); Serial.print("The myo info characteristic's value is: "); Serial.println(val);

any ideas as to what I am doing wrong? Thanks!

chegewara commented 6 years ago

Your code looks good, but here is the question: what have you read from the other device? Is it string or is it binary value? With your code you can only print string messages and with very little change integer values. Im guessing its the case, peripheral you are connecting to and read characteristic value is not sending string but other data (but like always, i may be wrong).

kirawadden commented 6 years ago

The characteristic is meant to print the firmware version of my server (the myo armband), so it's definitely possible that the device is sending that in binary/hexadecimal. I'm having a lot of trouble reading any of the read only characteristics from this device, but I appreciate your help a lot

chegewara commented 6 years ago

Sorry, but this library is not prepared to read hex/binary data. I will try to find some time in this/next week and work on few requested features. You can try to std::string value = pRemoteChar2->readValue(); and google search for "how to print binary/hex value in arduino"

hansmbakker commented 5 years ago

@kirawadden this issue seems solved, could you please close it to keep the issue list clean?

cc @chegewara