Originally published in this blog.
The goal of this tutorial is to demonstrate how you can read and write from a Bluetooth Low Energy (BLE) device. For example, if you want to read the ‘number of steps’ data from your fitbit and make interesting apps with it,
In this tutorial, I am using a RedBearLab Bluetooth Low Energy (BLE) shield connected to an Arduino UNO. This BLE+Arduino combo essentially represents a BLE device. We will use a Raspberry Pi to read from & write to this BLE device.
Step 1: Components Used
Step 2: Initial Setup
Install hard-float Raspberryian OS using this link.
Install Bluez using step 1, 2, 3 of this link.
I used CSR 4.0 dongle in the Raspberry Pi for BLE connection.
Make sure you have gatttool in the path using
Step 3: Bluetooth Dongle Setup, Scan and Connect
Check if the Bluetooth dongle is up and running
~/bluez/bluez-5.11 $ tools/hciconfig
If not (you will see DOWN written in the result), use below command to get it up
~/bluez/bluez-5.11 $ tools/hciconfig hci0 up
Now scan for BLE devices. The command below might continue scanning forever, so type CTRL+C when you have the device address
$ sudo hcitool lescan
Lets assume that you get the BLE device address xx:xx:xx:xx:xx:xx. Now connect with the device using gatttool
$ sudo gatttool -b xx:xx:xx:xx:xx:xx -t random --interactive
You might not need to use -t random. Also if you get device busy error, remove the dongle and reconnect it. You will see an interactive prompt. Type connect like below
For more detail: Bluetooth Low Energy: Read-Write to Sensor Network from Raspberry Pi