如何使用node.js从蓝牙设备接收数据

我是新的JavaScript和node.js。 目前正在从事医疗项目。 首先我会解释我的工作。 我必须从蓝牙设备接收数据(正常血压,脉搏率),并使用node.js在Web应用程序中显示读数。 我不知道如何从蓝牙设备(患者监护仪)接收数据,你们可以build议我一些博客或书籍阅读。 提前致谢。

您可以使用“节点蓝牙”分别向设备发送数据和从设备接收数据。 这是一个示例代码:

const bluetooth = require('node-bluetooth'); // create bluetooth device instance const device = new bluetooth.DeviceINQ(); device .on('finished', console.log.bind(console, 'finished')) .on('found', function found(address, name) { console.log('Found: ' + address + ' with name ' + name); device.findSerialPortChannel(address, function(channel) { console.log('Found RFCOMM channel for serial port on %s: ', name, channel); // make bluetooth connect to remote device bluetooth.connect(address, channel, function(err, connection) { if (err) return console.error(err); connection.write(new Buffer('Hello!', 'utf-8')); }); }); // make bluetooth connect to remote device bluetooth.connect(address, channel, function(err, connection) { if (err) return console.error(err); connection.on('data', (buffer) => { console.log('received message:', buffer.toString()); }); connection.write(new Buffer('Hello!', 'utf-8')); }); }).inquire(); 

它扫描“设备”variables中给出的设备名称。