Skip to content

Commit

Permalink
[Ameba] Implement light-switch-app, matter shell and add binding to a…
Browse files Browse the repository at this point in the history
…pps (#21153)

* [Bind] Add binding cluster to ameba all-clusters-app
- Implement ameba matter shell
- Add BindingHandler

* [Switch] Implement ameba light-switch-app
- Also removed unnecessary macros from chip_main.cmake of all the apps

* [README] Update README for Ameba examples
- all-clusters-app
- lighting-app
- light-switch-app
- ota-requestor-app

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Restyled by prettier-markdown

* [Build] Fix compile error
- Compile BindingHandler even when matter_enable_shell is disabled

* [README] Fix mispelled word

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 24, 2024
1 parent 3b038f7 commit 34c7249
Show file tree
Hide file tree
Showing 32 changed files with 2,545 additions and 108 deletions.
10 changes: 8 additions & 2 deletions config/ameba/chip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,24 @@ string(APPEND CHIP_GN_ARGS "pw_build_LINK_DEPS = [\"//third_party/connectedhomei
string(APPEND CHIP_GN_ARGS "pw_rpc_CONFIG = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc:disable_global_mutex\"")
endif (matter_enable_rpc)

# Build Matter Shell
if (matter_enable_shell)
string(APPEND CHIP_GN_ARGS "chip_build_libshell = true\n")
endif (matter_enable_shell)

# Build ota-requestor
if (matter_enable_ota_requestor)
string(APPEND CHIP_GN_ARGS "chip_enable_ota_requestor = true\n")
endif (matter_enable_ota_requestor)

# Rotating ID
if (matter_enable_rotating_id)
string(APPEND CHIP_GN_ARGS "chip_enable_additional_data_advertising = true\n")
string(APPEND CHIP_GN_ARGS "chip_enable_rotating_device_id = true\n")
else(matter_enable_rotating_id)
else (matter_enable_rotating_id)
string(APPEND CHIP_GN_ARGS "chip_enable_additional_data_advertising = false\n")
string(APPEND CHIP_GN_ARGS "chip_enable_rotating_device_id = false\n")
endif(matter_enable_rotating_id)
endif (matter_enable_rotating_id)

file(GENERATE OUTPUT ${CHIP_OUTPUT}/args.gn CONTENT ${CHIP_GN_ARGS})

Expand Down
111 changes: 57 additions & 54 deletions examples/all-clusters-app/ameba/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ control.
- [CHIP Ameba All Clusters Example](#chip-ameba-all-clusters-example)
- [Supported Device](#supported-device)
- [Building the Example Application](#building-the-example-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Commissioning](#commissioning)
- [BLE mode](#ble-mode)
- [IP mode](#ip-mode)
- [Cluster control](#cluster-control)
- [Commissioning](#commissioning)
- [BLE mode](#ble-mode)
- [IP mode](#ip-mode)
- [Cluster control](#cluster-control)
- [Running RPC Console](#running-rpc-console)
- [Running Matter Shell](#running-matter-shell)
- [Binding and Controlling a Lighting Device](#binding-and-controlling-a-lighting-device)

---

Expand All @@ -26,27 +27,19 @@ The CHIP demo application is supported on

- Pull docker image:

```
$ docker pull connectedhomeip/chip-build-ameba:latest
```

- Run docker container:

```
$ docker run -it -v ${CHIP_DIR}:/root/chip connectedhomeip/chip-build-ameba:latest
```

- Setup build environment:

```
$ source ./scripts/bootstrap.sh
```

- To build the demo application:

```
$ ./scripts/build/build_examples.py --target ameba-amebad-all-clusters build
```

The output image files are stored in
`out/ameba-amebad-all-clusters/asdk/image` folder.
Expand All @@ -63,43 +56,25 @@ The CHIP demo application is supported on
the correct locations
4. Click **Download** button.

## Commissioning and Cluster Control

## Commissioning

There are two commissioning modes supported by Ameba platform:

### BLE mode

1. In "connectedhomeip/config/ameba/args.gni"

- Set `chip_config_network_layer_ble = true`

2. In `connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h`

- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1`

3. Build and Flash
4. The all-clusters example will run automatically after booting the Ameba
1. Build and Flash
2. The all-clusters example will run automatically after booting the Ameba
board.
5. Test with
3. Test with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)

### IP mode

1. In `connectedhomeip/config/ameba/args.gni`

- Set `chip_config_network_layer_ble = false`

2. In `connectedhomeip/src/platform/Ameba/CHIPDevicePlatformConfig.h`

- Set `#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0`

3. Build and Flash
4. The all-clusters example will run automatically after booting the Ameba
1. Build and Flash
2. The all-clusters example will run automatically after booting the Ameba
board.
5. Connect to AP using `ATW0, ATW1, ATWC` commands
6. Test with
3. Connect to AP using `ATW0, ATW1, ATWC` commands
4. Test with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)

## Cluster Control
Expand All @@ -111,43 +86,71 @@ to be On or Off.
- Via
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool#using-the-client-to-send-matter-commands)

```
$ ./chip-tool onoff on ${NODE_ID_TO_ASSIGN} 1
$ ./chip-tool onoff off ${NODE_ID_TO_ASSIGN} 1
```
$ ./chip-tool onoff on <nodeID> 1
$ ./chip-tool onoff off <nodeID> 1

## Running RPC Console

- Connect a USB-TTL Adapter as shown below
- Connect a USB-TTL adapter as shown below

```
Ameba USB-TTL
A19 TX
A18 RX
GND GND
```

- Build the
* Build the
[chip-rpc console](https://github.com/project-chip/connectedhomeip/tree/master/examples/common/pigweed/rpc_console)

- As part of building the example with RPCs enabled the chip_rpc python
* As part of building the example with RPCs enabled the chip_rpc python
interactive console is installed into your venv. The python wheel files are
also created in the output folder: out/debug/chip_rpc_console_wheels. To
install the wheel files without rebuilding:

```
$ pip3 install out/debug/chip_rpc_console_wheels/*.whl
```

- Launch the chip-rpc console after resetting Ameba board

```
$ chip-console --device /dev/tty<port connected to USB-TTL adapter> -b 115200
```

- Get and Set lighting directly using the RPC console
* Get and Set lighting directly using the RPC console

```python
python
rpcs.chip.rpc.Lighting.Get()
rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5))
```

## Running Matter Shell

- Matter Shell is enabled whenever RPC is disabled.

- RPC console and Matter Shell cannot be enabled at the same time as they use
the same UART port.

- Connect Ameba to the USB-TTL adapter as shown in the RPC section.

- Open the USB-TTL serial port and type `help` to view the available commands

## Binding and Controlling a Lighting Device

- This example shows how to bind a Switch Device to a Lighting Device and
control it through the Matter Shell. One binding client (Switch Device) and
one binding server (Lighting Device) is required.

- Commission the switch (nodeID 1) and lighting device (nodeID 2) using
chip-tool.

$ ./chip-tool pairing ble-wifi 1 <SSID> <PASSWORD> 20202021 3840
$ ./chip-tool pairing ble-wifi 2 <SSID> <PASSWORD> 20202021 3840

* After successful commissioning, configure the ACL in the lighting device to
allow access from switch device and chip-tool.

$ ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null },{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [1], "targets": null }]' 2 0

- Bind the lighting device to the switch device.

$ ./chip-tool binding write binding '[{"fabricIndex": 1, "node":2, "endpoint":1, "cluster":6}]' 1 1

- Control the lighting device through the switch device's Matter Shell

> switch onoff on
> switch onoff off
19 changes: 17 additions & 2 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ list(
)
endif (matter_enable_rpc)

if (matter_enable_shell)
list(
APPEND ${list_chip_main_sources}
#shell
${chip_dir}/examples/platform/ameba/shell/launch_shell.cpp
)
endif (matter_enable_shell)

if (matter_enable_ota_requestor)
list(
APPEND ${list_chip_main_sources}
Expand All @@ -148,6 +156,7 @@ list(
${chip_dir}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp

${chip_dir}/examples/all-clusters-app/ameba/main/chipinterface.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/BindingHandler.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp
${chip_dir}/examples/all-clusters-app/ameba/main/Globals.cpp
Expand Down Expand Up @@ -242,9 +251,7 @@ list(
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
-DCHIP_HAVE_CONFIG_H
-DCHIP_SUPPORT_ENABLE_STORAGE_API_AUDIT
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
-DMATTER_ALL_CLUSTERS_APP=1
)

if (matter_enable_persistentstorage_audit)
Expand All @@ -269,6 +276,14 @@ list(
)
endif (matter_enable_rpc)

if (matter_enable_shell)
list(
APPEND chip_main_flags

-DCONFIG_ENABLE_CHIP_SHELL=1
)
endif (matter_enable_shell)

list(
APPEND chip_main_cpp_flags

Expand Down
Loading

0 comments on commit 34c7249

Please sign in to comment.