Barry Byford has a new blog post on D-Bus and Bluez. It documents his experiences creating a BLE central client on Linux. Barry deliberates over dbus-python and pydbus. He then provides an example how to create a Bluetooth GATT connection, converting D-Bus typed data to python types and interacting with a BBC micro:bit.
While you are on Barry’s site, read his notes from workshops and further notes on using Bluetooth.
The Bluetooth SIG has a new Bluetooth Technology for Linux Developers Study Guide. It explains how Bluetooth is implemented in hardware as part of the main board or added using a USB dongle. The Bluetooth stack runs as a system service using BlueZ. BlueZ is accessed via inter-process communication (IPC) via D-Bus, a message-based system service. Applications use D-Bus and hence BlueZ.
Barry Byford has a useful and continually growing introduction to using Bluetooth on Linux. He describes how to use BlueZ, the official Bluetooth stack on Linux, via D-Bus and Python. D-Bus allows communication between multiple processes running concurrently on the same machine. There’s an example how to set up an asynchronous event loop and how to build a Bluetooth Low Energy (BLE) device implementing the Bluetooth Central role.
The open source code advertises Eddystone-URL, Eddystone-UID and Eddystone-TLM. Examples are provided.
Most use of Bluetooth LE and beacons only looks at the transmitted advertising containing identification and sensor information. More advanced use requires connection to the device using GATT to write, read and be notified of changes in values (Bluetooth Service Characteristics). The most common use for connecting is to set configurable settings as in the case of device manufacturer smartphone apps.
Some solutions need to manipulate Bluetooth Service Characteristics programmatically. Barry Byford has a new Pyton library BLE-GATT for Linux based devices. It’s based on the BlueZ D-Bus API, features a small number of dependencies and can be easily installed without sudo privileges.
Cybele bridges Bluetooth Low Energy devices to MQTT on Linux devices. MQ Telemetry Transport Protocol (MQTT), invented by IBM, is an ISO standard that uses lightweight publish/subscribe messaging to send data to a server.
If you are developing using Node, there’s a Node.js module, node-beacon-scanner, that allows you to scan Bluetooth beacon packets and parse the packet data.
While Node tends to be associated with Linux, servers and hence web sites, Node can also be used on small single board computers such as the Raspberry Pi. Hence, this module provides an easy way to scan for Beacons and other Bluetooth devices.
The module supports iBeacon and Eddystone and outputs the MAC address, local name, transmit power level, RSSI and the iBeacon/Eddystone specific attributes.
We recently came across a Python library, BeaconTools, for working with various types of Bluetooth LE Beacon. It supports iBeacon, Eddystone and Estimote beacons, extracting information from raw binary beacon advertisements. It can also work as a beacon scanner.
Sparrow is an open source Graphical Bluetooth and WiFi Analyzer for Linux. It provides a 2.4 GHz and 5 GHz spectrum view, listens for Bluetooth LE advertising and tracks advertisement or iBeacons advertisement sources. It can also be used to advertise iBeacon.
Sparrow is useful for advanced users who need to diagnose more advanced problems related to interference or which part of a system isn’t working.