bluetoothctl というコマンドで制御することができるのでその方法を紹介します。
0、環境:Raspberry Pi B+:Debian 7.6、Raspberryに挿すBluetooth USBドングル:ELECOM LBT-UAN05C2、通信相手:BLE付きセンサ
1、bluez 5.33ダウンロード
#curl -L -o bluez-5.33.tar.gz https://www.kernel.org/pub/linux/bluetooth/bluez-5.33.tar.gz #tar zxvf bluez-5.33.tar.gz # cd bluez-5.33
2、必要なライブラリーインストール
# apt-get install libusb-dev libdbus-1-dev libglib2.0-dev automake libudev-dev libical-dev libreadline-dev # make # make install
3、シンボリックリンク
# ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin
4、Bluez コンフィグファイルコピー
# install -v -dm755 /etc/bluetooth # install -v -m644 src/main.conf /etc/bluetooth/main.conf
5、ドキュメント類インストール
# install -v -dm755 /usr/share/doc/bluez-5.33 # install -v -m644 doc/*.txt /usr/share/doc/bluez-5.33
6、ツールコピー
# install -v -m644 test/* /usr/local/bin
7、bluetoothd起動
# /usr/sbin/bluetoothd &
8、bluetoothデバイスON
# hciconfig hci0 up
9、いよいよbluetoothctlコンソール
# bluetoothctl -a
10、コンソールに切り替え、相手スキャン
[bluetooth]# scan on
11、相手に接続
[bluetooth]# connect xx:xx:xx:xx:xx:xx
12、今度も自動認識
[bluetooth]# trust xx:xx:xx:xx:xx:xx
13、bluetoothデバイス自動ON
#nano /etc/udev/rules.d/10-local.rules
以下追加
ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"
14、bluetoothd自動起動
#nano /etc/rc.local
以下exit 0の上に追加
/usr/sbin/bluetoothd &
これで再起動しても自動で通信相手が接続されるようになります。
以上。次は、node.jsで通信を制御、送受信を行います。