| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Glucose Application
This example requires one of the following SoftDevices: S130, S132

Important: Before you run this example, make sure to program the SoftDevice.

The Glucose Application is an example that implements the Glucose Profile using the hardware delivered in the nRF5 Development Kit.

The application includes the two services in the Glucose Profile:

- Glucose Service
- Device Information Service

In addition, use of the Battery Service is also demonstrated.

When the application starts, a timer for generating battery measurements is started.

The actual measurements are hard-coded values. They get added when connected and bonded to a central, at each press of the button 2. The timestamps are simulated and it uses the Record Access Control point and implements the filtering on sequence number. It supports only glucose measurement characteristic, not glucose context.

Note
  This application is not power optimized!
  The application will stop advertising after 3 minutes and go to system-off mode. Push the button 1 to restart advertising.

# Setup

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\ble_peripheral\ble_app_gls`

Button assignments - in addition to those defined in BSP BLE Button Assignments:

- When awake:
  - Button 2: Create a new record.

## MITM protection

The Glucose Application secures the bond using Man-in-the-Middle protection (MITM). A passkey must be entered at the central to complete the bonding and ensure MITM protection. The Glucose Application will present the passkey during bonding. It is sent on the UART. It is therefore important that UART is set up correctly on the receiving side. The application uses the following UART settings:

- Baud rate: 115.200
- 8 data bits
- 1 stop bit
- No parity
- HW flow control: RTS/CTS

If a collector does not use MITM protection, the Glucose Application will disconnect and delete the bond to enforce using MITM protection.

# Demonstrating the Glucose Meter Profile

The Glucose Meter Profile uses the Record Access Control Point characteristic to access all measurements. This means that the sensor does not automatically send new measurements, but the collector has to fetch them writing request to the control point (see developer.bluetooth.org for more detail on the RACP characteristic).

# Testing

Test the Glucose Meter Application with the nRF Toolbox app, which is available on both iOS (App Store) and Android (Google Play).

You can also test the application with the Master Control Panel by performing the following steps:

1. Compile and program the application. Observe that the BSP_INDICATE_ADVERTISING state is indicated.
2. Bond to the device (it is advertising as 'Nordic_Glucose'). A new window opens up and asks for a passkey. Enter the key received over the UART.
3. Perform service discovery. Observe that the BSP_INDICATE_CONNECTED state is indicated.
4. Click the 'Enable services' button on the Master Control Panel. Observe that Battery Level notifications are received every 10 seconds.
5. Press Button 2 five times.
6. Do a Read all records operation:
   - Write 0101 (OpCode : REPORT_STORED_RECORDS, Operator : ALL_STORED_RECORDS) to Record Access
   - Control Point Characteristic (UUID 0x2A52).
   - Observe that you receive five notification of the glucose measurements(UUID 0x2A18) and one indication of the RACP indicating success (06000101);
7. Read the number of stored records:
   - Write 0401 (OpCode: REPORT_NUM_STORED_RECORDS, Operator: ALL_STORED_RECORDS) to Record Access Control Point
   - Characteristic (UUID 0x2A52).
   - Observe that you get an indication of the RACP giving you the number of records, 5 (05000500).