After running through the Android (or IOS) App the next step was to manually read and write data from and to the sensor tag.
For this I used a Raspberry PI B running the most current version of Raspbian dated 2015-05-05 downloaded from the Raspberry PI Downloads page and an IOGEAR Bluetooth 4.0 USB Micro Adapter.
Raspbian doesn’t have Bluetooth support loaded. Unfortunately, the version that is currently in the repository doesn’t have a working copy of gatttool. As a result you will need both install Bluetooth using apt-get and build bluez from source.
pi@raspberrypi ~ $ sudo apt-get install --no-install-recommends bluetooth Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: bluez libcap-ng0 Recommended packages: bluez-alsa bluez-cups bluez-gstreamer The following NEW packages will be installed: bluetooth bluez libcap-ng0 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/945 kB of archives. After this operation, 2,203 kB of additional disk space will be used. Do you want to continue [Y/n]? Selecting previously unselected package libcap-ng0. (Reading database ... 78835 files and directories currently installed.) Unpacking libcap-ng0 (from .../libcap-ng0_0.6.6-2_armhf.deb) ... Selecting previously unselected package bluez. Unpacking bluez (from .../bluez_4.99-2_armhf.deb) ... <messages removed to save space> pi@raspberrypi ~ $ sudo service bluetooth status [ ok ] bluetooth is running. pi@raspberrypi ~ $ |
Bluez source can be downloaded from https://www.kernel.org/pub/linux/bluetooth/. At the time I am writing this July 3, 2015 the current version is 5.31 which built find on the most recent release of Raspbian.
Follow the commands below to build bluez. While you need to build bluez you don’t need to install what you build. You just need to copy the new version of gatttool to /usr/bin and you should be set to go.
pi@raspberrypi ~ $ sudo apt-get install --no-install-recommends bluetooth Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: bluez libcap-ng0 Recommended packages: bluez-alsa bluez-cups bluez-gstreamer The following NEW packages will be installed: bluetooth bluez libcap-ng0 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 945 kB of archives. After this operation, 2,203 kB of additional disk space will be used. Do you want to continue [Y/n]? Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcap-ng0 armhf 0.6.6-2 [12.3 kB] Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main bluez armhf 4.99-2 [895 kB] <messages removed to save space> Setting up libcap-ng0 (0.6.6-2) ... Setting up bluez (4.99-2) ... [ ok ] Reloading system message bus config...done. [ ok ] Starting bluetooth: bluetoothd rfcomm. Setting up bluetooth (4.99-2) ... pi@raspberrypi ~ $ wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.31.tar.xz --2015-07-03 20:23:58-- https://www.kernel.org/pub/linux/bluetooth/bluez-5.31.tar.xz Resolving www.kernel.org (www.kernel.org)... 198.145.20.140, 199.204.44.194, 149.20.4.69, ... Connecting to www.kernel.org (www.kernel.org)|198.145.20.140|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1631664 (1.6M) [application/x-xz] Saving to: `bluez-5.31.tar.xz' 100%[======================================>] 1,631,664 756K/s in 2.1s 2015-07-03 20:24:08 (756 KB/s) - `bluez-5.31.tar.xz' saved [1631664/1631664] pi@raspberrypi ~ $ tar xf bluez-5.31.tar.xz pi@raspberrypi ~ $ cd bluez-5.31/ pi@raspberrypi ~/bluez-5.31 $ ./configure --disable-systemd checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes <messages removed to save space> config.status: creating lib/bluez.pc config.status: creating config.h config.status: executing depfiles commands config.status: executing libtool commands pi@raspberrypi ~/bluez-5.31 $ make GEN lib/bluetooth/bluetooth.h GEN lib/bluetooth/hci.h GEN lib/bluetooth/hci_lib.h GEN lib/bluetooth/sco.h GEN lib/bluetooth/l2cap.h GEN lib/bluetooth/sdp.h GEN lib/bluetooth/sdp_lib.h GEN lib/bluetooth/rfcomm.h
<messages removed to save space> CC tools/obex-server-tool.o CCLD tools/obex-server-tool CC tools/bluetooth-player.o CCLD tools/bluetooth-player CC tools/obexctl.o CCLD tools/obexctl CC tools/hid2hci.o CCLD tools/hid2hci GEN tools/97-hid2hci.rules pi@raspberrypi ~/bluez-5.31 $sudo cp ./attrib/gatttool /usr/bin/ |
There are two tools that you will be using with your write data to the sensor tag.
- hcitool is the primary command line tool for configuring Bluetooth connections. It is used to scan for your sensor tag.
- gatttool is a tool that provides command line access to GATT Services on a Bluetooth Low Energy device.
To scan the sensor tag you will need to make sure that it is advertising. When the sensor tag is advertising there is a green led that flashes. The led can be seen if you turn the sensor tag over. It will is in the right window in the green circle. If it is not flashing then you will need to press the round button on the right side of the sensor tag shown in the yellow circle. If it doesn’t try removing and reinstalling the battery. If that doesn’t work replace the battery.
Once you have the sensor tag broadcasting go to your terminal window and type the hcitool command below.
pi@raspberrypi ~ $ sudo hcitool lescan LE Scan ... B0:B4:48:B9:2C:82 (unknown) B0:B4:48:B9:2C:82 CC2650 SensorTag ^C pi@raspberrypi ~ $ |
After a second you should see your sensor tag print out on your terminal. Once it has you can enter a ^C to stop the scan. For the next step you will need the address of you sensor tag which is highlighted in green above.
Congratulations you have now successfully scanned your sensor tag. Next up reading data from the sensor tag.
No comments:
Post a Comment