Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental services example #349

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 53 additions & 65 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,72 @@
version: 2.1

#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
prepare:
docker:
- image: mbedos/mbed-os-env:latest
working_directory: ~
steps:
- checkout:
path: mbed-os-example-ble
- run: |
cd mbed-os-example-ble
git clone https://github.com/ARMmbed/mbed-os.git
- run:
working_directory: mbed-os-example-ble
command: for i in BLE_* ; do cd $i ; ln -s $PWD/../mbed-os mbed-os ; cd .. ; done
- checkout
- run: git clone https://github.com/ARMmbed/mbed-os.git
- run: for i in BLE_* ; do cd $i ; ln -s $PWD/../mbed-os mbed-os ; mbed update ; cd .. ; done
- persist_to_workspace:
root: /root/project
paths: mbed-os-example-ble
root: .
paths:
- .

build_nrf52840:
build_mbed:
docker:
- image: mbedos/mbed-os-env:stable
working_directory: ~
- image: mbedos/mbed-os-env-armc:latest
auth:
username: mbedos
password: $DOCKERHUB_PASSWORD
parameters:
toolchain:
type: string
target:
type: string
steps:
- attach_workspace:
at: /root/project
- run: |
cd mbed-os-example-ble
for i in BLE_* ; do cd $i ; mbed update ; mbed compile -t GCC_ARM -m NRF52840_DK || exit 1 ; cd .. ; done
at: .
- run: for i in BLE_* ; do cd $i ; mbed compile -t << parameters.toolchain >> -m << parameters.target >> || exit 1 ; cd .. ; done

build_disco_l475vg:
build_cmake:
docker:
- image: mbedos/mbed-os-env:stable
working_directory: ~
- image: mbedos/mbed-os-env-armc:latest
auth:
username: mbedos
password: $DOCKERHUB_PASSWORD
parameters:
toolchain:
type: string
target:
type: string
steps:
- attach_workspace:
at: /root/project
- run: |
cd mbed-os-example-ble
for i in BLE_* ; do cd $i ; mbed update ; mbed compile -t GCC_ARM -m DISCO_L475VG_IOT01A || exit 1 ; cd .. ; done

cmake_nrf52840:
docker:
- image: mbedos/mbed-os-env:latest
working_directory: ~
steps:
- attach_workspace:
at: /root/project
- run: |
cd mbed-os-example-ble
for i in BLE_* ; do cd $i ; mbedtools checkout ; mbedtools build -t GCC_ARM -m NRF52840_DK || exit 1 ; cd .. ; done

cmake_disco_l475vg:
docker:
- image: mbedos/mbed-os-env:latest
working_directory: ~
steps:
- attach_workspace:
at: /root/project
- run: |
cd mbed-os-example-ble
for i in BLE_* ; do cd $i ; mbedtools checkout ; mbedtools build -t GCC_ARM -m DISCO_L475VG_IOT01A || exit 1 ; cd .. ; done
at: .
- run: python3 -m pip install mbed-tools --upgrade # remove after docker image is updated to contain new tools
- run: for i in BLE_* ; do cd $i ; mbed-tools compile -t << parameters.toolchain >> -m << parameters.target >> || exit 1 ; cd .. ; done

workflows:
version: 2
workflow:
jobs:
- prepare
- build_nrf52840:
requires:
- prepare
- build_disco_l475vg:
requires:
- prepare
- cmake_nrf52840:
requires:
- prepare
- cmake_disco_l475vg:
requires:
- prepare
- prepare
- build_mbed:
context:
- mbedos-docker-hub-creds
requires:
- prepare
matrix:
parameters:
target: ["DISCO_L475VG_IOT01A", "NRF52840_DK"]
toolchain: ["GCC_ARM"]
name: build-mbed-<< matrix.target >>-<< matrix.toolchain >>
- build_cmake:
context:
- mbedos-docker-hub-creds
requires:
- prepare
matrix:
parameters:
target: ["DISCO_L475VG_IOT01A"]
toolchain: ["GCC_ARM"]
name: build-cmake-<< matrix.target >>-<< matrix.toolchain >>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ mbed-os/
mbed_settings.py
mbed_config.h
*.pyc
BUILD
BUILD/
cmake_build/

2 changes: 1 addition & 1 deletion BLE_Advertising/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
2 changes: 1 addition & 1 deletion BLE_GAP/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
2 changes: 1 addition & 1 deletion BLE_GattClient_CharacteristicUpdates/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
2 changes: 1 addition & 1 deletion BLE_GattClient_CharacteristicWrite/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
2 changes: 1 addition & 1 deletion BLE_GattServer_AddService/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
2 changes: 1 addition & 1 deletion BLE_GattServer_CharacteristicUpdates/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
2 changes: 1 addition & 1 deletion BLE_GattServer_CharacteristicWrite/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
https://github.com/ARMmbed/mbed-os-ble-utils/
1 change: 1 addition & 0 deletions BLE_GattServer_ExperimentalServices/.mbed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ROOT=.
46 changes: 46 additions & 0 deletions BLE_GattServer_ExperimentalServices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "")
set(APP_TARGET BLE_GattServer_ExperimentalServices)

include(${MBED_PATH}/tools/cmake/app.cmake)

add_subdirectory(${MBED_PATH})

add_subdirectory(mbed-os-ble-utils)
add_subdirectory(mbed-os-experimental-ble-services/services/CurrentTime)
add_subdirectory(mbed-os-experimental-ble-services/services/LinkLoss)

add_executable(${APP_TARGET})

mbed_configure_app_target(${APP_TARGET})

mbed_set_mbed_target_linker_script(${APP_TARGET})

project(${APP_TARGET})

target_sources(${APP_TARGET}
PRIVATE
source/main.cpp
)

target_link_libraries(${APP_TARGET}
PRIVATE
mbed-os
mbed-events
mbed-ble
mbed-ble-utils
ble-service-link-loss
ble-service-current-time
)

mbed_set_post_build(${APP_TARGET})

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
102 changes: 102 additions & 0 deletions BLE_GattServer_ExperimentalServices/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Experimental Services
This example demonstrates the Link Loss and Current Time Services from the [Experimental BLE Services](https://github.com/ARMmbed/mbed-os-experimental-ble-services) repository.

## Overview

### Link Loss Service
The application sends an alert message over a serial terminal once the connection to the client is lost without prior warning.
The client sets the alert level by writing a valid byte to the alert level characteristic inside the Link Loss Service (LLS):

* 0x00 ("No Alert")
* 0x01 ("Mild Alert")
* 0x02 ("High Alert")

The alert ends after a user-defined timeout (= 1 minute).

### Current Time Service
The application permits reading/writing of the device's current time.
In the latter case, the client sets the current time by writing a stream of bytes to the current time characteristic inside the Current Time Service (CTS).
Table 1 shows the byte stream required to set the device's current time to Wed, 28 Oct 2009 11:35:37.

| B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 |
|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|
| 0xD9 | 0x07 | 0x0A | 0x1C | 0x0B | 0x23 | 0x25 | 0x03 | 0x00 | 0x00 |

**Table 1. Byte stream required to set the device's current time to Wed, 28 Oct 2009 11:35:37**

## Usage

### Hardware Requirements
Please refer to the main [README](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md).

### Build Instructions
Please refer to the main [README](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md).

### Demonstration
**Note:** The steps given below demonstrate the application using an Android smartphone running nRF Connect 4.24.3.
The illustrations will be different for other clients.
* Build the application and flash the board
* Open a serial terminal on your host to receive serial prints from the application:
`mbed term -b 115200`
* Open nRF Connect, locate your device and press connect (Fig. 1)

![](img/connect.png)

**Fig. 1 Connecting to the device**

#### Link Loss Service

* Select the Link Loss Service from the list of available services (Fig. 2)

![](img/select_lls.png)

**Fig. 2 Selecting the Link Loss Service**

* Press the upward pointing arrow to interact with the alert level characteristic (Fig. 3)

![](img/interact_alert_level.png)

**Fig. 3. Interacting with the alert level characteristic**

* Select an appropriate alert level from the dropdown menu and press send (Fig. 4)

![](img/write_alert_level.png)

**Fig. 4. Writing the alert level characteristic**

* Confirm that the value parameter was updated after the write (Fig. 5)

![](img/read_alert_level.png)

**Fig. 5. Reading the alert level characteristic**

* Go far enough away from the device so that nRF Connect disconnects in an ungraceful fashion
* The alert level should appear at your terminal, e.g. "High Alert!"

#### Current Time Service

* Select the Current Time Service from the list of available services (Fig. 6)

![](img/select_cts.png)

**Fig. 6. Selecting the Current Time Service**

* Press the upward pointing arrow to interact with the current time characteristic (Fig. 7)

![](img/interact_current_time.png)

**Fig. 7. Interacting with the current time characteristic**

* Create a new write value for the byte stream in Table 1, save and load it, and press send (Fig. 8)

![](img/write_current_time.png)

**Fig. 8. Writing the current time characteristic**

* Confirm that the value parameter was updated with the correct date/time after the write (Fig. 9)

![](img/read_current_time.png)

**Fig. 9. Reading the current time characteristic**

* The current time in seconds should appear at your terminal, i.e. "1256729737"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions BLE_GattServer_ExperimentalServices/mbed-os-ble-utils.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os-ble-utils/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os-experimental-ble-services
1 change: 1 addition & 0 deletions BLE_GattServer_ExperimentalServices/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/
23 changes: 23 additions & 0 deletions BLE_GattServer_ExperimentalServices/mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"target_overrides": {
"*": {
"platform.stdio-baud-rate": 115200
},
"K64F": {
"target.components_add": ["BlueNRG_MS"],
"target.features_add": ["BLE"],
"target.extra_labels_add": ["CORDIO"]
},
"NUCLEO_F401RE": {
"target.components_add": ["BlueNRG_MS"],
"target.features_add": ["BLE"],
"target.extra_labels_add": ["CORDIO"]
},
"NRF52840_DK": {
"target.features_add": ["BLE"]
},
"NRF52_DK": {
"target.features_add": ["BLE"]
}
}
}
Loading