nRF Blinky for Android
nRF Blinky is an application targeting an audience of developers who are new to Bluetooth Low Energy.
The app can be easily converted to work with other devices and may act as a template app.
This very simple application contains two basic features:
- turning on a LED on a connected Bluetooth LE device,
- receiving a Button press and release events from the device.
It demonstrates how the BleManager
class from
Android BLE Library
library can be used from a View Model
(see Architecture Components).
Structure
The new version of nRF Blinky application has been created in Jetpack Compose.
Dependencies
It is using the following libraries:
- Android BLE Library - handles Bluetooth LE connectivity
- Nordic Common Library for Android - theme and common UI components, e.g. scanner screen
- nRF Logger tree for Timber - logs to nRF Logger app using Timber
- Android Gradle Plugins - set of Gradle plugins
The gradle script was written in Kotlin Script (gradle.kts) and is using version catalog for dependency management.
Modules
The application consists of the following modules:
- :app - the main module, contains the application code
- :scanner - contains the scanner screen destination
- :blinky:spec - contains the Blinky device specification, e.g.
Blinky
API or the Service UUID - :blinky:ble - contains the BLE related code, e.g.
BlinkyManager
implementation - :blinky:ui - contains the UI related code, e.g.
BlinkyScreen
orBlinkyViewModel
implementation
The :blinky:ui and :blinky:spec modules are transport agnostic. The Bluetooth LE transport
is set using Hilt @Binds
dependency injection here.
The app is based on :navigation module from the Nordic Common Library, which is using
NavHost
under the hood, and adds
type-safety to the navigation graph.
Each screen defines a DestinationId
(with input and output types) and NavigationDestination
,
which declares the composable, inner navigation or a dialog target. See BlinkyDestination
for an example.
Navigation between destinations is done using Navigator
object,
available using Hilt form a ViewModel
. When a new destination is selected, the input parameters
are available from SavedStateHandle
(see BlinkyModule
class).
Nordic LED and Button Service (LBS)
Service UUID: 00001523-1212-EFDE-1523-785FEABCD123
A simplified proprietary service by Nordic Semiconductor, containing two characteristics:
-
LED state (On/Off).
- UUID:
00001525-1212-EFDE-1523-785FEABCD123
- Properties: Write or Write Without Response
- Value:
0x01
=> LED On - Value:
0x00
=> LED Off
- Value:
- UUID:
-
Button state (Pressed/Released).
- UUID:
00001524-1212-EFDE-1523-785FEABCD123
- Properties: Notify
- Value:
0x01
=> Button Pressed - Value:
0x00
=> Button Released
- Value:
- UUID:
For documentation for nRF5 SDK, check out this link and for one based on nRF Connect SDK this link.
Requirements
- This application depends on Android BLE Library.
- Android 4.3 or newer is required.
- Any nRF5 DK or another device is required in order to test the BLE Blinky service. The service can also be emulated using nRF Connect for Android, iOS or Desktop.
Installation and usage
Program your device with LED Button sample from nRF5 SDK (blinky sample) or nRF Connect SDK (LBS sample).
The device should appear on the scanner screen after granting required permissions.
Required permissions
On Android 6 - 11 nRF Blinky will ask for Location Permission and Location services. This permission is required on Android in order to obtain Bluetooth LE scan results. The app does not use location in any way and has no Internet permission so can be used safely.
This permission is not required from Android 12 onwards, where new
Bluetooth permissions
were introduced. The BLUETOOTH_SCAN
permission can now be requested with
usesPermissionFlags="neverForLocation"
parameter, which excludes location related data from the
scan results, making requesting location not needed anymore.