LoginSignup
34
37

More than 5 years have passed since last update.

UbuntuマシンでBluetooth4.0+LE(BLE), iBeaconが受信したい: Node.jsのBleaconライブラリを使う

Last updated at Posted at 2014-03-02

bleaconというライブラリをつかうと、Node.jsでBluetooth通信を送受信したりiBeaconで遊んだりできるらしい。
https://github.com/sandeepmistry/node-bleacon

用意する必要があるものと、Bluetoothの準備

  • root権限のあるUbuntuマシン。
  • マシン本体内蔵のBluetoothが古い場合、Bluetooth4.0+LEに対応し、かつLinuxに対応したドングルが必要。
  • 適当なiBeacon端末、iPhone4S以降があればEstimoteアプリ入れてもいいし、MacBookでも可

本体に4.0以前の古いBluetoothが載っている場合、無効にしなければならない。
hciconfig, hcitoolのようなコマンドがない場合、インストールしておく必要がある。

sudo aptitude install bluez
# USBドングルを挿す前にbluetoothデバイスを確認
hciconfig
# 本体内蔵のやつがあったら、止める
sudo hciconfig hci1 down
# DOWNになっているか確認
hciconfig
# USBドングルを挿す...
# ちゃんと増えてるか、確認
hciconfig
# BLEビーコンのスキャンを試してみる
sudo hcitool lescan

sudo hcitool lescanSet scan parameters failed: Input/output error. のようなエラーがでる場合、
そのBluetoothデバイスは4.0が対応していない場合がある。

  • USBドングルを抜き差しするなどしてちゃんとLinuxに認識されているか
  • 古いbluetoothのほうがちゃんと無効になっているか
    • USBドングルのほうを無効にしてたりしないか
    • hci*の番号間違ってないか

を確認しましょう。

bleaconのインストール

bleaconのビルドには、bluetooth.hヘッダが必要なのでlibbluetooth-devをインストール。

sudo aptitude install libbluetooth-dev
npm install bleacon

USBドングルに超近いやつだけ表示させる

Bleacon = require "bleacon"
Bleacon.startScanning()

console.log "start scanning"
console.log Bleacon

proximity_list = [ "immediate", "near", "far"]
Bleacon.on "discover", (bcon)->
    if bcon.proximity is "immediate"
        console.log "ID: #{bcon.major}-#{bcon.minor}, 距離:#{bcon.proximity}"
        console.log "\t 信号強度: #{bcon.measuredPower}, #{bcon.rssi}, 精度:#{Math.ceil(bcon.accuracy)}"
34
37
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
37