Martin covered scanning, GATT, how to maximise data rates, speed vs reliability and using different PHY for enhanced range or data rates. The second part of the talk covers Bluetooth Mesh and proxy nodes.
One thing not mentioned in the slides, to be careful of, is that connection via a proxy node is relatively slow because it’s limited by the GATT connection. Proxy nodes are good for controlling (sending small amounts of data into) a Bluetooth Mesh but poor if you want to use the connected Android device as a gateway for all outgoing data.
We recently came across a library ‘iBeacon scanner android’ for Android that allows you to scan for iBeacon and receive notifications when one or more specific beacons enter or exist range. The source code is on GitHub.
Artem Gapchenko has created a new Android Bluetooth scanning library called Luch that looks for beacons when the app is in the foreground. Unique features include it’s lightweight at a just over 50Kb, it performs RSSI smoothing and it calculates distance based on the RSSI.
We recently started selling beacons that can advertise LINE. This post explains LINE advertising with information on the packet format.
LINE Beacons are used with the LINE messenger service that allows users to send text, video, and voice messages on smartphones and the PC. It’s currently available in Japan, Taiwan, Thailand, and Indonesia. LINE have iOS and Android developer APIs that allow you to hook into the LINE service and include LINE services in your app. The LINE beacon allows your LINE code, called a bot, to receive beacon webhook events whenever a LINE user enters the proximity of a beacon. The beacons allow you to customise your bot app to interact with users in specific contexts. There’s also a beacon banner feature, available for corporate users, that causes a banner to appear in the LINE messenger app when it comes close to a LINE beacon.
Unlike iBeacon, LINE Beacon packets have a secure message field to prevent packet tampering and replay attacks. The secure data is 7 bytes long containing a message authentication code, timestamp and battery level. Secure messages are sent to the LINE platform for verification.
LINE recommend LINE beacon packets be sent at a very high rate of every 152ms. In addition, LINE recommend advertising iBeacon (UUID D0D2CE24-9EFC-11E5-82C4-1C6A7A17EF38, Major 0x4C49, Mino 0x4E45) to notify iOS devices that the LINE Beacon device is nearby. This is because an iOS app can only see iBeacons when in background and LINE beacons can’t wake an app.
We observe that the high advertising rate and concurrent iBeacon advertising aren’t battery friendly and the beacon battery isn’t going to last long.
When working with Bluetooth beacons and/or gateways and looking at raw Bluetooth data it can often become confusing which device is which. When setting up beacons using manufacturers’ apps, it’s a common occurrence for our customers to mistakenly connect to smartphones or fitness trackers rather than a beacon and wonder why the connection doesn’t work.
RaMBLE is a useful Android app that helps decode the Bluetooth devices around you. It attempts to classify devices so you can identify them:
The scanning runs in background and also logs advertising so that the data can be exported for analysis.
PunchThrough has a comprehensive new guide about using Bluetooth on Android. It explains the basics of Bluetooth, introduces the Android Bluetooth API and provides a guide how to scan for devices and connect to them using Bluetooth GATT.
It also covers bonding, thread-safety, queuing requests, background services and 3rd party libraries.
A new version of Nordic Semiconductor’s Android BLE library has been released. Nordic is the manufacturer of the system on a chip (SoC) inside some Bluetooth devices. Connecting to these devices, as opposed to just scanning for their advertising data, can be very tricky and there are lots of different ways of doing things depending on the Android version and workarounds based on specific situations. Nordic’s Android library aims to solve these problems and claims it “makes working with Bluetooth LE on Android a pleasure”. The library uses standard Bluetooth and hence works for all Android Bluetooth development, not just Nordic’s devices.
The new Android BLE Library v2.2.0 adds GATT server support and tidies up the callback mechanism. GATT server is where the Android device itself can be connected to from another device as opposed to Android initiating the connection. Note that this library is all about Bluetooth GATT connections. Connections are rare in the BLE World as most information is obtained through non-connected scanning for Bluetooth advertising. Connections tend to be used for settings or where you need higher or larger throughput than advertising can provide.
Note that the library doesn’t include scanning which is required before you can connect. Nordic provides a separate scanning library.
Also be aware that these libraries are relatively large. When we used them they took us over the Android 64K method limit thus complicating development slightly. Also, the later versions have dependencies on AndroidX. Finally, while the libraries hide the complications of Android development, this can be good and bad. When problems happen, as they always do with Bluetooth GATT, if you didn’t write the workarounds in the first place, debugging and fixing can be difficult.
As more and more devices are being shipped with Android 10 we are increasing getting reports of problems with beacon apps built for previous versions of Android. We mentioned this issue back in October last year.
To compound the problem, many popular Chinese manufacturers such as Oppo, Huawei and Xiaomi also now using Android 10 in their forked versions of Android. Not only are these manufacturers inheriting the Android 10 problem but their devices also suffer from problems running services, such as Bluetooth scanning, in background. The problem is that these manufacturers also add their own additional background throttling (and killing) mechanisms into the OS that make Bluetooth unreliable. The site dontkillmyapp documents the known problems and some workarounds for various forks of Android.
If you think you might be a victim of these issues, try using another, perhaps older, Android smartphone to isolate the problem.
Bluetooth SIG have updated their Introduction to Bluetooth Beacons. It provides advice and examples how to use beacons from iOS, Android and Raspberry Pi using the respective Bluetooth APIs.
The examples show how to scan for AltBeacon which is unusual because most people will want to scan for iBeacon because AltBeacon is sent by very few beacons. This is less of a problem on Android and Raspberry Pi where slightly modified code can be used. However, on iOS, the suggested APIs won’t work for iBeacon because Apple removes the iBeacon data from the Bluetooth scan response data to force you to use the iBeacon specific APIs which aren’t mentioned in the guide.