[[Armadillo]]~ [[Armadillo-Box WS1/BLE Gateway]]~ #contents * BLE Support [#n6410641] > Based upon a Japanese blog “[[Try the newest bluez on Armadillo-IoT:https://users.atmark-techno.com/blog/750/1552]],” this article explains how to add Bluetooth Low Energy support.~ ~ Bluetooth adapter used here is [[Logitec LBT-UAN04C2BK:http://www.logitec.co.jp/products/bluetooth/lbtuan04c2bk/]], which is a Bluetooth 4.0 support USB adapter (Sold in Japan).~ ** Customizing Kernel [#r7795aa3] > Specify “vender/Product” by make menuconfig~ (AtmarkTechno) Vendor (Armadillo-Box WS1) AtmarkTechno Products ~ Make Bluetooth effective by putting check marks on the certain parts of Linux Kernel Configuration. Please look at right below for the details. Linux Kernel Configuration [*] Networking support ---> --- Bluetooth subsystem support <*> RFCOMM protocol support  <-- Mark it for being effective [*] RFCOMM TTY support   <-- Mark it for being effective <*> BNEP protocol support <-- Mark it for being effective [*] Multicast filter support <-- Mark it for being effective [*] Protocol filter support <-- Mark it for being effective <*> HIDP protocol support <-- Mark it for being effective Bluetooth device drivers ---> <*> HCI USB driver <-- Mark it for being effective ** Configuration of UserLand [#pb63f5f6] > At this time, Java is not used. Since Java generally occupies a lot space in UserLand, Java is NOT included. Since atmark dist is deployed at ramfs, please remove other unnecessary applications and files, using “make menuconfig.” (Available memory will increase if unneeded applications and files are removed as many as possible.)~ atmark@atde5:~/atmark-dist$ make menuconfig Userland Configuration Miscellaneous Applications ---> [ ] java  <-- Remove check mark ** Cross compile for Bluez [#k79519a0] > Build Bluez.~ Down load the source code of Bluez and extract it. (As of November 15, 2015, the newest version is 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 ~ Install the local packages of libical to ATDES.~ 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 ~ Execute 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 ~ Execute make.~ atmark@atde5:~/bluez-5.36$ make ~ Execute make install, and install it to ROM image directory of atmark dist.~ atmark@atde5:~/bluez-5.36$ make install DESTDIR=/home/atmark/atmark-dist/romfs/ ~ Remove unnecessary files such as documents.~ atmark@atde5:~/bluez-5.36$ rm -rf /home/atmark/atmark-dist/romfs/usr/share/man/ ~ Manually install gatttool, which is not installed by make install. atmark@atde5:~/bluez-5.36$ cp attrib/gatttool /home/atmark/atmark-dist/romfs/usr/bin/ **Installing D-bus [#y1557779] > Download D-bus deb package. 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 ~ Extract D-bus deb package in ROM image directory of atmark dist.~ atmark@atde5:~$ rm -rf atmark-dist/romfs/usr/share/doc atmark@atde5:~$ rm -rf atmark-dist/romfs/usr/share/man ~ Including init-funcions, which D-bus package is depending, extract lsb-base deb package in ROM image directory of atmark dist. Then, remove unnecessary documents. 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 ~ Add user/group, which execute D-sub daemon.~ ~ -Adding user~ atmark@atde5:~$ vi atmark-dist-20151026/vendors/AtmarkTechno/Armadillo-Box-WS1/etc/passwd At the end of file, please add line listed below messagebus:x:101:105::/var/run/dbus:/bin/false ~ -Adding group~ atmark@atde5:~$ vi atmark-dist-20151026/vendors/AtmarkTechno/Armadillo-Box-WS1/etc/group At the end of file, please add line listed below. messagebus:x:105: ** Recreating image [#yf1b85a5] > Complete the process so far, add BLE to Kernel and UserLand. Now, create the images of those Kernel and UserLand, which include BLE supports. atmark@atde5:~$ cd atmark-dist atmark@atde5:~/atmark-dist$ make romfs atmark@atde5:~/atmark-dist$ make image Please make sure that the files, which are located at the below atmark-dist/images/, are updated. ** Checking operation [#mab100ea] > Please rewrite Kernel and UserLand to newly created ones. To rewrite the images, please follows the directions, which is explained in [[this page (written in Japanese):http://manual.atmark-techno.com/armadillo-box-ws1/armadillo-box-ws1_product_manual_ja-1.0.0/ch12.html#sct.update_image-with-tftpdl]]. This method is the fastest way to rewrite the images if Armadillo-Box WS1 is connected to a netowrk. 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 ~ Booting the new Kernel and UserLand, insert the USB bluetooth adapter to a USB port.~ Check that the USB Bluetooth adapter is recognized.~ [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) The status of hci0 is automatically set to up.~ (Configurations of dbus start and bluetooth start are NOT required.)~ ~ Check the current status of BLE support.~ [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 ~ Doing scan around the neighborhood, look for BLE devices, which are currently in 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) ~ Doing scan correctly, obtain the list.~ Using gatttool, connect one of the devices in the list by interactive mode. [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) ~]# Then, successfully read the primary service information.~ * Revision History [#xf617bcf] > -2015-12-8: This article is initially released.