前言
node-red-contrib-ble-heart-rate
是一个基于 Node-RED
平台的 BLE
心率数据流采集插件。本文将介绍此插件的使用和安装方法,并提供实用的代码示例。
安装
在 Node-RED
管理面板中搜索 node-red-contrib-ble-heart-rate
并进行安装即可。或者,您也可以在终端中使用以下命令进行安装:
npm install node-red-contrib-ble-heart-rate
使用教程
node-red-contrib-ble-heart-rate
可以作为 Node-RED
中的一个节点来使用。例如,可以将其与 BLE
设备安装在一起并进行数据流传输。使用此节点,可以方便地获取 BLE
设备中的心率数据信息。
在 Node-RED
编辑器中,可以首先创建一个 BLE
连接节点,以建立设备和 Node-RED
之间的连接。然后,通过将 BLE Heart Rate
节点添加到流程中,可以从设备中捕获心率数据流并进行处理。
BLE 连接节点
对于 BLE 连接的节点,可以使用 node-red-contrib-generic-ble
包。此包包含 BLE Scan
和 BLE Connect
节点,可以帮助我们建立与 BLE 设备的连接。
以下是一个示例流程:
[{"id":"fbde68d3.1b2ab8","type":"blescan","z":"d58076ca.47c488","name":"","mac":"","interval":"30","duration":"5","allow_duplicates":true,"x":150,"y":100,"wires":[["e938e88.484787"]]},{"id":"e938e88.484787","type":"debug","z":"d58076ca.47c488","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":430,"y":100,"wires":[]},{"id":"3651a022.3302f8","type":"ble-connect","z":"d58076ca.47c488","name":"","deviceName":"","x":447,"y":243,"wires":[["45dc7c3d.e0cc3"]]},{"id":"45dc7c3d.e0cc3","type":"debug","z":"d58076ca.47c488","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":655,"y":246,"wires":[]},{"id":"83ba6f7b.032b48","type":"inject","z":"d58076ca.47c488","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":220,"wires":[["3651a022.3302f8"]]}]
在此示例中,我们使用了 blescan
节点来扫描附近所有的 BLE
设备,并使用 ble-connect
节点来建立连接。
BLE Heart Rate 节点
在成功建立连接之后,可以使用 node-red-contrib-ble-heart-rate
包中的 BLE Heart Rate
节点来获取心率数据流。
以下是一个示例流程:
[{"id":"cd4bb4a4.4a4f98","type":"debug","z":"ce3221dd.10724","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":120,"wires":[]},{"id":"6c92d6a7.446e28","type":"ble-heart-rate","z":"ce3221dd.10724","name":"","x":330,"y":120,"wires":[["cd4bb4a4.4a4f98"]]}]
在此示例中,我们使用了 ble-heart-rate
节点,并将其连接到 debug
节点,以便在控制台中显示心率数据信息。
示例代码
以下是一个完整的 Node-RED
流程示例:
[{"id":"2d1b9448.b47fda","type":"blescan","z":"4dbcba8e.8909cc","name":"","mac":"","interval":"30","duration":"5","allow_duplicates":true,"x":260,"y":100,"wires":[["9faa3ae3.4527a"]]},{"id":"9faa3ae3.4527a","type":"ble-connect","z":"4dbcba8e.8909cc","name":"","deviceName":"Device","x":480,"y":180,"wires":[["f1de9b49.53d328"]]},{"id":"f1de9b49.53d328","type":"ble-heart-rate","z":"4dbcba8e.8909cc","name":"","x":490,"y":280,"wires":[["c797d26.8e28378"]]},{"id":"c797d26.8e28378","type":"debug","z":"4dbcba8e.8909cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":380,"wires":[]},{"id":"e1aa2eb5.76b9b","type":"inject","z":"4dbcba8e.8909cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":240,"y":220,"wires":[["9faa3ae3.4527a"]]}]
此示例代码中包含一个芯片设备的连接,以及从设备中捕获心率数据流并在控制台显示的示例流程。
结论
node-red-contrib-ble-heart-rate
对于需要使用 BLE
传感器设备收集心率数据的应用程序是一个不错的选择。随着 Node-RED
和 BLE
技术的发展,其使用的案例和适用范围也不断扩大。希望本文能够为您提供有关此插件的详细和实用信息,并有助于您在以后的开发和应用中更好地使用它。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60056cb581e8991b448e6215