BLEのアドバタイズを受信する
EdisonやRaspberry PiでBLEのセントラルになる場合、Node.jsのモジュールnobleが便利です。
以下のコマンドでnobleをインストールします。
npm install noble
次にGetting startedを参考にコードを書きます。
https://github.com/sandeepmistry/noble/wiki/Getting-started
var noble = require('noble'); noble.on('stateChange', function(state) { if (state === 'poweredOn') { noble.startScanning(); } else { noble.stopScanning(); } }); noble.on('discover', function(peripheral) { console.log('Found device with local name: ' + peripheral.advertisement.localName); console.log('advertising the following service uuid\'s: ' + peripheral.advertisement.serviceUuids); console.log(); });
stateがpoweredOnのときにstartScanning()を呼んでいます。 アドバタイズを受信するとnoble.on()のdiscoverに来ますので、受信したペリフェラルの内容を表示します。 ここではlocalNameとサービスのUUIDを表示しています。
BLEのペリフェラルデバイスを持っていなくてもNode.jsのモジュールblenoを利用することでアドバタイズを発信することができます。
MacやiPhoneにもBLEのアドバタイズ(iBeaconなど)を発信することができるアプリがあるので探してみてください。