Skip to content

nordicsemi/Android-nRF-Blinky

Repository files navigation

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 modified 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.

Based on these 2 states, the derived flows allow to detect:

  • button click events (press and release),
  • long button click events (pressed for longer than 1 second).

nRF Blinky demonstrates how to implement basic Bluetooth LE operations (blinking) or binding flows and states (control the LED state based on the button state).

Scanner Blinky

Kotlin BLE Library

This app is designed to work as a sample app for the Kotlin BLE Library. It demonstrates how a connection can be handled using a Service with a clear separation of the Bluetooth LE logic from the App using a Blinky interface.

The Bluetooth LE logic is implemented in the LedButtonServiceImpl class, which is injected as a "profile".

Structure

The nRF Blinky application has been created in Jetpack Compose.

Dependencies

It is using the following libraries:

The Gradle script 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 navigation entry
  • :blinky:spec - contains the Blinky device specification, i.e. Blinky API or the Service UUID
  • :blinky:ble - contains the BLE related code, i.e. BlinkyManager implementation
  • :blinky:ui - contains the UI related code, i.e. BlinkyScreen or BlinkyViewModel implementation, and the BlinkyService

The :blinky:ui and :blinky:spec modules are transport agnostic. The Bluetooth LE transport is specified in the :app module using Hilt here.

The app is using Navigation 3. The :app module defines navigation in App composable. The entries are defined in the :scanner and :blinky:ui modules.

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
  • Button state (Pressed/Released).

    • UUID: 00001524-1212-EFDE-1523-785FEABCD123
    • Properties: Notify
      • Value: 0x01 => Button Pressed
      • Value: 0x00 => Button Released

For documentation for nRF5 SDK, check out this link.

Requirements

  • This application depends on Kotlin BLE Library.
  • Android 6 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 nRF Connect SDK (Peripheral LBS sample).

The device should appear on the scanner screen after granting required permissions.

Required permissions

  • ACCESS_FINE_LOCATION - 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.

Note

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.

  • POST_NOTIFICATIONS - permissions is used for showing a foreground service notification, which allows to control the LED state when the app is in background.

  • VIBRATE - required to vibrate when the Button on a DK is pressed.

  • FOREGROUND_SERVICE and FOREGROUND_SERVICE_CONNECTED_DEVICE are needed for the Service to be started as a foreground service.

About

nRF Blinky is an application developed targeting an audience of developers who are new to Bluetooth Low Energy

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors