Getting BLE to behave on the Pi

Lead Image © robodread,

Under the Radar

BLE is a convenient choice for wireless communication where WiFi and Internet connectivity aren't available, but getting it to work on a Raspberry Pi can be a minefield of compatibility problems. We look at the main concepts and debugging tools you will need to get the most out of BLE on your Pi.

BLE (Bluetooth Low Energy) is one of several standards developed for short-range wireless communication between devices. By design, BLE consumes very little power, which makes it attractive for always-on applications that don't have continual human interaction and maintenance. As a result, it's turning up in more and more products.

BLE interaction with users is less complex than other communication technologies, because devices exchange data quickly without the usual pairing process. This makes it suitable for iBeacon applications, in which an app detects the proximity of a BLE device (e.g., I'm in a shop or at a particular stand at a conference).

Something I've noticed in building BLE prototypes and projects on the Raspberry Pi, however, is that it's a whole load harder than you'd expect. As others have found with their Rasp Pi applications, supported devices and interoperable libraries change frequently. If you're used to debugging on one machine, and you add to that debugging on several machines, with a substantial amount of the operability occurring in the air, you'll find it's not fun.

In this article, I'll run through some of the core concepts of BLE and how these relate to the more popular tools available on the Pi and in iOS (as an example app platform). I'll also run through the debugging tools to keep close at hand. This article isn't so much a single project as a helpful collection of information lacking from many of the project pages on the web.

BLE Parts

To begin, I'll look at what BLE is suited to, avoiding the holy war of wireless standards and mostly looking at BLE's strengths.

BLE is designed for lower power consumption and is increasingly supported by phones, devices, and add-ons for the Raspberry Pi. Anyone who has paired their Fitbit to their phone or their phone to their car knows the typical process, but if you get into the BLE spec a bit more, some great hacks can allow you to change the user experience.

What you'll be used to is the scan and pair process, but underneath the hood, you can scan without pairing to see who's nearby. With a better understanding of BLE, you can build better projects and hack deeper into what's possible.

BLE, like any local wireless, is a way to transfer data between devices. To do this, the devices have to establish a connection, which in turn requires that they find each other. Therefore, the first stage is for some devices to advertise and others to scan for the advertised devices. The devices advertise their name, but when each device is interrogated, it will tell you more about its services and, within each of those, its characteristics.

The BLE spec has a list of standard services for things like heart rate, glucose, phone alert state, and many others. Each of these is designed to contain that specific type of information, be it the battery level service, which simply provides the level of a device's battery, or blood pressure, which provides a more complex set of information [1].

Each part of the service is called a characteristic, and this is where you start to read and write data. Think of the characteristics as fields in a table. Some of these fields can only be read, such as the name of the device while others can be written such as toggling a light switch on and off.

BLE devices take on one of two roles: the central or the peripheral. The central scans for peripherals and uses them to get things done. For example, your phone looks for a BLE fitness device and gets data from it. The peripheral typically advertises, so nearby centrals can get its data.

This simplified description should provide a good understanding to let you accomplish more with BLE rather than just following the project instructions. For example, one of the first things you can hack with is the fact that you don't have to pair with a device, you can just scan for it and pick up its presence. If you scan for nearby devices, you can remember their device IDs and start working out who is in the room.

What Can You Do with BLE?

Controlling devices, monitoring, manipulating lighting, sensing temperatures – any data that is fairly small can easily be transferred over BLE, meaning that most sensing and control easily falls into its scope.

Bundling this ability with a wired connection opens up the possibility of home control [2], as well as iBeacons and anything that involves wireless control, such as turning a lamp on and off [3].

iBeacon is a technology developed by Apple and based on BLE that allows an app running on a smartphone to find "beacons" and react accordingly. The beacon itself is fairly dumb; it simply emits a signal that uniquely identifies itself. The app can then work out what it's near and give the user access to information or device features.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content