Bluetooth Low Energy

This is something of a departure for us, as it's not your usual devops/sysadmin/architecture but since we worked with it, we thought we'd write it up.

What is Bluetooth Low Energy?

Bluetooth Low Energy (BLE) is a radio technology that's completely different from "regular" Bluetooth, but typically sits alongside it (in phones, laptops, USB dongles, etc). It's used in tiny, battery powered devices which, for the most part, just broadcast a message every few seconds - and so are "beacons". BLE is deliberately a short-range, low power technology. Typical maximum transmission distances are about 20 metres in open space (and much less than that indoors).

That broadcast message doesn't contain much information, other than the device address and some other details. However, receivers can measure the signal strength they receive from the broadcast, and if they're sufficiently advanced can "connect" to the BLE device and collect more detailed information from it (such as its battery level).

All this really means that a receiver is able to approximate the distance between it and the BLE beacon. This gives rise to "key finders", indoor positioning and of course, Apple Airtags (see the bit about them in the section below).

One thing to note is that "connecting" to a BLE device is not like regular Bluetooth Pairing. The connection is really only temporary, but it is two way, and it allows the receiver to ask the beacon for its "features". Those features will include things like its battery level, and perhaps the state of a buzzer or maybe a sensor of some sort.

BLE beacons typically stop broadcasting while they're connected. They also typically only allow one connection at a time. As such, some beacons will actively close connections if they're open and idle for too long.

The BLE specs require broadcasts to be between a few milliseconds to 10.1 seconds apart. They have a slight "jitter" applied to them so that two beacons don't collide with each other more than once or twice too. This means that you can expect a beacon to broadcast pretty frequently - perhaps once per second or so.

BLE "Key Finders"

"Key Finders" are small keyring type devices which you can attach to something you're likely to lose around the house (eg. your keys). If you want to find it again, you can use your phone to get a distance to the object from where you are. Now, by walking around the house, you can "zero in" on the lost item. Some key finders also allow you to make them beep so you can find them audibly as well.

Despite the dressing on the phone apps these key finders come with, the phone can't tell you the direction of the signal its receiving. It actually can't tell you the distance accurately either - it's only really receiving the signal stength of the device's broadcasts. If the device is physically near you, but perhaps the other side of a wall, the "distance" reported will likely be a lot further than reality because the wall will have attenuated the signal, making it weaker at the receiver.

Depending how sophisticated the receiver is, it can potentially connect to the beacon, obtain battery level and then derive a more accurate distance measurement from the combination of the signal strength received and the battery level of the sender. Other opportunities for more accurate readings may be possible, depending on the features of the beacon and the receiver.

A particular type of beacon is the Apple AirTag. These little devices have got a lot of attention because they can be used to track people or things around the world. The tags are actually no cleverer than a "key finder", but Apple has used the FindMy network of devices around the world to listen out for any AirTags that happen to be nearby. The FindMy devices can be any Apple phones, laptops or potentially a range of other devices (not just Apple) that are running the FindMy software.

If any FindMy devices "see" an Airtag, they report it to the FindMy servers on the Internet, and those servers are then able to approximate global location, based on the location of the receiver. It's important to note that the tags themselves have the same limited range as any other BLE tag, and don't have any GPS capability. It's the FindMy device that has the GPS (or other) location capability, and its connection to the Internet that makes it possible to track Airtags around the world. So if an Airtag doesn't go near a FindMy device, then it won't be trackable until it eventually does so.

Working with BLE Beacons

As we've said, BLE beacons are deliberately low power devices. This makes them somewhat different to work with than other radio technologies that aim to provide perfect connectivity over difficult circumstances. By contrast, BLE pretty much deliberately doesn't work over difficult circumstances, and even having a device sat next to you on the desk doesn't guarantee a perfect signal or connection.

We found some variability between BLE radios on laptops, USB dongles and Raspberry Pis. We suspect different chips are better than others, and driver support varies between them, and between Operating Systems too. However, once you've got a good BLE hardware and driver stack, you can work with pretty much any sort of BLE beacon because that part of it seems to be quite well defined and standardised. As a general rule, we'd advise a USB connected BLE device because it means you can move it about and hopefully move it nearer where you expect beacons to be. The short-range nature of BLE makes this a more important consideration than it is for Wifi, or regular Bluetooth or whatever else.

That said, there are definitely good and bad beacons available. There are some very cheap beacons around which are hard to work with, but moving very slightly "up the quality scale" and they become quite predictable and reliable.

We also found some peculiarities with software. Here you need to "scan" for any BLE broadcasts, and you can choose between "active" and "passive" scans. We found "active" scans to be very unreliable with only a small number of broadcasts received per minute. Switching to "passive" scans, we got pretty much all of them, from multiple devices.

For a simple example of a BLE broadcast "receiver" that publishes to MQTT, written in Python, take a look at ble2mqtt on Github.

For help with this or any other technology, working with it or integrating it into your IT infrastructure, please contact us - we can help you figure out what you need and make it work for you.