如何解决Arduino 到 Raspberry Pi 通过 BLE 的通信
我正在尝试通过 BLE 连接将实时温度数据(浮点数)从 Arduino Nano 33 BLE Sense 发送到 RaspBerry Pi 4B。我已经成功通过广播传输数据。所以,这次我想在central和peripheral之间建立连接并发送数据。但是,有一些模糊的东西我无法理解:
1 - BLECharacteristic()
方法有浮动版本 BLEFloatCharacteristic
,所以我使用的是给定的 here. 但是,writeValue
有两个版本:
bleCharacteristic.writeValue(buffer,length)
bleCharacteristic.writeValue(value)
这是否意味着 value
可以是浮点数,如果我的特征也是浮点数,或者我应该发送 字节数组 并尝试提到的解决方法 here?
2 - 我也读过 |通知允许连续读取数据,如下所示:
BLEFloatCharacteristic tempCharacteristic(TEMP_UUID,BLERead | BLENotify);
BLEFloatCharacteristic humCharacteristic(HUM_UUID,BLERead | BLENotify);
在 RaspBerry Pi 部分
1 - 我正在使用 noble.js 库通过在 Node-RED 环境中运行的 node.js 获取数据。我能够建立连接并读取特征,但在尝试读取数据时遇到问题。下面我添加了让我读取一些数据的代码部分:
await noble.stopScanningAsync().catch(e => node.send(e));
await peripheral.connectAsync().catch(e => node.send(e));
const { characteristics } = await peripheral.discoverAllServicesAndcharacteristicsAsync().catch(e => node.send(e));
characteristics.forEach((characteristic) => {
node.send(characteristic);
characteristic.read(function callback(error,data) {
if (error){
node.send(error);
} else {
node.send(data);
}
});
});
正如预期的那样,我只能阅读一次。此外,我无法理解这些数据。
持续获取有意义的数据:
- 我需要订阅某个特征。
- 然后我还需要解释数据。
问题是我尝试了诸如 characteristic.subscribe([callback(error)]);
之类的可用方法,但无法成功。当我通过 Serial.println(tempCharacteristic.subscribed());
检查它时,它总是返回 0。
因此,我希望得到有关这些主题的指导。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。