【发布时间】:2018-03-27 01:31:00
【问题描述】:
使用Noble-Master Node package 中的examples,我已经从我正在使用的 TacX Vortex 蓝牙 Le 自行车训练器中找到了我需要的顶级特性。但是,我不知道如何从打包字节数组中获取累积轮转数。对于使用原生蓝牙功能的 Android,This answer 表示该值为 32 位,偏移量为 4,但 data.readUInt32LE(4) 会引发 index out of range 错误。当使用data.length 进行检查时,data 似乎是一个数组,但神秘地似乎在包含 11 个值或 7 个值之间交替。当使用data[n] 逐一读取时,发现的所有值都与自行车后轮的运行情况无关(制造商的测试安卓应用程序显示我应该在全倾斜时达到~100rpm)。当我将data.readUInt32LE(n) 中的偏移量从 0 更改为 3 时,它们也不会出现。我的问题是,如何使用 Javascript 从 CSC 测量特性中提取累积车轮转速?
var noble = require('./index');
noble.on('stateChange', function(state) {
if (state === 'poweredOn') {
noble.startScanning();
} else {
noble.stopScanning();
}
});
noble.on('discover', function(peripheral) {
peripheral.connect(function(error) {
console.log('connected to peripheral: ' + peripheral.uuid);
/* find the right service (Cycling Speed and Cadence) */
peripheral.discoverServices(['1816'], function(error, services) {
var CSCService = services[0];
console.log('discovered CSC Service: ' + CSCService);
/* find the right characteristic (Cycling Speed and Cadence Measurement) */
CSCService.discoverCharacteristics(['2a5b'], function(error, characteristics) {
var CSCMCharacteristic = characteristics[0];
console.log('discovered CSC Measurement Characteristic: ' + CSCMCharacteristic);
// problem is here: how to get cumulative wheel revolutions?
CSCMCharacteristic.on('data', function(data, isNotification) {
console.log('CSC Measurement is now: ', data.readUInt32LE(1));
});
// to enable notify
CSCMCharacteristic.subscribe(function(error) {
console.log('notification on');
});
});
});
});
});
【问题讨论】:
标签: javascript node.js bluetooth-lowenergy