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

Pra*_*eep 8 javascript bluetooth node.js

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

Asi*_*sim 8

您可以使用"node-bluetooth"分别从设备发送数据和从设备接收数据.这是一个示例代码: -

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();
Run Code Online (Sandbox Code Playgroud)

它会扫描"device"变量中给出的设备名称.