There’s a new Capacitor plugin for Bluetooth LE. Capacitor is new way to build web apps. Capacitor’s native plugin APIs allow easy access to common functionality, such as Bluetooth, across multiple platforms.
The plugin supports the web, Android and iOS. It allows scanning, GATT connecting, reading, writing and notifications. The source code is available on GitHub.
When connecting to Bluetooth devices such as beacons via GATT, APIs are used to connect to specific Bluetooth Services and Bluetooth Characteristics. Services and Characteristics are identified by 128-bit UUID values written as 00000000-0000-1000-0000-000000000000 where each digit is a hexadecimal number. For example, an app might connect to a Service with id D35B1000-E01C-9FAC-BA8D-7CE20BDBA0C6 and then read and write to a Characteristic with id D35B1001-E01C-9FAC-BA8D-7CE20BDBA0C6.
In practice, an interface usually uses similar UUIDs that only change in the xxxx part of the UUID: D35Bxxxx-E01C-9FAC-BA8D-7CE20BDBA0C6. There’s usually a base UUID such as D35B0000-E01C-9FAC-BA8D-7CE20BDBA0C6 and only 16-bits values are provided in the interface documented description.
Here’s an example from the Meeblue beacon documentation:
The Meeblue base UUID is D35B0000-E01C-9FAC-BA8D-7CE20BDBA0C6. When it’s said the UUID is 0x1000, the actual UUID is D35B1000-E01C-9FAC-BA8D-7CE20BDBA0C6.
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.
Beacons send most of the time periodically advertising the same data. For setup, apps usually connect to them to set settings such as the advertising period, unique id and power level. The connection is performed using standard Bluetooth GATT.
Bluetooth LE devices connect to others via GATT. Devices such as fitness trackers and our social distancing beacons are regularly connected to, to download data. It’s also common to connect to sensor beacons to extract sensor data.
GATT is usually used via compiled code and it can be time consuming to test GATT devices and/or subsequently use the GATT interface in a flexible way. Should you need to do this, take a look at Bleak GATT client software capable of connecting to Bluetooth LE devices acting as GATT servers. It provides an asynchronous, cross-platform (Windows 10, Linux, Mac) Python API to connect and communicate with Bluetooth devices.
The paper looks into the affect of radio frequency (RF) noise on connection based Bluetooth LE communication and provides a mechanism that significantly improves the time taken to send a message in noisy environments. To be clear, beacon-related scenarios rarely use GATT connection based communication and instead use connection-less communication repeatedly broadcasting short packets on 3 advertisement channels (37, 38, and 39). Connection tends to be used only to set up beacon parameters or for more advanced scenarios where a device such as a smartphone connects to the beacon for bidirectional data transfer to get real time data, for example, more timely motion detection.
The authors distinguish their research as experimentally derived as opposed to analytic (just using calculations). They show how the Bluetooth Adaptive Frequency Hopping (AFH) algorithm allows Bluetooth devices to blacklist interfered channels and re-transmit packets on different frequencies until interference is avoided.
The paper shows how the AFH algorithm mitigates the effects of Wi-Fi interference near a Bluetooth master by blacklisting channels. An interesting insight is that the master is unable to detect Wi-Fi interference near the Bluetooth slave and is unable to adapt resulting in UDP messages being significantly delayed.
“Our experiments show that BLE connections are eventually able to successfully transmit all data packets, even under heavy Wi-Fi or Bluetooth interference”
The authors demonstrate that by lowering the connection interval in response to changes in the link quality, an application can reduced the average number of packets delayed from 6.18% to 0.54%.
There’s a useful tool called bettercap that claims to be the “Swiss Army knife for WiFi, Bluetooth Low Energy, wireless HID hijacking and Ethernet networks reconnaissance and MITM attacks”.
While you might want to use it to test Bluetooth LE security, a more interesting use is for debugging Bluetooth LE. If you are scanning for advertising or creating or using GATT, for example with a beacon, it’s sometimes useful to have a separate way of exercising Bluetooth LE.
Bettercap is written in Go and runs on GNU/Linux, BSD, Android, Apple macOS and the Microsoft Windows. However, a bug in Windows and macOS prevents the Bluetooth commands from working. Hence, it’s for Linux or Android only.
Better caps runs in the browser and you can create scripts.
A PWA is one that can be run in the web browser. There’s no need to install anything and it works offline after it has been loaded.
Web Bluetooth allows the browser to see and interact directly with Bluetooth LE devices. This allows such devices to be configured and controlled from the web browser, where the browser is on a smartphone, laptop or desktop that has a Bluetooth LE adapter.
A particularly useful feature of Web Bluetooth Terminal is that it supports GATT Serial Port Profile. This is a standard interface that allows control of a Bluetooth device in much the same way as via UART. This means it’s possible to send strings of commands to configure and control. Some Bluetooth LE devices such as the HM-10 (make sure you get a genuine rather than fake one) include the Serial Port profile. Alternatively, if you are creating your own Bluetooth LE device you might include the GATT Serial Port Profile as part of the firmware.
The Wiki includes information about Bluetooth LE idioms such as advertising, MAC address, Bluetooth name, GATT, transmit power, measured power, range, RSSI, mesh and the new direction finding feature. It also has links to hardware and programming information.
The article talks about using beacons to promote consumer interaction, track customer shopping patterns and offer rewards but stops short of providing some scenarios and explaining some of the technical possibilities.
Imagine approaching a kiosk and it automatically knowing who you are and providing one touch (or zero touch) vending of your favourite drink or snack. You are billed automatically and you accrue loyalty points. For the merchandiser, think about extra things you could do (or know) if you could target your top customers and offer them frictionless service. These things are possible using beacons.
Depending on what you need to do, the beacon can be in the kiosk or (or and) with the user. If it’s with the user it can be a physical beacon or an app advertising as a beacon. Some scenarios need more functionality or security than is provided with just Bluetooth advertising. In these cases, it’s possible to connect to the beacon via Bluetooth GATT to store or view data.