Raspberry Pi B+のBLuetooth BLE接続について

概況

bluetoothctlというコマンドで制御することができたのでその方法は以下のとおり記す。

環境

Raspberry Pi B+:Debian 7.6、Raspberryに挿すBluetooth USBドングル:ELECOM LBT-UAN05C2、通信相手:BLE付きセンサ

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

必要なライブラリ

# apt-get install libusb-dev libdbus-1-dev libglib2.0-dev automake libudev-dev libical-dev libreadline-dev
# make
# make install

シンボリックリンク

# ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin

Bluezコンフィグファイル

# install -v -dm755 /etc/bluetooth
# install -v -m644 src/main.conf /etc/bluetooth/main.conf

ドキュメント類インストール

# install -v -dm755 /usr/share/doc/bluez-5.33
# install -v -m644 doc/*.txt /usr/share/doc/bluez-5.33

ツールコピー

# install -v -m644 test/* /usr/local/bin

bluetoothd起動

# /usr/sbin/bluetoothd &

bluetoothデバイスON

# hciconfig hci0 up

いよいよbluetoothctlコンソール

# bluetoothctl -a

コンソールに切り替え、相手スキャン

[bluetooth]# scan on

相手に接続

[bluetooth]# connect xx:xx:xx:xx:xx:xx

今度も自動認識

[bluetooth]# trust xx:xx:xx:xx:xx:xx

bluetoothデバイス自動ON

#nano /etc/udev/rules.d/10-local.rules

以下追加

ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"

bluetoothd自動起動

#nano /etc/rc.local

以下exit 0の上に追加

/usr/sbin/bluetoothd &

これで再起動しても自動で通信相手が接続されるようになる。

次は、node.jsで通信を制御、送受信を行う。

ロボット・ドローン部品お探しなら
ROBOT翔・電子部品ストア