2017-12-12 17 views
3

javascriptおよびnode.jsを初めて使用しています。現在、医療プロジェクトに取り組んでいます。最初に私の仕事を説明します。私はBluetoothデバイス(通常のBPレート、脈拍数)からデータを受信し、node.jsを使用してウェブアプリケーションで読み取り値を表示する必要があります私はBluetoothデバイス(患者モニターマシン)からデータを受信する方法がわからないので、読者にはブログや書籍を読んでもらうことをお勧めします。前もって感謝します。node.jsを使用してBluetoothデバイスからデータを受信する方法

+0

多分このヘルプ[Node.jsを使ってBluetoothデバイスと話す](http://opensourceforu.com/2017/02/talk-bluetooth-device-using-node-js/) –

答えて

3

"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(); 

"device"変数で指定されたデバイス名をスキャンします。

+0

ありがとうここに問題があります。使用可能なBluetoothデバイスのペアが表示されていません。近くのBluetoothデバイスに自動的に接続されます。 Bluetoothデバイスをリストする方法を助けてください@Asim Raja事前に感謝します。 – Pradeep

+0

投稿を編集しました^^ – Asim

+0

ありがとう@Asim Rajaしかし前と同じですが、Bluetoothデバイスのリストが表示されていないことがわかりました。デバイスが1つしか表示されず、自動的にペア設定しようとしましたが、 bluetooth.connect(アドレス、チャンネル、関数(エラー、接続)){ ^ ReferenceError:チャンネルが定義されていません – Pradeep

関連する問題