This application shows how to use GAP to transmit a simple value to disconnected peer listening for advertisement every time that a value is updated. The canonical source for this example lives at: https://github.com/ARMmbed/mbed-os-example-ble/tree/master/BLE_GAPButton

Button count over GAP

This application shows how to use GAP to transmit a simple value to disconnected peer listening for advertisement every time that a value is updated:

  • The value is a count of how many times a button on the device was pressed (the code actually monitors the button's releases, not press downs).
  • We transmit the value in the SERVICE_DATA field of the advertising payload.

Running the application

Requirements

The sample application can be seen on any BLE scanner on a smartphone. If you don't have a scanner on your phone, please install :

- nRF Master Control Panel for Android.

- LightBlue for iPhone.

Hardware requirements are in the main readme.

Building instructions

Building with mbed CLI

If you'd like to use mbed CLI to build this, then you should refer to the main readme. The instructions here relate to using the developer.mbed.org Online Compiler

In order to build this example in the mbed Online Compiler, first import the example using the ‘Import’ button on the right hand side.

Next, select a platform to build for. This must either be a platform that supports BLE, for example the NRF51-DK, or one of the following:

List of platforms supporting Bluetooth Low Energy

Or you must also add a piece of hardware and the supporting library that includes a Bluetooth Low Energy driver for that hardware, for example the K64F or NUCLEO_F401RE with the X-NUCLEO-IDB05A1

List of components supporting Bluetooth Low Energy.

Once you have selected your platform, compile the example and drag and drop the resulting binary onto your board.

For general instructions on using the mbed Online Compiler, please see the mbed Handbook

Checking for success

Note: Screens captures depicted below show what is expected from this example if the scanner used is nRF Master Control Panel version 4.0.5. If you encounter any difficulties consider trying another scanner or another version of nRF Master Control Panel. Alternative scanners may require reference to their manuals.

  • Build the application and install it on your board as explained in the building instructions.
  • Open the BLE scanner on your phone.
  • Start a scan.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-GAPButton/raw-file/8f898b781de2/img/start_scan.png

figure 1 How to start scan using nRF Master Control Panel 4.0.5.

  • Find your device; it should be named `GAPButton`; and look at the advertisement broadcasted by your device (there is no need to connect to your device).

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-GAPButton/raw-file/8f898b781de2/img/discovery.png

figure 2 Scan results using nRF Master Control Panel 4.0.5.

  • The Service Data field of the advertisement packet broadcasted by your device reflects the button press count. The starting value is 0.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-GAPButton/raw-file/8f898b781de2/img/initial_state.png

figure 3 Initial state of the button using nRF Master Control Panel 4.0.5.

  • Press the button on the device.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-GAPButton/raw-file/8f898b781de2/img/first_press.png

figure 3 State after 1 button press using nRF Master Control Panel 4.0.5.

  • The Service Data field value of the advertisement packet should change every time you press the button.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-GAPButton/raw-file/8f898b781de2/img/result.png

figure 3 State after 6 button press using nRF Master Control Panel 4.0.5.

Note

Since broadcasting is not reliable and your phone may scan intermittently, it is possible that your phone will miss button updates.

Committer:
mbed_official
Date:
Fri Oct 18 15:01:02 2019 +0100
Revision:
85:c66873cfddb4
Parent:
84:07091894cd00
Merge pull request #268 from trowbridgec/add-ep-agora

Add support for the Embedded Planet EP_AGORA target
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-ble

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 3:f0ed4199b362 1 {
mbed_official 6:bfe23efb0d97 2 "config": {
mbed_official 6:bfe23efb0d97 3 "ble_button_pin_name": {
mbed_official 6:bfe23efb0d97 4 "help": "The pin name used as button in this application",
mbed_official 6:bfe23efb0d97 5 "macro_name": "BLE_BUTTON_PIN_NAME",
mbed_official 6:bfe23efb0d97 6 "required": true
mbed_official 83:5f43cd2a93e6 7 },
mbed_official 83:5f43cd2a93e6 8 "ble_button_pin_pull": {
mbed_official 83:5f43cd2a93e6 9 "help": "The BLE button may need a pull-up. Possible values are PullUp, PullDown, PullNone (default).",
mbed_official 83:5f43cd2a93e6 10 "macro_name": "BLE_BUTTON_PIN_PULL",
mbed_official 83:5f43cd2a93e6 11 "value": "PullNone"
mbed_official 6:bfe23efb0d97 12 }
mbed_official 6:bfe23efb0d97 13 },
mbed_official 3:f0ed4199b362 14 "target_overrides": {
mbed_official 6:bfe23efb0d97 15 "NRF51_DK": {
mbed_official 6:bfe23efb0d97 16 "ble_button_pin_name": "BUTTON1"
mbed_official 6:bfe23efb0d97 17 },
mbed_official 3:f0ed4199b362 18 "K64F": {
mbed_official 3:f0ed4199b362 19 "target.features_add": ["BLE"],
mbed_official 72:89208d8c67a2 20 "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"],
mbed_official 6:bfe23efb0d97 21 "ble_button_pin_name": "SW2"
mbed_official 3:f0ed4199b362 22 },
mbed_official 3:f0ed4199b362 23 "NUCLEO_F401RE": {
mbed_official 3:f0ed4199b362 24 "target.features_add": ["BLE"],
mbed_official 72:89208d8c67a2 25 "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"],
mbed_official 6:bfe23efb0d97 26 "ble_button_pin_name": "USER_BUTTON"
mbed_official 41:5d7d704433f1 27 },
mbed_official 41:5d7d704433f1 28 "DISCO_L475VG_IOT01A": {
mbed_official 41:5d7d704433f1 29 "target.features_add": ["BLE"],
mbed_official 72:89208d8c67a2 30 "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"],
mbed_official 41:5d7d704433f1 31 "ble_button_pin_name": "USER_BUTTON"
mbed_official 78:3f848aa75a8a 32 },
mbed_official 83:5f43cd2a93e6 33 "NUCLEO_WB55RG": {
mbed_official 83:5f43cd2a93e6 34 "ble_button_pin_name": "USER_BUTTON",
mbed_official 83:5f43cd2a93e6 35 "ble_button_pin_pull": "PullUp"
mbed_official 83:5f43cd2a93e6 36 },
mbed_official 78:3f848aa75a8a 37 "NRF52840_DK": {
mbed_official 78:3f848aa75a8a 38 "target.features_add": ["BLE"],
mbed_official 78:3f848aa75a8a 39 "ble_button_pin_name": "BUTTON1"
mbed_official 78:3f848aa75a8a 40 },
mbed_official 78:3f848aa75a8a 41 "NRF52_DK": {
mbed_official 78:3f848aa75a8a 42 "target.features_add": ["BLE"],
mbed_official 78:3f848aa75a8a 43 "ble_button_pin_name": "BUTTON1"
mbed_official 78:3f848aa75a8a 44 },
mbed_official 78:3f848aa75a8a 45 "MTB_UBLOX_NINA_B1": {
mbed_official 78:3f848aa75a8a 46 "ble_button_pin_name": "BUTTON1"
mbed_official 85:c66873cfddb4 47 },
mbed_official 85:c66873cfddb4 48 "EP_AGORA": {
mbed_official 85:c66873cfddb4 49 "ble_button_pin_name": "PIN_NAME_PUSH_BUTTON",
mbed_official 85:c66873cfddb4 50 "target.macros_add": ["NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=4"]
mbed_official 85:c66873cfddb4 51 }
mbed_official 3:f0ed4199b362 52 }
mbed_official 3:f0ed4199b362 53 }