Skip to content

Commit 3570346

Browse files
s07641069UR6LALserhiiSalamakharestyled-commits
authored andcommitted
[Telink] Add air quality sensor app (#29579)
* [Telink] add draft air quality app * [Telink] add air-quality example * [Telink] Clear code * [Telink] add air-quality example to github-CI * [Telink] Adopt to latest master chnages * [Telink] update AppTask of air-quality-sensor-app * [Telink] use new APIs * Restyled by whitespace * Restyled by autopep8 * [Telink] Remove read example due to spelling errors * [Telink] fix spelling errors * [Telink] Fix typo --------- Co-authored-by: UR6LAL <ur6lal@gmail.com> Co-authored-by: Serhii Salamakha <serhii.salamakha@gmail.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 7ddd80a commit 3570346

File tree

17 files changed

+611
-19
lines changed

17 files changed

+611
-19
lines changed

.github/workflows/examples-telink.yaml

+16-16
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ jobs:
5454
with:
5555
gh-context: ${{ toJson(github) }}
5656

57+
- name: Build example Telink (B92) Air Quality Sensor App
58+
run: |
59+
./scripts/run_in_build_env.sh \
60+
"./scripts/build/build_examples.py --target 'telink-tlsr9528a-air-quality-sensor' build"
61+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
62+
telink tlsr9528a air-quality-sensor-app \
63+
out/telink-tlsr9528a-air-quality-sensor/zephyr/zephyr.elf \
64+
/tmp/bloat_reports/
65+
66+
- name: clean out build output
67+
run: rm -rf ./out
68+
5769
- name: Build example Telink (B91) All Clusters App
5870
run: |
5971
./scripts/run_in_build_env.sh \
@@ -124,25 +136,13 @@ jobs:
124136
- name: clean out build output (keep tools)
125137
run: rm -rf ./out/telink*
126138

127-
- name: Build example Telink (B92) Lighting App with RPC, Shell and Factory Data
128-
run: |
129-
./scripts/run_in_build_env.sh \
130-
"./scripts/build/build_examples.py --target 'telink-tlsr9528a-light-rpc-shell-factory-data' build"
131-
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
132-
telink tlsr9528a lighting-app-rpc-shell-factory-data \
133-
out/telink-tlsr9528a-light-rpc-shell-factory-data/zephyr/zephyr.elf \
134-
/tmp/bloat_reports/
135-
136-
- name: clean out build output
137-
run: rm -rf ./out
138-
139-
- name: Build example Telink (B91) Light Switch App
139+
- name: Build example Telink (B92) Light Switch App with RPC, Shell and Factory Data
140140
run: |
141141
./scripts/run_in_build_env.sh \
142-
"./scripts/build/build_examples.py --target 'telink-tlsr9518adk80d-light-switch' build"
142+
"./scripts/build/build_examples.py --target 'telink-tlsr9528a-light-switch-rpc-shell-factory-data' build"
143143
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
144-
telink tlsr9518adk80d light-switch-app \
145-
out/telink-tlsr9518adk80d-light-switch/zephyr/zephyr.elf \
144+
telink tlsr9528a light-switch-app-rpc-shell-factory-data \
145+
out/telink-tlsr9528a-light-switch-rpc-shell-factory-data/zephyr/zephyr.elf \
146146
/tmp/bloat_reports/
147147
148148
- name: clean out build output

.vscode/tasks.json

+1
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@
663663
"openiotsdk-lock",
664664
"openiotsdk-shell",
665665
"qpg-qpg6100-lock",
666+
"telink-tlsr9518adk80d-air-quality-sensor",
666667
"telink-tlsr9518adk80d-all-clusters",
667668
"telink-tlsr9518adk80d-all-clusters-minimal",
668669
"telink-tlsr9518adk80d-bridge",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#
2+
# Copyright (c) 2023 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
cmake_minimum_required(VERSION 3.13.1)
17+
18+
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
19+
get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
20+
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)
21+
22+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
23+
set(LOCAL_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
24+
else()
25+
unset(LOCAL_DTC_OVERLAY_FILE)
26+
endif()
27+
28+
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}.overlay")
29+
set(GLOBAL_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}.overlay")
30+
else()
31+
unset(GLOBAL_DTC_OVERLAY_FILE)
32+
endif()
33+
34+
if(DTC_OVERLAY_FILE)
35+
set(DTC_OVERLAY_FILE
36+
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
37+
CACHE STRING "" FORCE
38+
)
39+
else()
40+
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
41+
endif()
42+
43+
set(CONF_FILE prj.conf)
44+
45+
# Load NCS/Zephyr build system
46+
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
47+
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
48+
49+
project(chip-telink-air-quality-sensor-example)
50+
51+
include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake)
52+
include(${CHIP_ROOT}/src/app/chip_data_model.cmake)
53+
54+
target_compile_options(app PRIVATE -fpermissive)
55+
56+
target_include_directories(app PRIVATE
57+
include
58+
${GEN_DIR}/app-common
59+
${GEN_DIR}/air-quality-sensor-app
60+
${TELINK_COMMON}/common/include
61+
${TELINK_COMMON}/util/include
62+
${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/include)
63+
64+
add_definitions(
65+
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
66+
)
67+
68+
target_sources(app PRIVATE
69+
src/AppTask.cpp
70+
src/ZclCallbacks.cpp
71+
${TELINK_COMMON}/common/src/mainCommon.cpp
72+
${TELINK_COMMON}/common/src/AppTaskCommon.cpp
73+
${TELINK_COMMON}/util/src/LEDWidget.cpp
74+
${TELINK_COMMON}/util/src/ButtonManager.cpp
75+
${TELINK_COMMON}/util/src/ThreadUtil.cpp
76+
${TELINK_COMMON}/util/src/PWMDevice.cpp
77+
${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/src/air-quality-sensor-manager.cpp)
78+
79+
chip_configure_data_model(app
80+
INCLUDE_SERVER
81+
ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../air-quality-sensor-common/air-quality-sensor-app.zap
82+
)
83+
84+
if(CONFIG_CHIP_OTA_REQUESTOR)
85+
target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp)
86+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2023 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
mainmenu "Matter Telink Air Quality Sensor Example Application"
17+
18+
rsource "../../../config/telink/chip-module/Kconfig.defaults"
19+
source "Kconfig.zephyr"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Matter Telink Air Quality Sensor Example Application
2+
3+
You can use this example as a reference for creating your own application.
4+
5+
![Telink B91 EVK](http://wiki.telink-semi.cn/wiki/assets/Hardware/B91_Generic_Starter_Kit_Hardware_Guide/connection_chart.png)
6+
7+
## Build and flash
8+
9+
1. Run the Docker container:
10+
11+
```bash
12+
$ docker run -it --rm -v $PWD:/host -w /host ghcr.io/project-chip/chip-build-telink:$(wget -q -O - https://raw.githubusercontent.com/project-chip/connectedhomeip/master/.github/workflows/examples-telink.yaml 2> /dev/null | grep chip-build-telink | awk -F: '{print $NF}')
13+
```
14+
15+
Compatible docker image version can be found in next file:
16+
17+
```bash
18+
$ .github/workflows/examples-telink.yaml
19+
```
20+
21+
2. Activate the build environment:
22+
23+
```bash
24+
$ source ./scripts/activate.sh
25+
```
26+
27+
3. In the example dir run (replace _<build_target>_ with your board name, for
28+
example, `tlsr9518adk80d` or `tlsr9528a`):
29+
30+
```bash
31+
$ west build -b <build_target>
32+
```
33+
34+
4. Flash binary:
35+
36+
```
37+
$ west flash --erase
38+
```
39+
40+
## Usage
41+
42+
### UART
43+
44+
To get output from device, connect UART to following pins:
45+
46+
| Name | Pin |
47+
| :--: | :---------------------------- |
48+
| RX | PB3 (pin 17 of J34 connector) |
49+
| TX | PB2 (pin 16 of J34 connector) |
50+
| GND | GND |
51+
52+
### Buttons
53+
54+
The following buttons are available on **tlsr9518adk80d** board:
55+
56+
| Name | Function | Description |
57+
| :------- | :--------------------- | :----------------------------------------------------------------------------------------------------- |
58+
| Button 1 | Factory reset | Perform factory reset to forget currently commissioned Thread network and back to uncommissioned state |
59+
| Button 2 | `AirQuality` control | Manually triggers the `AirQuality` state |
60+
| Button 3 | Thread start | Commission thread with static credentials and enables the Thread on device |
61+
| Button 4 | Open commission window | The button is opening commissioning window to perform commissioning over BLE |
62+
63+
### LEDs
64+
65+
#### Indicate current state of Thread network
66+
67+
**Red** LED indicates current state of Thread network. It is able to be in
68+
following states:
69+
70+
| State | Description |
71+
| :-------------------------- | :--------------------------------------------------------------------------- |
72+
| Blinks with short pulses | Device is not commissioned to Thread, Thread is disabled |
73+
| Blinks with frequent pulses | Device is commissioned, Thread enabled. Device trying to JOIN thread network |
74+
| Blinks with wide pulses | Device commissioned and joined to thread network as CHILD |
75+
76+
#### Indicate identify of device
77+
78+
**Green** LED used to identify the device. The LED starts blinking when the
79+
Identify command of the Identify cluster is received. The command's argument can
80+
be used to specify the the effect. It is able to be in following effects:
81+
82+
| Effect | Description |
83+
| :------------------------------ | :--------------------------------------------------------------------------- |
84+
| Blinks (200 ms on/200 ms off) | Blink (`Clusters::Identify::EffectIdentifierEnum::kBlink`) |
85+
| Breathe (during 1000 ms) | Breathe (`Clusters::Identify::EffectIdentifierEnum::kBreathe`) |
86+
| Blinks (50 ms on/950 ms off) | Okay (`Clusters::Identify::EffectIdentifierEnum::kOkay`) |
87+
| Blinks (1000 ms on/1000 ms off) | Channel Change ( `Clusters::Identify::EffectIdentifierEnum::kChannelChange`) |
88+
| Blinks (950 ms on/50 ms off) | Finish ( `Clusters::Identify::EffectIdentifierEnum::kFinishEffect`) |
89+
| LED off | Stop (`Clusters::Identify::EffectIdentifierEnum::kStopEffect`) |
90+
91+
### CHIP tool commands
92+
93+
1. Build
94+
[chip-tool cli](https://github.com/project-chip/connectedhomeip/blob/master/examples/chip-tool/README.md)
95+
96+
2. Pair with device
97+
98+
```
99+
${CHIP_TOOL_DIR}/chip-tool pairing ble-thread ${NODE_ID} hex:${DATASET} ${PIN_CODE} ${DISCRIMINATOR}
100+
```
101+
102+
Example:
103+
104+
```
105+
./chip-tool pairing ble-thread 1234 hex:0e080000000000010000000300000f35060004001fffe0020811111111222222220708fd61f77bd3df233e051000112233445566778899aabbccddeeff030e4f70656e54687265616444656d6f010212340410445f2b5ca6f2a93a55ce570a70efeecb0c0402a0fff8 20202021 3840
106+
```
107+
108+
### OTA with Linux OTA Provider
109+
110+
OTA feature enabled by default only for ota-requestor-app example. To enable OTA
111+
feature for another Telink example:
112+
113+
- set CONFIG_CHIP_OTA_REQUESTOR=y in corresponding "prj.conf" configuration
114+
file.
115+
116+
After build application with enabled OTA feature, use next binary files:
117+
118+
- zephyr.bin - main binary to flash PCB (Use 2MB PCB).
119+
- zephyr-ota.bin - binary for OTA Provider
120+
121+
All binaries has the same SW version. To test OTA “zephyr-ota.bin” should have
122+
higher SW version than base SW. Set CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 in
123+
corresponding “prj.conf” configuration file.
124+
125+
Usage of OTA:
126+
127+
- Build the [Linux OTA Provider](../../ota-provider-app/linux)
128+
129+
```
130+
./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/ota-provider-app chip_config_network_layer_ble=false
131+
```
132+
133+
- Run the Linux OTA Provider with OTA image.
134+
135+
```
136+
./chip-ota-provider-app -f zephyr-ota.bin
137+
```
138+
139+
- Provision the Linux OTA Provider using chip-tool
140+
141+
```
142+
./chip-tool pairing onnetwork ${OTA_PROVIDER_NODE_ID} 20202021
143+
```
144+
145+
here:
146+
147+
- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
148+
149+
- Configure the ACL of the ota-provider-app to allow access
150+
151+
```
152+
./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": null, "targets": null}]' ${OTA_PROVIDER_NODE_ID} 0
153+
```
154+
155+
here:
156+
157+
- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
158+
159+
- Use the chip-tool to announce the ota-provider-app to start the OTA process
160+
161+
```
162+
./chip-tool otasoftwareupdaterequestor announce-otaprovider ${OTA_PROVIDER_NODE_ID} 0 0 0 ${DEVICE_NODE_ID} 0
163+
```
164+
165+
here:
166+
167+
- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
168+
- \${DEVICE_NODE_ID} is the node id of paired device
169+
170+
Once the transfer is complete, OTA requestor sends ApplyUpdateRequest command to
171+
OTA provider for applying the image. Device will restart on successful
172+
application of OTA image.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
// ---- Air Quality Example App Config ----
22+
23+
#define APP_USE_EXAMPLE_START_BUTTON 1
24+
#define APP_USE_BLE_START_BUTTON 0
25+
#define APP_USE_THREAD_START_BUTTON 0
26+
#define APP_SET_DEVICE_INFO_PROVIDER 1
27+
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
28+
#define APP_USE_IDENTIFY_PWM 1

0 commit comments

Comments
 (0)