Click here to Skip to main content
15,867,308 members
Articles / Internet of Things
Article

Using the Generic Attribute Profile (GATT) in Bluetooth* Low Energy with your Intel® Edison Board

10 Jun 2015CPOL4 min read 19.7K  
This guide will teach you how to use GATT profile, by interfacing with the Texas Instruments SensorTag over Bluetooth* Low Energy.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

Overview

This guide will teach you how to use GATT profile, by interfacing with the Texas Instruments SensorTag over Bluetooth* Low Energy.

Requirements

You have assembled your Intel® Edison board, updated to the latest firmware, connected via serial and connected the board to Wi-Fi*. If you need help completing these steps, please refer to the Getting Started Guides.

Install Gatttool

The TI SensorTag, along with many other Bluetooth devices, uses the Generic Attribute Profile (GATT) to interface with your computer and other devices. Gatttool is a standard tool included in the BlueZ software package, but it is not installed on the Intel Edison board by default. To install it, download and compile BlueZ 5.24 by logging in to your Intel Edison board over serial and entering the following commands:

root@edison: cd ~
root@edison: wget 	
https://www.kernel.org/pub/linux/bluetooth/bluez-5.24.tar.xz –	no-check-certificate
root@edison: tar -xf bluez-5.24.tar.xz
root@edison: cd bluez-5.24
root@edison: ./configure --disable-systemd –disable-udev
root@edison: make
root@edison: make install

To be able to launch gatttool from anywhere add it to the path:

root@edison: export PATH=$PATH:~/bluez-5.24/attrib/

Scanning and discovering BLE devices with bluetoothctl

  1. First enable Bluetooth on the Intel Edison board.
    root@edison: rfkill unblock bluetooth
  2. Launch bluetoothctl.
    root@edison: bluetoothctl
  3. Register an agent and set it to default.
    [bluetooth]# agent KeyboardDisplay<br />
    	[bluetooth]# default-agent<br />
    	[bluetooth]# scan on 
  4. If the SensorTag does not show up in the scan, click the pair button on the side of the SensorTag. Once you have discovered the SensorTag MAC address, you can turn off scan mode and quit.
    [bluetooth]# scan off<br />
    	[bluetooth]# quit 

Image 1
In the screen shot above the SensorTag MAC address is highlighted.

Use gatttool to read sensor values

gatttool can now be used to read sensor data from the SensorTag.

  1. Launch gatttool in interactive mode using the MAC address you received from the previous step.
    root@edison: gatttool -b 34:B1:F7:D5:15:38 -I
  2. Connect to the device, turn on the temperature sensor by writing 01 to the configure handle 0x29, and read out the value from the temperature handle 0x25.
    [34:B1:F7:D5:15:38][LE]> connect<br />
    	[34:B1:F7:D5:15:38][LE]> char-write-cmd 0x29 01<br />
    	[34:B1:F7:D5:15:38][LE]> char-read-hnd 0x25 

The handle values corresponding to the temperature sensor were pulled from the Sensor Tag attribute table: http://processors.wiki.ti.com/images/a/a8/BLE_SensorTag_GATT_Server.pdf.

Image 2

The output is two 16-bit unsigned values. Tto convert these values to a temperature reading they must be fed into a script that uses the conversion algorithm outlined in the SensorTag wiki: http://processors.wiki.ti.com/index.php/SensorTag_User_Guide#Sensors_2

Download Python* Script to Interpret Sensor Data

  1. One way of creating such a script is using the Python* programming language and the pexpect module. As an example, you can download the Python script from: https://github.com/msaunby/ble-sensor-pi/blob/master/sensortag/sensortag_test.py and use it to read out temperature values from the SensorTag.
    root@edison: wget https://github.com/msaunby/ble-sensor-<br />
    	pi/archive/master.zip -–no-check-certificate<br />
    	root@edison: unzip master.zip<br />
    	root@edison: cd /ble-sensor-pi-master/sensortag
  2. Open sensortag_test.py with vi.
    root@edison: vi ./sensortag_test.py
  3. Change line 62 from
    tool.expect('\[CON\].*>')
    to
    tool.expect('Connection successful')
  4. Once the edit is made save and quit by pressing Escape and entering:
    :wq

Installing pip and required Python modules

To run the Python script using pexpect, pexpect must be installed, which is easiest to do with Pip. Pip is not installed on the Intel Edison board by default and is not present in the official opkg repo. However, Pip is in the unofficial Intel Edison board’s repo compiled by Michael Hirsch. The following is an excerpt from his guide on using the unofficial repo from: http://blogs.bu.edu/mhirsch/2014/11/getting-started-with-intel-edison/.

  1. Use vi to edit the base-feeds.conf file.
    root@edison: vi /etc/opkg/base-feeds.conf
  2. Enter:
    src/gz all http://repo.opkg.net/edison/repo/all<br />
    	src/gz edison http://repo.opkg.net/edison/repo/edison<br />
    	src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
  3. Press Escape and enter:
    :wq
  4. Update opkg and install Python
    root@edison: opkg update<br />
    	root@edison: opkg install python-pip 
  5. >Install setup-tools for Pip
    root@edison: wget<br />
    	https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py<br />
    	-–no-check-certificate -O - | python
    >

Launch Python script and read out temperature

You are now ready to run the temperature script. From the  /ble-sensor-pi-master/sensortag directory, type the following command.

root@edison: ./sensortag_test.py 34:B1:F7:D5:15:38

The output should be similar to the screen shot below.

Image 3

Intel® Developer Zone for IoT

Start inventing today with the Intel® IoT Developer Program which offers knowledge, tools, kits and a community of experts to quickly and easily turn your innovative ideas into IoT Solutions.

Dream it, Build it with the Intel® IoT Developer Kit for Intel® Edison and Intel® Galileo platforms. These kits are versatile, performance-optimized and fully integrated end-to-end IoT solutions supporting a variety of programming environments, tools, security, cloud connectivity and hardware.

For more resources and to learn how the new Intel® IoT Developer Kit v1.0 can help streamline your IoT projects:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
This is a Organisation

42 members

Comments and Discussions

 
-- There are no messages in this forum --