如何使用node.js从蓝牙设备接收数据 [英] how to receive data from bluetooth device using node.js
问题描述
我是javascript和node.js的新手。目前正在从事医疗项目。首先,我将解释我的工作。我必须从蓝牙设备接收数据(正常血压率,脉搏率)并使用node.js在Web应用程序中显示读数。我不知道如何从蓝牙设备(病人监护仪)接收数据你们可以建议我阅读一些博客或书籍。在此先感谢。
I am new to javascript and node.js. Currently am working in medical project. First i will explain my work. I have to receive data from Bluetooth device (normal BP rate ,pulse rate ) and display the readings in the web app using node.js. I don't know how to receive data from Bluetooth device (patient monitor machine) can you guys suggest me some blogs or books to read. Thanks in advance.
推荐答案
您可以使用node-bluetooth分别从设备发送数据和从设备接收数据。这是一个示例代码: -
You can use "node-bluetooth" to send and receive data from and to a device respectively. This is a sample code:-
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();
它会扫描device变量中给出的设备名称。
It scans for the device name given in "device" variable.
这篇关于如何使用node.js从蓝牙设备接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!