I'm trying to read the heart beat rate from my Fitbit Versa Lite Smart Watch from my React-Native application, i was able to get the characteristics of the heart rate and was able to get the value in encoded base64 format like below
Heart Rate Data: AAAAAAAAuQAA
when i decoded the base64 string, it is showing me as
Heart Rate Data: ¹
after having a look into the bluetooth heart rate specifications from the below link
<Bit index="0" size="1" name="Heart Rate Value Format bit">
<Enumerations>
<Enumeration key="0" value="Heart Rate Value Format is set to UINT8. Units: beats per
minute (bpm)" requires="C1"/>
<Enumeration key="1" value="Heart Rate Value Format is set to UINT16. Units: beats per
minute (bpm)" requires="C2"/>
</Enumerations>
</Bit>
<Field name="Heart Rate Measurement Value (uint16)">
<InformativeText> Note: The format of the Heart Rate Measurement Value field is dependent
upon bit 0 of the Flags field. </InformativeText>
<Requirement>C2</Requirement>
<Format>uint16</Format>
<Unit>org.bluetooth.unit.period.beats_per_minute</Unit>
</Field>
now considering the above explanation from the link, do i need to consider the 1 as unit of measurement or 1 as the Bytes of data which i received from the heart rate sensor.
React-Native Code for reading the characteristics:
async readData(device) {
const services = await device.services();
console.log("Services:",services);
const characteristics = await services[1].characteristics();
// console.log(JSON.stringify(characteristicW));
console.log("Characteristics:",characteristics);
characteristics[0].monitor((err, update) => {
if (err) {
console.log(`characteristic error: ${err}`);
console.log(JSON.stringify(err));
} else {
console.log("Is Characteristics Readable:",update.isReadable);
console.log("Heart Rate Data:",base64.decode(update.value));
var data = new Uint16Array(base64.decode(update.value));
console.log("Heart Beats:",data[1]);
}
});
}
Any help is appreciated.
Thank you.
Looks to me like your output from
base64.decode(update.value)
is ¹. That is the Unicode representation of hex value 0xB9, or decimal value 185.Not clear to me from your code that this is the appropriate way to decipher the Characteristic you are getting in
update
. Maybe have your code be closer to the example documented in the wiki?