我正试图从我的React Native应用程序中读取Fitbit Versa Lite智能手表的心率,我能够获得心率的特征,并能够获得编码base64格式的值,如下面的
Heart Rate Data: AAAAAAAAuQAA
当我解码base64字符串时,它显示我为
Heart Rate Data: ¹
从下面的链接查看蓝牙心率规范之后
https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.heart_rate_measurement.xml
<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>
现在考虑到链接的上述解释,我需要将1视为测量单位还是将1视为由心率传感器接收的数据字节。
React读取特性的本地代码:
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]);
}
});
}
感谢您的帮助。
谢谢。
在我看来,您从base64.decode(update.value)
输出的结果是。这是十六进制值0xB9或十进制值185的Unicode表示。
从你的代码中,我不清楚这是破译你在update
中获得的特征的合适方法。也许您的代码更接近wiki中记录的示例?