- 追加された行はこの色です。
- 削除された行はこの色です。
[[Armadillo]]~
[[Armadillo-Box WS1]]
[[Armadillo-Box WS1/BLE Gateway]]
#contents
*BLE対応 [#sf73fca9]
Armadillo-IoTで最新のbluezを使ってみる~
https://users.atmark-techno.com/blog/750/1552~
を参考に Armadillo-Box WS1 に Bluetooth Low Energy 対応を追加します。~
~
使用する USB Bluetooth アダプターは~
[[Bluetooth 4.0 対応 USB アダプタ Logitec LBT-UAN04C2BK:http://www.logitec.co.jp/products/bluetooth/lbtuan04c2bk/]]~
です。
**カーネルのカスタマイズ [#l9fdf22d]
make menuconfig で vendor/Product を指定します。
(AtmarkTechno) Vendor
(Armadillo-Box WS1) AtmarkTechno Products
カーネルコンフィギュレーションで Bluetooth を有効にします。
Linux Kernel Configuration
[*] Networking support --->
--- Bluetooth subsystem support
<*> RFCOMM protocol support <-- チェックをいれ有効にする
[*] RFCOMM TTY support <-- チェックをいれ有効にする
<*> BNEP protocol support <-- チェックをいれ有効にする
[*] Multicast filter support <-- チェックをいれ有効にする
[*] Protocol filter support <-- チェックをいれ有効にする
<*> HIDP protocol support <-- チェックをいれ有効にする
Bluetooth device drivers --->
<*> HCI USB driver <-- チェックをいれ有効にする
**ユーザーランドをコンフィギュレーション [#ybbb18be]
今回は使用しないので、サイズの大きい java を外してユーザーランドに含めないようにします。~
atmark dist は ramfs に展開されるので、他にも使用しないアプリケーションやファイルなどがあるのであれば~
可能な限り削ると使用可能メモリが増えます。
atmark@atde5:~/atmark-dist$ make menuconfig
Userland Configuration
Miscellaneous Applications --->
[ ] java ← チェックを外す
**Bluez クロスビルド [#ja2df1c6]
Bluez をビルドします。
Bluez のソースコードをダウンロードして展開します。(2015年11月15日時点の最新は 5.36 です。)
atmark@atde5:~$ wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.36.tar.xz
atmark@atde5:~$ tar Jxf bluez-5.36.tar.xz
ATDE5 に libical のクロスパッケージをインストールします。
atmark@atde5:~$ wget http://ftp.jp.debian.org/debian/pool/main/libi/libical/libical0_0.48-2_armel.deb
atmark@atde5:~$ dpkg-cross -v --build --arch armel libical0_0.48-2_armel.deb
atmark@atde5:~$ sudo dpkg -i libical0-armel-cross_0.48-2_all.deb
atmark@atde5:~$ wget http://ftp.jp.debian.org/debian/pool/main/libi/libical/libical-dev_0.48-2_armel.deb
atmark@atde5:~$ dpkg-cross -v --build --arch armel libical-dev_0.48-2_armel.deb
atmark@atde5:~$ sudo dpkg -i libical-dev-armel-cross_0.48-2_all.deb
configure を実行します。
atmark@atde5:~$ cd bluez-5.36/
atmark@atde5:~/bluez-5.36$ ./configure --build=i686 --host=arm-linux-gnueabi --enable-threads --enable-library \
--disable-udev --disable-systemd --prefix=/usr
make を実行します。
atmark@atde5:~/bluez-5.36$ make
make install を実行し、atmark dist の ROM イメージディレクトリに install します。
atmark@atde5:~/bluez-5.36$ make install DESTDIR=/home/atmark/atmark-dist/romfs/
ドキュメント類など不要なファイルを削除します。
atmark@atde5:~/bluez-5.36$ rm -rf /home/atmark/atmark-dist/romfs/usr/share/man/
make install ではインストールされない gatttool を手動でインストールします。
atmark@atde5:~/bluez-5.36$ cp attrib/gatttool /home/atmark/atmark-dist/romfs/usr/bin/
**D-bus インストール [#o9fe40f1]
D-bus deb パッケージをダウンロードします。~
atmark@atde5:~/bluez-5.36$ cd
atmark@atde5:~$ wget http://ftp.gnome.org/mirror/cdimage/snapshot/Debian/pool/main/d/dbus/dbus_1.6.8-1+deb7u1_armel.deb
D-bus deb パッケージを atmark dist の ROM イメージディレクトリに展開します。
atmark@atde5:~$ dpkg -x dbus_1.6.8-1+deb7u6_armel.deb atmark-dist/romfs/
不要なドキュメントファイルなどを削除します。~
atmark@atde5:~$ rm -rf atmark-dist/romfs/usr/share/doc
atmark@atde5:~$ rm -rf atmark-dist/romfs/usr/share/man
D-bus パッケージが依存する init-funcions を含む lsb-base deb パッケージを~
ROM イメージディレクトリに展開し、不要な Document のみ削除します。
atmark@atde5:~$ wget http://ftp.jp.debian.org/debian/pool/main/l/lsb/lsb-base_4.1+Debian8+deb7u1_all.deb
atmark@atde5:~$ dpkg -x lsb-base_4.1+Debian8+deb7u1_all.deb atmark-dist/romfs/
atmark@atde5:~$ rm -rf atmark-dist/romfs/usr/share/doc
D-busデーモンを実行するユーザ/グループを追加します。~
ユーザー追加
atmark@atde5:~$ vi atmark-dist-20151026/vendors/AtmarkTechno/Armadillo-Box-WS1/etc/passwd
ファイル末尾に以下の行を追加します。~
messagebus:x:101:105::/var/run/dbus:/bin/false~
グループ追加
atmark@atde5:~$ vi atmark-dist-20151026/vendors/AtmarkTechno/Armadillo-Box-WS1/etc/group
ファイル末尾に以下の行を追加します。~
messagebus:x:105:~
**イメージ再作成 [#t6f0f383]
上記の作業で BLE 対応が含まれたカーネルとユーザーランドのイメージを作成します。
atmark@atde5:~$ cd atmark-dist
atmark@atde5:~/atmark-dist$ make romfs
atmark@atde5:~/atmark-dist$ make image
atmark-dist/images/ の下のファイルが更新されていることを確認します。
**動作確認 [#n0d7cd76]
Armadillo-Box WS1 がネットワークに接続してある場合に一番速い書き換え方法である~
12.4. TFTPを使用してフラッシュメモリを書き換える~
http://manual.atmark-techno.com/armadillo-box-ws1/armadillo-box-ws1_product_manual_ja-1.0.0/ch12.html#sct.update_image-with-tftpdl~
でカーネルとユーザーランドを再作成したものに書き換えます。~
hermit> tftpdl 192.168.0.90 192.168.0.164 --blksize=1024 --kernel=linux.bin.gz
hermit> tftpdl 192.168.0.90 192.168.0.164 --blksize=1024 --userland=romfs.img.gz
新しいカーネルとユーザーランドで起動したら USB Bluetooth アダプターを USB ポートに挿します。
USB Bluetooth アダプターを認識しているか確認します。
[root@abws1-0 (ttymxc1) ~]# hciconfig -a
hci0: Type: BR/EDR Bus: USB
BD Address: 00:09:DD:40:C8:E6 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:1389 acl:0 sco:0 events:37 errors:0
TX bytes:382 acl:0 sco:0 commands:37 errors:0
Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'CSR8510 A10'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.0 (0x6) Revision: 0x22bb
LMP Version: 4.0 (0x6) Subversion: 0x22bb
Manufacturer: Cambridge Silicon Radio (10)
自動で hci0 が up した状態になっています。~
(参考元記事にある dbus start や bluetooth start は設定しなくても動作しました。)~
~
BLE 対応の状況を確認します。~
[root@abws1-0 (ttymxc1) ~]# hciconfig hci0 lestates
Supported link layer states:
YES Non-connectable Advertising State
YES Scannable Advertising State
YES Connectable Advertising State
YES Directed Advertising State
YES Passive Scanning State
YES Active Scanning State
YES Initiating State/Connection State in Master Role
YES Connection State in the Slave Role
YES Non-connectable Advertising State and Passive Scanning State combination
YES Scannable Advertising State and Passive Scanning State combination
YES Connectable Advertising State and Passive Scanning State combination
YES Directed Advertising State and Passive Scanning State combination
YES Non-connectable Advertising State and Active Scanning State combination
YES Scannable Advertising State and Active Scanning State combination
YES Connectable Advertising State and Active Scanning State combination
YES Directed Advertising State and Active Scanning State combination
YES Non-connectable Advertising State and Initiating State combination
YES Scannable Advertising State and Initiating State combination
YES Non-connectable Advertising State and Master Role combination
YES Scannable Advertising State and Master Role combination
YES Non-connectable Advertising State and Slave Role combination
YES Scannable Advertising State and Slave Role combination
YES Passive Scanning State and Initiating State combination
YES Active Scanning State and Initiating State combination
YES Passive Scanning State and Master Role combination
YES Active Scanning State and Master Role combination
YES Passive Scanning State and Slave Role combination
YES Active Scanning State and Slave Role combination
YES Initiating State and Master Role combination/Master Role and Master Role combination
scan して周囲の BLE デバイスの advertise を探索してみます。
[root@abws1-0 (ttymxc1) ~]# hcitool lescan
LE Scan ...
59:FF:59:55:45:CC (unknown)
59:FF:59:55:45:CC (unknown)
D9:9E:B9:CE:47:FD FNSensor
D9:9E:B9:CE:47:FD (unknown)
7D:FD:8D:EC:B2:4E (unknown)
7D:FD:8D:EC:B2:4E (unknown)
59:FF:59:55:45:CC (unknown)
59:FF:59:55:45:CC (unknown)
7D:FD:8D:EC:B2:4E (unknown)
7D:FD:8D:EC:B2:4E (unknown)
EB:49:99:58:22:49 (unknown)
EB:49:99:58:22:49 estimote
7D:FD:8D:EC:B2:4E (unknown)
7D:FD:8D:EC:B2:4E (unknown)
59:FF:59:55:45:CC (unknown)
59:FF:59:55:45:CC (unknown)
C2:A4:23:28:B1:6B FNSensor
C2:A4:23:28:B1:6B (unknown)
D9:9E:B9:CE:47:FD FNSensor
D9:9E:B9:CE:47:FD (unknown)
F4:C9:10:75:CB:91 fnColor
F4:C9:10:75:CB:91 (unknown)
正常にscanしてlistを取得できます。~
gatttool でそのうちの一つにインタラクティブモードで接続してみます。~
[root@abws1-0 (ttymxc1) ~]# gatttool -i hci0 -b D9:9E:B9:CE:47:FD -t random -I
[D9:9E:B9:CE:47:FD][LE]> connect
Attempting to connect to D9:9E:B9:CE:47:FD
Connection successful
[D9:9E:B9:CE:47:FD][LE]> help
help Show this help
exit Exit interactive mode
quit Exit interactive mode
connect [address [address type]] Connect to a remote device
disconnect Disconnect from a remote device
primary [UUID] Primary Service Discovery
included [start hnd [end hnd]] Find Included Services
characteristics [start hnd [end hnd [UUID]]] Characteristics Discovery
char-desc [start hnd] [end hnd] Characteristics Descriptor Discovery
char-read-hnd <handle> Characteristics Value/Descriptor Read by handle
char-read-uuid <UUID> [start hnd] [end hnd] Characteristics Value/Descriptor Read by UUID
char-write-req <handle> <new value> Characteristic Value Write (Write Request)
char-write-cmd <handle> <new value> Characteristic Value Write (No response)
sec-level [low | medium | high] Set security level. Default: low
mtu <value> Exchange MTU for GATT/ATT
[D9:9E:B9:CE:47:FD][LE]> primary
attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0008, end grp handle: 0x0008 uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0009, end grp handle: 0x000b uuid: 0000bc00-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0xffff uuid: bc000020-227d-902f-c2a8-0eb884017953
[D9:9E:B9:CE:47:FD][LE]>quit
[root@abws1-0 (ttymxc1) ~]#
プライマリ・サービス情報も正常に読みだせました。~
* 更新履歴 [#ke5d7093]
2015/12/08 初稿掲載 ~
RIGHT:Satoshi OTSUKA