Hello. I’ve been struggling to understand how to do what I think is a simple thing with BLE on the Particle units. I really want to use Particle to read this sensor. I have been going over the Particle bluetooth docs off and on for two weeks and I’m ready to give up.
I feel I understand the protocol itself and what I’m trying to do, I just don’t undersatnd how to use the Particle code to make it work. I see a lot of short fragments of examples, but I’m just not finding anything that clearly puts together what steps are needed to do a few simple things. I am struggling to understand how to actually modify/use the examples.
I am attempting to connect to a BLE device, then I want to write to a UUID and I want to then read from a UUID.
I think I am looking for an example that would look something like the following, which is what I’d expect for something like a SPI port or I2C handler.
BLE.Connect(my_target_device);
BLE.UUIDWrite(UUID, WriteValue);
myResult = BLE.UUIDRead(UUID);
I am trying to follow the example here:
https://docs.particle.io/tutorials/device-os/bluetooth-le/#heart-rate-central
But I just can’t understand what to do with it.
For example, the first significant line in the example is this, but no explanation:
BleCharacteristic heartRateMeasurementCharacteristic;
I don’t understand what that is doing, or what should be done differently to query something different. I looked up “BleCharacteristic” in the docs and it says “In a BLE central role, you typically have a receive handler to be notified when the peripheral updates each characteristic value that you care about.”. That is exactly what I want to do, but I don’t see “how” to do it. Where does the receive handler go? Is there a simple example of one that just queries a UUID?
Should I just replace “heartRateMeasurementCharacteristic” with the hex of the UUID I’m looking for? Later in setup() of the example it has this:
heartRateMeasurementCharacteristic.onDataReceived(onDataReceived, NULL);
Again, I’m not sure how that works or what exactly is happening. I think it’s telling me to do the following, but I know this is not correct:
BleCharacteristic 0xffff; //the 16-bit UUID I'm interest in
void setup(){
0xffff.onDataReceived(onDataReceived, NULL);
}
I also don’t understand how to actually grab the returned value into a variable. I have posted a screen shot below of this example in my browser. I’m sorry but I don’t understand what part of that copies the result into a variable for use. It is very hard to follow.
If I could have a little more guidance or see some more full examples that are simple, maybe I can logically relate these parts together. Most of the examples I’m finding on the internet are in phthon, and they use libraries, so it’s real hard to dissect the internals of those examples to figure out what to do in C on the Particle.
Much thanks for any further help.
Thank you.