・2016/09/28
Raspberry Pi 3に Bluetooth BlueZ Version 5.42 BLE
(ラズパイで Bluetooth 4.0の BLE gatt通信を行なう TIの SensorTagや iBeacon実験など)
Tags: [Raspberry Pi], [電子工作]
● Raspberry Pi 3 Model Bを遂に購入
Raspberry Pi3 Model B RPI2 RPI3
大人気の CPUボードの Raspberry Piに WiFiと Bluetoothが搭載されたモデルが新発売となりました。
以前から Raspberry Pi 2を買おうかどうか迷っていましたが、Raspberry Pi 3 Model Bの発売を機に購入を決意してラズベリアンになる事にしました。
※ ラズパイの OS Raspbianはバージョンが上がる毎に過去の版と OSの内部の作りが変わり、過去に書かれた製作記事(例えば Raspbian Wheezyの時代の記事)がそのままではエラーが出たりして動かない事が有ります。
※ 当方のホームページのラズパイ記事は全て Raspberry Pi 3 Model Bと Raspbian Jessieの組み合わせで動作確認をしております。
(ただし、将来的に新しい Raspbian OSが出た場合に、当方の Raspbian Jessieを基にした内容がそのままでは動かない可能性が有ります。)
※ 2017/08/16から Raspbian OSは Raspbian Jessieから Raspbian Stretchに変わりました。
※ 2019/06/20から Raspbian OSは Raspbian Stretchから Raspbian Busterに変わりました。
Download Raspbian for Raspberry Pi
ちなみに、歴代のバージョンと名称は
Debian | コードネーム | 年月 | 備考 | (参考)Ubuntuでの該当名称 |
Debian 11 | Bullseye | 2021/08/14~ | 2021/11からラズパイにリリース | Focal Fossa 20.04 LTS ? |
Debian 10 | Buster | 2019/06/20~ | 2019/06からラズパイ4対応 | Bionic 18.04 LTS |
Debian 9 | Stretch | 2017/08/16~ | 2018/03からラズパイ3B+対応 | Xenial 16.04 LTS |
Debian 8 | Jessie | 2015~ | 2016/02からラズパイ3対応 | Trusty 14.04 LTS |
Debian 7 | Wheezy | 2013~2016 | | |
Debian 6.0 | Squeeze | 2011~2014 | | |
Debian GNU/Linux 5.0 | Lenny | 2009~2012 | | |
● Bluetooth BlueZ
Release of BlueZ 5.42
BlueZはオープンソースの Bluetoothプロトコルスタック
● Raspberry Piのデフォルトの bluetoothctlのバージョンは 5.23
$ bluetoothctl
[bluetooth]# version
Version 5.23
$ which bluetoothctl
/usr/bin/bluetoothctl
# ---
$ hcidump
-bash: hcidump: command not found
# Install bluez-hcidump package
$ sudo apt-get install bluez-hcidump
$ which hcidump
/usr/bin/hcidump
$ hcidump
HCI sniffer - Bluetooth packet analyzer ver 5.23
# ---
$ which hciconfig
/bin/hciconfig
# ---
$ hcitool
hcitool - HCI Tool ver 5.23
$ which hcitool
/usr/bin/hcitool
# ---
$ which gatttool
/usr/bin/gatttool
$ ls -l /usr/bin/gatttool
-rwxr-xr-x 1 root root 157556 May 27 10:46 /usr/bin/gatttool
● BlueZのコンパイルで依存関係が有るライブラリ
BlueZのコンパイルで依存関係が有るライブラリを実際に ./configureしつつ確認します。
sudo apt-get install -y libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline-dev
$ uname -a
# Linux raspberrypi 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux
sudo apt-get update
./configure
# checking for GLIB... no
# configure: error: GLib >= 2.28 is required
sudo apt-get install -y libglib2.0-dev
./configure
# checking for DBUS... no
# configure: error: D-Bus >= 1.6 is required
sudo apt-get install -y libdbus-1-dev
./configure
# checking for UDEV... no
# configure: error: libudev >= 172 is required
sudo apt-get install -y libudev-dev
./configure
# checking for ICAL... no
# configure: error: libical is required
sudo apt-get install -y libical-dev
./configure
# checking readline/readline.h usability... no
# checking readline/readline.h presence... no
# checking for readline/readline.h... no
# configure: error: readline header files are required
sudo apt-get install -y libreadline-dev
# --enable-experimental Enable BLE function
./configure --enable-experimental
make
sudo make install
● BlueZ Version 5.42 2016/08/26
BlueZ Version 5.42 2016/08/26
sudo apt-get update
sudo apt-get install -y libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline-dev
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.42.tar.xz
tar xvf bluez-5.42.tar.xz
cd bluez-5.42/
# --enable-experimental Enable BLE function
./configure --enable-experimental
./configure
make
sudo make install
sudo hcitool lescan
# Could not open device: No such device
sudo reboot
# sudo systemctl daemon-reload
# sudo systemctl restart bluetooth
# sudo systemctl enable bluetooth
# sudo nano /lib/systemd/system/bluetooth.service
systemctl status bluetooth
sudo hcitool lescan
# ---
bluetoothctl
[NEW] Controller B8:27:xx:xx:xx:xx raspberrypi [default]
[bluetooth]# version
Version 5.42
systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
Active: active (running) since Sat 2016-10-01 02:31:49 UTC; 1min 17s ago
Docs: man:bluetoothd(8)
Main PID: 689 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─689 /usr/local/libexec/bluetooth/bluetoothd
# ---
$ hcidump
HCI sniffer - Bluetooth packet analyzer ver 5.42
# ---
hcitool
hcitool - HCI Tool ver 5.42
●ラズパイで BLEを使って TIの SensorTagを認識する
$ sudo hcitool lescan
Could not open device: No such device
# Could not open deviceの時は再起動する
$ sudo hcitool lescan
LE Scan ...
4C:E8:XX:XX:XX:XX (unknown)
4C:E8:XX:XX:XX:XX (unknown)
BC:6A:XX:XX:XX:XX (unknown)
BC:6A:XX:XX:XX:XX SensorTag
# IR Temperature Sensor
# AA02
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-write -a 0x0029 -n 01
# AA01
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-read -a 0x0025
# Characteristic value/descriptor: 99 fe c8 0c
# Accelerometer
# F000AA12
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-write -a 0x0034 -n 01
# F000AA11
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-read -a 0x0030
# Characteristic value/descriptor: 00 00 00
# Humidity Sensor
# AA22
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-write -a 0x003f -n 01
# AA21
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-read -a 0x003b
# Characteristic value/descriptor: 00 00 00
# uuid = 00002a00-0000-1000-8000-00805f9b34fb
sudo gatttool -b BC:6A:XX:XX:XX:XX --char-read -a 0x0003
# Characteristic value/descriptor: 54 49 20 42 4c 45 20 53 65 6e 73 6f 72 20 54 61 67# "TI BLE Sensor Tag"
# ---
$ sudo hcitool lescan --duplicates &
$ sudo hcidump --raw &
$ jobs
[1]- Running sudo hcitool lescan --duplicates &
[2]+ Running sudo hcidump --raw &
$ fg 2
sudo hcidump --raw
^C [Ctrl+C]
$ fg 1
sudo hcitool lescan --duplicates
^C [Ctrl+C]
$ jobs
(none)
# "TI BLE Sensor Tag"
$ sudo gatttool -b BC:6A:XX:XX:XX:XX --characteristics | grep "ffe1"
handle = 0x006a, char properties = 0x10, char value handle = 0x006b, uuid = 000 ffe1-0000-1000-8000-00805f9b34fb
$ sudo gatttool -b BC:6A:XX:XX:XX:XX --characteristics | grep "0003"
handle = 0x0002, char properties = 0x02, char value handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb
$ sudo gatttool -b BC:6A:XX:XX:XX:XX --characteristics | grep "aa"
handle = 0x0024, char properties = 0x12, char value handle = 0x0025, uuid = f00 aa01-0451-4000-b000-000000000000
handle = 0x0028, char properties = 0x0a, char value handle = 0x0029, uuid = f00 aa02-0451-4000-b000-000000000000
handle = 0x002b, char properties = 0x0a, char value handle = 0x002c, uuid = f00 aa03-0451-4000-b000-000000000000
handle = 0x002f, char properties = 0x12, char value handle = 0x0030, uuid = f00 aa11-0451-4000-b000-000000000000
handle = 0x0033, char properties = 0x0a, char value handle = 0x0034, uuid = f00 aa12-0451-4000-b000-000000000000
handle = 0x0036, char properties = 0x0a, char value handle = 0x0037, uuid = f00 aa13-0451-4000-b000-000000000000
handle = 0x003a, char properties = 0x12, char value handle = 0x003b, uuid = f00 aa21-0451-4000-b000-000000000000
handle = 0x003e, char properties = 0x0a, char value handle = 0x003f, uuid = f00 aa22-0451-4000-b000-000000000000
handle = 0x0041, char properties = 0x0a, char value handle = 0x0042, uuid = f00 aa23-0451-4000-b000-000000000000
handle = 0x0045, char properties = 0x12, char value handle = 0x0046, uuid = f00 aa31-0451-4000-b000-000000000000
handle = 0x0049, char properties = 0x0a, char value handle = 0x004a, uuid = f00 aa32-0451-4000-b000-000000000000
handle = 0x004c, char properties = 0x0a, char value handle = 0x004d, uuid = f00 aa33-0451-4000-b000-000000000000
handle = 0x0050, char properties = 0x12, char value handle = 0x0051, uuid = f00 aa41-0451-4000-b000-000000000000
handle = 0x0054, char properties = 0x0a, char value handle = 0x0055, uuid = f00 aa42-0451-4000-b000-000000000000
handle = 0x0057, char properties = 0x0a, char value handle = 0x0058, uuid = f00 aa44-0451-4000-b000-000000000000
handle = 0x005a, char properties = 0x02, char value handle = 0x005b, uuid = f00 aa43-0451-4000-b000-000000000000
handle = 0x005f, char properties = 0x12, char value handle = 0x0060, uuid = f00 aa51-0451-4000-b000-000000000000
handle = 0x0063, char properties = 0x0a, char value handle = 0x0064, uuid = f00 aa52-0451-4000-b000-000000000000
handle = 0x0066, char properties = 0x0a, char value handle = 0x0067, uuid = f00 aa53-0451-4000-b000-000000000000
handle = 0x006f, char properties = 0x02, char value handle = 0x0070, uuid = f00 aa61-0451-4000-b000-000000000000
handle = 0x0072, char properties = 0x0a, char value handle = 0x0073, uuid = f00 aa62-0451-4000-b000-000000000000
●ラズパイ3の iBeacon化
ラズパイを BLEを使って iBeacon化する
Bluetooth Low Energy BLEで iBeacon
[GitHub] Complete example of using Bluez as an iBeacon
cd ~/
sudo git clone https://github.com/carsonmcdonald/bluez-ibeacon.git
cd ~/bluez-ibeacon/bluez-beacon
make
# cc -g -o ibeacon ibeacon.c -lbluetooth
# ibeacon.c:9:33: fatal error: bluetooth/bluetooth.h: No such file or directory
# #include
sudo apt-get -y install libbluetooth-dev
make
cc -g -o ibeacon ibeacon.c -lbluetooth
/usr/bin/ld: cannot open output file ibeacon: Permission denied
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
sudo make
./ibeacon
Usage: ./ibeacon
# ラズパイ3の内蔵 BlueToothは RSSIは -52程度
./ibeacon 200 11223344556677889900AABBCCDDEEFF 12 34 -52
Can't send request Operation not permitted (1)
# ibeaconで iBeaconの BLEアドバタイジングを開始する
# ibeaconは sudoが必要
sudo ./ibeacon 200 11223344556677889900AABBCCDDEEFF 12 34 -52
# Hit ctrl-c to stop advertising
BLE対応のスマホから iBeacon化したラズパイを発見できました。
Tags: [Raspberry Pi], [電子工作]
●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)
TIの 8051マイコン内蔵の BLE CC2540/CC2541を使ってみる
Bluetooth Low Energyの SensorTagや iBeacon、CC Debuggerの使い方など
Raspberry Pi 3の Bluetooth BLEで TI SensorTagと接続してセンサーの測定値を読み取る方法
ラズパイ3の BLEと Node.jsで、TIの SensorTag CC2541DKに接続してセンサーの状態を取得
Raspberry Pi 3の gatttoolのコマンドラインで TIの SensorTagを直接操作する方法
ラズパイ3と gatttoolのコマンドラインで TIの SensorTagに直接接続して gatttoolの使い方を覚える
Raspberry Pi 3に Nodejs blenoをインストールして Bluetooth BLEのペリフェラルを作成する
ラズパイ3と Node.js blenoで Bluetooth BLEの周辺機器機能を実装する
Raspberry Pi 3の Nodejs blenoで BLE接続して GPIOで Lチカ制御やボタン状態を読み取る
ラズパイ3と Node.js blenoで BLEの周辺機器機能を実装する GPIO編
Raspberry Pi 3の Python BLE pygattlibライブラリで TIの SensorTagに接続して制御する方法
ラズパイ3と Python BLE pygattlibで TIの SensorTagのセンサーの値を取得とボタン状態の通知を受信する
Amazon Dash Buttonをハックして IoTボタンとして使う方法を解説
Amazon Dash Buttonをハック。ARP要求を監視、DNSハック、IPアドレスハック等。
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。node-dash-button方法
ラズパイ + Node.jsで Amazon Dash Buttonをハックして IoTボタンとして使う方法を解説
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。tcpdump libpcap方法
ラズパイ + libpcap Packet Capture libraryで Amazon Dash Buttonをハックして IoTする
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。Python Scapyライブラリ方法
ラズパイ + Python Scapyライブラリで ARPパケット検出からの Amazon Dash Buttonをハック
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。Node.js Dasher方法
ラズパイ + Node.js Dasherライブラリで ARPパケット検出からの Amazon Dash Buttonをハック
Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ
ラズパイ3で安定して使える microSDカードを購入する Teamと SanDiskは絶対に買わない
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も
Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法
ラズパイ3の GPIO端子の I2C機能を有効にして各種センサーを繋げる方法まとめ
[HOME]
|
[BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c)
2016 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator
http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_bluetooth_ble_bluez/