Wednesday, July 22, 2015

TI SimpleLink SensorTag 2015 - Development Environment Guide

Gerard at 43oh has posted an excellent guide for setting up the development environment for the CC2650STK.  I highly recommend that you check it out before you attempt to install Code Composer Studio.

image

Sunday, July 12, 2015

TI SimpleLink SensorTag 2015 - Python

Code for these examples is on GitHub in the dhSensorTag2015 repository.

Having successfully accessed data on the sensor tag I decided to try my hand at programmatically accessing data from the sensor tag.  I started out with the same two examples I had developed in bash: 1) to get the device name; and 2) get the humidty reading from the humidity sensor.

Surprisingly there are not too many options when it comes to Bluetooth Low Engergy APOs for Windows 7 or Linux. One of the few that exists is Ian Harvey’s bluepy for python on Linux.

Python isn’t something I use very much.  I do most of my work in Perl and C with a bit of Java thrown in for Android.  Fortunately there are a set of pretty good set of instructions for setting up bluepy on the Raspberry Pi that can be found at: http://www.elinux.org/RPi_Bluetooth_LE.  The output from these instructions is below:

pi@raspberrypi ~ $ git clone https://github.com/IanHarvey/bluepy.git
Cloning into 'bluepy'...
remote: Counting objects: 459, done.
remote: Total 459 (delta 0), reused 0 (delta 0), pack-reused 459
Receiving objects: 100% (459/459), 1.51 MiB | 556 KiB/s, done.
Resolving deltas: 100% (172/172), done.
pi@raspberrypi ~ $ cd bluepy/bluepy
pi@raspberrypi ~/bluepy/bluepy $ make
gcc -L. -O0 -g -DHAVE_CONFIG_H -I../bluez-5.4/attrib -I../bluez-5.4 -I../bluez-5.4/lib -I../bluez-5.4/src -I../bluez-5.4/gdbus -I../bluez-5.4/btio `pkg-config glib-2.0 dbus-1 --cflags` -o bluepy-helper bluepy-helper.c ../bluez-5.4/lib/bluetooth.c ../bluez-5.4/lib/hci.c ../bluez-5.4/lib/sdp.c ../bluez-5.4/lib/uuid.c ../bluez-5.4/attrib/att.c ../bluez-5.4/attrib/gatt.c ../bluez-5.4/attrib/gattrib.c ../bluez-5.4/attrib/utils.c ../bluez-5.4/btio/btio.c ../bluez-5.4/src/log.c `pkg-config glib-2.0 --libs`
pi@raspberrypi ~/bluepy/bluepy $ python btle.py B0:B4:48:B9:2C:82

Running the script generates the a dump of the services and characteristics.

Connecting to: B0:B4:48:B9:2C:82, address type: public
Service <uuid=Generic Access handleStart=1 handleEnd=7> :
    Characteristic <Device Name>, supports READ
    -> 'SensorTag 2.0'
    Characteristic <Appearance>, supports READ
    -> '\x00\x00'
    Characteristic <Peripheral Preferred Connection Parameters>, supports READ
    -> 'P\x00\xa0\x00\x00\x00\xe8\x03'
Service <uuid=f000aa70-0451-4000-b000-000000000000 handleStart=63 handleEnd=70> :
    Characteristic <f000aa71-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00'
    Characteristic <f000aa72-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa73-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'P'
Service <uuid=f000ac00-0451-4000-b000-000000000000 handleStart=81 handleEnd=88> :
    Characteristic <f000ac01-0451-4000-b000-000000000000>, supports NOTIFY READ WRITE
    -> '\x00\x00'
    Characteristic <f000ac02-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x02\x02\x00\x00\x00'
    Characteristic <f000ac03-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00D'
Service <uuid=Generic Attribute handleStart=8 handleEnd=11> :
    Characteristic <Service Changed>, supports INDICATE
Service <uuid=ffe0 handleStart=71 handleEnd=75> :
    Characteristic <ffe1>, supports NOTIFY
Service <uuid=f000aa64-0451-4000-b000-000000000000 handleStart=76 handleEnd=80> :
    Characteristic <f000aa65-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x7f'
    Characteristic <f000aa66-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
Service <uuid=f000aa00-0451-4000-b000-000000000000 handleStart=31 handleEnd=38> :
    Characteristic <f000aa01-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00'
    Characteristic <f000aa02-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa03-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'd'
Service <uuid=f000ffc0-0451-4000-b000-000000000000 handleStart=97 handleEnd=65535> :
    Characteristic <f000ffc1-0451-4000-b000-000000000000>, supports NOTIFY WRITE NO RESPONSE WRITE
    Characteristic <f000ffc2-0451-4000-b000-000000000000>, supports NOTIFY WRITE NO RESPONSE WRITE
Service <uuid=f000aa20-0451-4000-b000-000000000000 handleStart=39 handleEnd=46> :
    Characteristic <f000aa21-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00'
    Characteristic <f000aa22-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa23-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'd'
Service <uuid=Device Information handleStart=12 handleEnd=30> :
    Characteristic <System ID>, supports READ
    -> '\x82,\xb9\x00\x00H\xb4\xb0'
    Characteristic <Model Number String>, supports READ
    -> 'CC2650 SensorTag\x00'
    Characteristic <Serial Number String>, supports READ
    -> 'N.A.\x00'
    Characteristic <Firmware Revision String>, supports READ
    -> '1.01 (Mar 13 2015)\x00'
    Characteristic <Hardware Revision String>, supports READ
    -> 'PCB 1.2\x00'
    Characteristic <Software Revision String>, supports READ
    -> 'N.A.\x00'
    Characteristic <Manufacturer Name String>, supports READ
    -> 'Texas Instruments\x00'
    Characteristic <IEEE 11073-20601 Regulatory Cert. Data List>, supports READ
    -> '\xfe\x00experimental'
    Characteristic <PnP ID>, supports READ
    -> '\x01\r\x00\x00\x00\x10\x01'
Service <uuid=f000aa80-0451-4000-b000-000000000000 handleStart=55 handleEnd=62> :
    Characteristic <f000aa81-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    Characteristic <f000aa82-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00\x02'
    Characteristic <f000aa83-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'n'
Service <uuid=f000ccc0-0451-4000-b000-000000000000 handleStart=89 handleEnd=96> :
    Characteristic <f000ccc1-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '6\x00\x00\x00d\x00'
    Characteristic <f000ccc2-0451-4000-b000-000000000000>, supports WRITE
    Characteristic <f000ccc3-0451-4000-b000-000000000000>, supports WRITE
Service <uuid=f000aa40-0451-4000-b000-000000000000 handleStart=47 handleEnd=54> :
    Characteristic <f000aa41-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00\x00\x00'
    Characteristic <f000aa42-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa44-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'd'

At this point I created a directory SensorTag2015 off my home directory to work in.  I copied the bluepy python files into a subdirectory bluepy.  This gave me a setup that looked like this.

image

In the SensorTag2015 directory I created and ran my python examples.  I started with a very simple script that expects an address for the sensor tag on the command line.

pi@raspberrypi ~/SensorTag2015 $ python getDeviceName.py 00:00:00:00:00:00
SensorTag 2.0
pi@raspberrypi ~/SensorTag2015 $

The script imports two methods from the bluepy.btle fileand then it defines a UUID for the device name.  It checks to make sure that at least one argument is passed and then establishes a connection to the sensor tag.  If the script fails to connect to the sensor tag check to make sure that the sensor tag is advertising.  If it isn't push the left button and check that the green LED is flashing.  Once connected the script checks to make sure that the device name characteristic is readable, reads it and prints it out.

getDeviceName.py

import sys
from bluepy.btle import UUID, Peripheral

temp_uuid = UUID(0x2A00)

if len(sys.argv) != 2:
  print "Fatal, must pass device address:", sys.argv[0], ""
  quit()

p = Peripheral(sys.argv[1])

try:
    ch = p.getCharacteristics(uuid=temp_uuid)[0]
    if (ch.supportsRead()):
            print ch.read()

finally:
    p.disconnect()

Next I developed a slightly more complicated script for reading the Humidity sensor.  The template I developed with this script is what I used for most of the examples.

The script expects the address of the sensor tag to be passed on the command line as with the script above.  Then it defines TI unique UUIDs to configure the sensor and to get data from the sensor.  Next it sets up the values that get written to the sensor's configure UUID to turn the sensor on or off.  Note you must turn a sensor on before you are able to read it and get values other than zero back.

After these variables are setup the script connects to the sensor tag.  Once connected the script writes the value to turn on the sensor to the configuration UUID.  Then it reads the raw data from the sensor tag, converts it to values and calculates the sensor value.  The formulas for calculating the sensor values were pulled from the Android App source code. After the values are printed out the script turns of the sensor and disconnects from the device.

getHumidity.py

#
# TI SimpleLink SensorTag 2015
# Date: 2015 07 06
#
# Sensor: Humidity Temperature
# Values: Temperature and Humidity
#
import struct, sys, traceback
from bluepy.btle import UUID, Peripheral, BTLEException

def TI_UUID(val):
    return UUID("%08X-0451-4000-b000-000000000000" % (0xF0000000+val))

config_uuid = TI_UUID(0xAA22)
data_uuid = TI_UUID(0xAA21)

sensorOn  = struct.pack("B", 0x01)
sensorOff = struct.pack("B", 0x00)

if len(sys.argv) != 2:
  print "Fatal, must pass device address:", sys.argv[0], ""
  quit()

try:
  print "Info, trying to connect to:", sys.argv[1]
  p = Peripheral(sys.argv[1])

except BTLEException:
  print "Fatal, unable to connect!"
  
except:
  print "Fatal, unexpected error!"
  traceback.print_exc()
  raise

else:

  try:
    print "Info, connected and turning sensor on!"
    ch = p.getCharacteristics(uuid=config_uuid)[0]
    ch.write(sensorOn, withResponse=True)
    
    print "Info, reading values!"
    ch = p.getCharacteristics(uuid=data_uuid)[0]
    
    # IR Temperature sensor returns 4 bytes object(LSB),
    # object(MSB), ambient(LSB) and ambient(MSB).
    # Python unpack using "<" which denotes little-endian format
    # and "hh" which denotes 2 unsigned short (2 byte/16 bit) values.
    rawVals=ch.read()
    #(tempVal, humidVal) = struct.unpack('<HH', ch.read())
    tempVal = (ord(rawVals[1])<<8)+ord(rawVals[0])
    humidVal = (ord(rawVals[3])<<8)+ord(rawVals[2])
    
    #object temp and ambient temp are calculated as shown below
    print "Temp: %.2f F" % float((tempVal / 65536.0 * 165 - 40) * 1.8 + 32)
    print "Humidity: %.2f %%RH" % float(humidVal / 65536.0 * 100)
    
    print "Info, turning sensor off!"
    ch = p.getCharacteristics(uuid=config_uuid)[0]
    ch.write(sensorOff, withResponse=True)
    
  except:
    print "Fatal, unexpected error!"
    traceback.print_exc()
    raise

  finally:
    print "Info, disconnecting!"
    p.disconnect()
    
finally:
  quit()

On GitHub in the dhSensorTag2015 repository you will find these examples as well as additional examples to read the other sensors. 

A couple of things to bear in mind with these examples:

  • These examples were written using python 2.7.10 and were developed using V1.12 (Jun 23 2015) of TI’s firmware.
  • The barometer example calculation in the Andriod App doesn’t appear to be correct and therefore the example uses an updated calculation.
  • Data from all of the sensor examples, except the movement sensor, has been validated.

Friday, July 3, 2015

TI SimpleLink SensorTag 2015 - Reading Temperature and Humidity

Next up we are going to read the temperature and humidity from the HC1000 Humidity Sensor.  Each of the sensors that are accessible on the sensor tag has a GATT Service defined for it.  Below is the Humidity Service.

Handle Type Type (text) GATT Server Description/Value (text)
(hex) (hex) Permissions
0x27 0x2800 GATT Primary Service Declaration R Humidity Service
0x28 0x2803 GATT Characteristic Declaration R Humidity Data
0x29 0xAA21 Humidity Data RN TempLSB:TempMSB:HumidityLSB:HumidityMSB
0x2A 0x2902 Client Characteristic Configuration RW Write "01:00" to enable notifications, "00:00" to disable
0x2B 0x2803 GATT Characteristic Declaration R Humidity Config
0x2C 0xAA22 Humidity Config RW Write "01" to start measurements, "00" to stop
0x2D 0x2803 GATT Characteristic Declaration R Humidity Period
0x2E 0xAA23 Humidity Period RW Period = [Input*10] ms, (lower limit 100 ms), default 1000 ms

Before you can read a sensor value from the service you must turn it on.  For the Humidity Service this is done by writing a 01 to the handle at 0x2C labeled in the table above as Humidity Config.  Once you have turned on the Humidity Service you will read values from the handle at 0x29 labeled Humidity Data.

Referring to the table above we see that four values will be returned from left to right:

  1. Temp(LSB) - The least significant byte of the temperature data in hex.
  2. Temp(MSB) - The most significant byte of the temperature data in hex.
  3. Humidity(LSB) - The least significant byte of the humidity data in hex.
  4. Humidity(MSB) - The most significant byte of the humidity data in hex.

On page 14 of data sheet for the HC1000 Humidity Sensor are the formulas for converting this data into a temperature reading and a humidity reading.

  • Temperature in Celsius = (Temp(MSB) * 0x100 + Temp(LSB)) / 65536 * 165 – 40
  • Humidity = (Humidity(MSB) * 0x100 + Humidity(LSB)) / 65536 * 100

To get the values for the temperature and humidity readings follow the steps below.  In this example the values returned are 64 66 0c a2.

pi@raspberrypi ~ $ gatttool -b B0:B4:48:B9:2C:82 -I
[B0:B4:48:B9:2C:82][LE]> connect
Attempting to connect to B0:B4:48:B9:2C:82
Connection successful
[B0:B4:48:B9:2C:82][LE]> char-write-req 0x2C 01
Characteristic value was written successfully
[B0:B4:48:B9:2C:82][LE]> char-read-hnd 0x29
Characteristic value/descriptor: 64 66 0c a2
[B0:B4:48:B9:2C:82][LE]> char-write-req 0x2C 00
Characteristic value was written successfully
[B0:B4:48:B9:2C:82][LE]> disconnect
[B0:B4:48:B9:2C:82][LE]> exit

The resulting temperature is:

(0x66 * 0x100 + 0x64) / 65536 * 165 – 40 = 26.19 C

The resulting humidity is:

(0xa2 * 0x100 + 0x0C) / 65536 * 100 = 63.30%

Below is a bash script that will perform the commands above and calculate the temperature and humidity.

getTempHumidity.sh

#!/bin/bash
if [ "$#" != 1 ]; then
  echo "Need to pass BLE Address $0 <BLE Address>"
else
  echo "Turning on Temperature and Humidity Sensor"
  gatttool -b $1 --char-write-req --handle=0x2C --value=01
  echo "Getting Temperature and Humidity"
  for i in `seq 1 10`;
  do
    sleep 1
    str=`gatttool -b $1 --char-read --handle=0x29`
    # Discard everything up to and including the ": " in the

    # gatttool response.  Put the four bytes returned into an
    # array. Then swap the bytes and put the results in a variable. 
    #
Use bc to compute the temp and humdity.
    IFS=' ' read -a array <<< ${str#*: }
    temp="0x${array[1]}${array[0]}"
    temp=$((temp))
    humidity="0x${array[3]}${array[2]}"
    humidity=$((humidity))
    printf "temp: %s, humidity: %s\n" \
      `echo "scale=4; ($temp/65536*165-40)*1.8+32" | bc -l` \
      `echo "scale=4; ($humidity*1.0/65536.0)*100.0" | bc -l`
  done
  echo "Turning off Temperature and Humidity Sensor"
  gatttool -b $1 --char-write-req --handle=0x2C --value=00
fi

TI SimpleLink SensorTag 2015 - Reading the Device Name

In the last post we reviewed setting up a Raspberry Pi with Bluetooth to access the sensor tag.  We finished up by successfully performing a Bluetooth Low Energy scan which saw the sensor tag and returned the address.

In this post we will walk through reading and writing to the sensor tag using gatttool which is provided as part of the bluez Bluetooth stack.

Reading the Sensor Tag’s Device Name

As discussed in the previous post you will need to make sure your sensor tag is advertising.  When advertising the green LED visible on the back of the sensor tag will be blinking.  If it isn’t blinking try removing and reinstalling the battery.  If that doesn’t work replace the battery.

In the example below the hcitool lescan function is used to find the sensor tag.  It reports back the sensor tag’s address shown in green below.  Once you have the sensor tag’s address you should run gatttool providing –b and the address and a –I.  The –b tells gatttool that the next set of numbers is the address of the device you want to use.  The –I is for interactive mode.  gatttool has both an interactive mode and a command line mode.

As you can see the steps start with connecting to the device.  If the connect fails it could be because you waited too long and the sensor tag exited advertise mode or it could be that you have a version of gatttool that doesn’t work.  Put the sensor tag back into advertise mode, make sure the green LED is blinking and try to connect again.  If it fails this time it is most likely problem with gatttool.

Once you successfully connect to the sensor tag the green LED will stop flashing.  Enter the char-read-hnd command which stands for read characteristic by handle for handle 0x3 which is the device name.  You should get back the string of numbers below which if you convert from ascii values to characters spells SensorTag 2.0.

Disconnect from the sensor tag and the green LED should start blinking again and exit gatttool.

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 ~ $ gatttool -b B0:B4:48:B9:2C:82 -I
[B0:B4:48:B9:2C:82][LE]> connect
Attempting to connect to B0:B4:48:B9:2C:82
Connection successful
[B0:B4:48:B9:2C:82][LE]> char-read-hnd 0x3
Characteristic value/descriptor: 53 65 6e 73 6f 72 54 61 67 20 32 2e 30
[B0:B4:48:B9:2C:82][LE]> disconnect

[B0:B4:48:B9:2C:82][LE]> exit

Below is a bash script that will perform the commands above and translate the numeric values to their ascii equivalents.

getDeviceName.sh

#!/bin/bash
if [ "$#" != 1 ]; then
  echo "Need to pass BLE Address $0 <BLE Address>"
else
  # Discard everything up to and including the ": " in the
  # gatttool response.  Put the bytes returned into an array. 
  # Convert the bytes to ascii and print out.
  str=`gatttool -b $1 --char-read --handle=0x3`
  IFS=' ' read -a array <<< ${str#*: }
  for element in "${array[@]}"
  do
    printf "\x$(printf "%x" "0x$element")"
  done
  echo
fi

TI SimpleLink SensorTag 2015 - First Steps

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.

SLST2-Left_thumb1 SLST2-Front_thumb1 SLST2-Right01_thumb1 SLST2-Back01_thumb1

Left

Front

Right

Back

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.