Skip to content

Commit 51afed4

Browse files
paul-szczepanek-armAbbas Bracken Ziad
andauthored
Add experimental services example (#349)
* Add Link Loss Service example * Add Current Tme Service * Update README.md * Update README.md Remove last bullet point * Corrections 28/12 - Add lib in requires - Change name of demo class - Add captions to remaining figures - Correct current time images * remove accidental commit symlink is breaking CI * add cmakelists to example * fix ci to use new tools * requires not needed for libraries * use master of utils Co-authored-by: Abbas Bracken Ziad <[email protected]>
1 parent ea20e43 commit 51afed4

File tree

28 files changed

+423
-75
lines changed

28 files changed

+423
-75
lines changed

.circleci/config.yml

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,72 @@
1+
version: 2.1
12

2-
#
3-
# Check https://circleci.com/docs/2.0/language-python/ for more details
4-
#
5-
version: 2
63
jobs:
74
prepare:
85
docker:
96
- image: mbedos/mbed-os-env:latest
10-
working_directory: ~
117
steps:
12-
- checkout:
13-
path: mbed-os-example-ble
14-
- run: |
15-
cd mbed-os-example-ble
16-
git clone https://github.com/ARMmbed/mbed-os.git
17-
- run:
18-
working_directory: mbed-os-example-ble
19-
command: for i in BLE_* ; do cd $i ; ln -s $PWD/../mbed-os mbed-os ; cd .. ; done
8+
- checkout
9+
- run: git clone https://github.com/ARMmbed/mbed-os.git
10+
- run: for i in BLE_* ; do cd $i ; ln -s $PWD/../mbed-os mbed-os ; mbed update ; cd .. ; done
2011
- persist_to_workspace:
21-
root: /root/project
22-
paths: mbed-os-example-ble
12+
root: .
13+
paths:
14+
- .
2315

24-
build_nrf52840:
16+
build_mbed:
2517
docker:
26-
- image: mbedos/mbed-os-env:stable
27-
working_directory: ~
18+
- image: mbedos/mbed-os-env-armc:latest
19+
auth:
20+
username: mbedos
21+
password: $DOCKERHUB_PASSWORD
22+
parameters:
23+
toolchain:
24+
type: string
25+
target:
26+
type: string
2827
steps:
2928
- attach_workspace:
30-
at: /root/project
31-
- run: |
32-
cd mbed-os-example-ble
33-
for i in BLE_* ; do cd $i ; mbed update ; mbed compile -t GCC_ARM -m NRF52840_DK || exit 1 ; cd .. ; done
29+
at: .
30+
- run: for i in BLE_* ; do cd $i ; mbed compile -t << parameters.toolchain >> -m << parameters.target >> || exit 1 ; cd .. ; done
3431

35-
build_disco_l475vg:
32+
build_cmake:
3633
docker:
37-
- image: mbedos/mbed-os-env:stable
38-
working_directory: ~
34+
- image: mbedos/mbed-os-env-armc:latest
35+
auth:
36+
username: mbedos
37+
password: $DOCKERHUB_PASSWORD
38+
parameters:
39+
toolchain:
40+
type: string
41+
target:
42+
type: string
3943
steps:
4044
- attach_workspace:
41-
at: /root/project
42-
- run: |
43-
cd mbed-os-example-ble
44-
for i in BLE_* ; do cd $i ; mbed update ; mbed compile -t GCC_ARM -m DISCO_L475VG_IOT01A || exit 1 ; cd .. ; done
45-
46-
cmake_nrf52840:
47-
docker:
48-
- image: mbedos/mbed-os-env:latest
49-
working_directory: ~
50-
steps:
51-
- attach_workspace:
52-
at: /root/project
53-
- run: |
54-
cd mbed-os-example-ble
55-
for i in BLE_* ; do cd $i ; mbedtools checkout ; mbedtools build -t GCC_ARM -m NRF52840_DK || exit 1 ; cd .. ; done
56-
57-
cmake_disco_l475vg:
58-
docker:
59-
- image: mbedos/mbed-os-env:latest
60-
working_directory: ~
61-
steps:
62-
- attach_workspace:
63-
at: /root/project
64-
- run: |
65-
cd mbed-os-example-ble
66-
for i in BLE_* ; do cd $i ; mbedtools checkout ; mbedtools build -t GCC_ARM -m DISCO_L475VG_IOT01A || exit 1 ; cd .. ; done
45+
at: .
46+
- run: python3 -m pip install mbed-tools --upgrade # remove after docker image is updated to contain new tools
47+
- run: for i in BLE_* ; do cd $i ; mbed-tools compile -t << parameters.toolchain >> -m << parameters.target >> || exit 1 ; cd .. ; done
6748

6849
workflows:
69-
version: 2
7050
workflow:
7151
jobs:
72-
- prepare
73-
- build_nrf52840:
74-
requires:
75-
- prepare
76-
- build_disco_l475vg:
77-
requires:
78-
- prepare
79-
- cmake_nrf52840:
80-
requires:
81-
- prepare
82-
- cmake_disco_l475vg:
83-
requires:
84-
- prepare
52+
- prepare
53+
- build_mbed:
54+
context:
55+
- mbedos-docker-hub-creds
56+
requires:
57+
- prepare
58+
matrix:
59+
parameters:
60+
target: ["DISCO_L475VG_IOT01A", "NRF52840_DK"]
61+
toolchain: ["GCC_ARM"]
62+
name: build-mbed-<< matrix.target >>-<< matrix.toolchain >>
63+
- build_cmake:
64+
context:
65+
- mbedos-docker-hub-creds
66+
requires:
67+
- prepare
68+
matrix:
69+
parameters:
70+
target: ["DISCO_L475VG_IOT01A"]
71+
toolchain: ["GCC_ARM"]
72+
name: build-cmake-<< matrix.target >>-<< matrix.toolchain >>

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ mbed-os/
3838
mbed_settings.py
3939
mbed_config.h
4040
*.pyc
41-
BUILD
41+
BUILD/
42+
cmake_build/
4243

BLE_Advertising/mbed-os-ble-utils.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/

BLE_GAP/mbed-os-ble-utils.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os-ble-utils/#5a87e640383b2a1465e19ea6c052f80459314670
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ROOT=.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2020 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5+
6+
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
7+
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "")
8+
set(APP_TARGET BLE_GattServer_ExperimentalServices)
9+
10+
include(${MBED_PATH}/tools/cmake/app.cmake)
11+
12+
add_subdirectory(${MBED_PATH})
13+
14+
add_subdirectory(mbed-os-ble-utils)
15+
add_subdirectory(mbed-os-experimental-ble-services/services/CurrentTime)
16+
add_subdirectory(mbed-os-experimental-ble-services/services/LinkLoss)
17+
18+
add_executable(${APP_TARGET})
19+
20+
mbed_configure_app_target(${APP_TARGET})
21+
22+
mbed_set_mbed_target_linker_script(${APP_TARGET})
23+
24+
project(${APP_TARGET})
25+
26+
target_sources(${APP_TARGET}
27+
PRIVATE
28+
source/main.cpp
29+
)
30+
31+
target_link_libraries(${APP_TARGET}
32+
PRIVATE
33+
mbed-os
34+
mbed-events
35+
mbed-ble
36+
mbed-ble-utils
37+
ble-service-link-loss
38+
ble-service-current-time
39+
)
40+
41+
mbed_set_post_build(${APP_TARGET})
42+
43+
option(VERBOSE_BUILD "Have a verbose build process")
44+
if(VERBOSE_BUILD)
45+
set(CMAKE_VERBOSE_MAKEFILE ON)
46+
endif()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Experimental Services
2+
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.
3+
4+
## Overview
5+
6+
### Link Loss Service
7+
The application sends an alert message over a serial terminal once the connection to the client is lost without prior warning.
8+
The client sets the alert level by writing a valid byte to the alert level characteristic inside the Link Loss Service (LLS):
9+
10+
* 0x00 ("No Alert")
11+
* 0x01 ("Mild Alert")
12+
* 0x02 ("High Alert")
13+
14+
The alert ends after a user-defined timeout (= 1 minute).
15+
16+
### Current Time Service
17+
The application permits reading/writing of the device's current time.
18+
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).
19+
Table 1 shows the byte stream required to set the device's current time to Wed, 28 Oct 2009 11:35:37.
20+
21+
| B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 |
22+
|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|
23+
| 0xD9 | 0x07 | 0x0A | 0x1C | 0x0B | 0x23 | 0x25 | 0x03 | 0x00 | 0x00 |
24+
25+
**Table 1. Byte stream required to set the device's current time to Wed, 28 Oct 2009 11:35:37**
26+
27+
## Usage
28+
29+
### Hardware Requirements
30+
Please refer to the main [README](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md).
31+
32+
### Build Instructions
33+
Please refer to the main [README](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md).
34+
35+
### Demonstration
36+
**Note:** The steps given below demonstrate the application using an Android smartphone running nRF Connect 4.24.3.
37+
The illustrations will be different for other clients.
38+
* Build the application and flash the board
39+
* Open a serial terminal on your host to receive serial prints from the application:
40+
`mbed term -b 115200`
41+
* Open nRF Connect, locate your device and press connect (Fig. 1)
42+
43+
![](img/connect.png)
44+
45+
**Fig. 1 Connecting to the device**
46+
47+
#### Link Loss Service
48+
49+
* Select the Link Loss Service from the list of available services (Fig. 2)
50+
51+
![](img/select_lls.png)
52+
53+
**Fig. 2 Selecting the Link Loss Service**
54+
55+
* Press the upward pointing arrow to interact with the alert level characteristic (Fig. 3)
56+
57+
![](img/interact_alert_level.png)
58+
59+
**Fig. 3. Interacting with the alert level characteristic**
60+
61+
* Select an appropriate alert level from the dropdown menu and press send (Fig. 4)
62+
63+
![](img/write_alert_level.png)
64+
65+
**Fig. 4. Writing the alert level characteristic**
66+
67+
* Confirm that the value parameter was updated after the write (Fig. 5)
68+
69+
![](img/read_alert_level.png)
70+
71+
**Fig. 5. Reading the alert level characteristic**
72+
73+
* Go far enough away from the device so that nRF Connect disconnects in an ungraceful fashion
74+
* The alert level should appear at your terminal, e.g. "High Alert!"
75+
76+
#### Current Time Service
77+
78+
* Select the Current Time Service from the list of available services (Fig. 6)
79+
80+
![](img/select_cts.png)
81+
82+
**Fig. 6. Selecting the Current Time Service**
83+
84+
* Press the upward pointing arrow to interact with the current time characteristic (Fig. 7)
85+
86+
![](img/interact_current_time.png)
87+
88+
**Fig. 7. Interacting with the current time characteristic**
89+
90+
* Create a new write value for the byte stream in Table 1, save and load it, and press send (Fig. 8)
91+
92+
![](img/write_current_time.png)
93+
94+
**Fig. 8. Writing the current time characteristic**
95+
96+
* Confirm that the value parameter was updated with the correct date/time after the write (Fig. 9)
97+
98+
![](img/read_current_time.png)
99+
100+
**Fig. 9. Reading the current time characteristic**
101+
102+
* The current time in seconds should appear at your terminal, i.e. "1256729737"
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os-ble-utils/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os-experimental-ble-services
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"platform.stdio-baud-rate": 115200
5+
},
6+
"K64F": {
7+
"target.components_add": ["BlueNRG_MS"],
8+
"target.features_add": ["BLE"],
9+
"target.extra_labels_add": ["CORDIO"]
10+
},
11+
"NUCLEO_F401RE": {
12+
"target.components_add": ["BlueNRG_MS"],
13+
"target.features_add": ["BLE"],
14+
"target.extra_labels_add": ["CORDIO"]
15+
},
16+
"NRF52840_DK": {
17+
"target.features_add": ["BLE"]
18+
},
19+
"NRF52_DK": {
20+
"target.features_add": ["BLE"]
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)