ambiot / ambz2_matter

amebaZ2 public SDK to support Matter project
https://www.amebaiot.com/en/
13 stars 13 forks source link

Matter (previously CHIP) on AmebaZ2

How to support Matter on Ameba SDK

https://github.com/ambiot/ambz2_matter/blob/main/CHANGELOG.md

Get Ameba SDK & Matter SDK

Tested on Ubuntu 20.04 and above

Create and enter new directory

mkdir dev
cd dev

To check out AmebaZ2 repository:

git clone --recurse-submodules https://github.com/ambiot/ambz2_matter.git

To check out Matter repository:

git clone --recurse-submodules https://github.com/project-chip/connectedhomeip

Make sure ambz2_matter and connectedhomeip are on the same directory level

dev/
├── ambz2_matter
└── connectedhomeip

Set Matter Build Environment

> Find more details to setup linux build environment
> https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/BUILDING.md

cd connectedhomeip

source scripts/bootstrap.sh

source scripts/activate.sh

Make CHIP library by gn and Make lib_main.a

all-clusters-app

cd ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE

make all_clusters

lighting-app

cd ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE

make light

switch-app

cd ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE

make switch

ota-requestor-app

cd ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE

make otar

CHIP core (generated by GN/ninja in connectedhomeip. Configured by lib_chip.mk)

output : ambz2_matter/component/soc/realtek/8710c/misc/bsp/lib/common/GCC

> libCHIP.a

CHIP application (generated and configured by lib_chip_main.mk))

output : ambz2_matter/component/soc/realtek/8710c/misc/bsp/lib/common/GCC

> lib_main.a

Make Ameba Matter application

cd ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE

make is_matter

Clean Ameba Matter libraries

make clean_matter_libs

Clean Ameba Matter application

make clean_matter

Enable BLE Mesh with Matter

To use BLE Mesh with Matter, uncomment the following in platform_opts_bt.h

BT_MATTER_MESH_ADAPTER = 1

Flash Image

The generated image is found in ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE/application_is/Debug/bin/flash_is.bin

Method 1:

Method 2 (using image tool and flashing script):

Run CHIP task on AmebaZ2 (all-cluster-app/lighting-app/ota-requestor-app example)

Matter task will auto start after reset the device.

Test with chip-tool

Use standalone chip-tool app(linux) to communicate with the device.

In order to send commands to a device, the device must be commissioned into the Matter network. The configuration state for chip-tool is stored in /tmp/chip_tool_config.ini; deleting this and other .ini files in /tmp can sometimes resolve issues due to stale configuration.

Commission a device over BLE-WiFi

Commission a device over IP (For devices already on the WiFi network)

Command for onoff cluster

Use PA_20 as output, connect a LED to this pin and GND.

Find more detail in chip-tool

Test with Android Chip-Tool

Install Android Studio

Preparing for build

Run the following commands

cd connectedhomeip/
source script/bootstrap.sh
export ANDROID_HOME=~/Android/Sdk
export ANDROID_NDK_HOME={path to android-ndk-r21e}

Target CPU TARGET_CPU can have the following values, depending on your smartphone CPU architecture:

ABI TARGET_CPU
armeabi-v7a arm
arm64-v8a arm64
x86 x86
x86_64 x64

Complete the following steps to prepare the Matter build:

  1. Check out the Matter repository.

  2. Run bootstrap (only required first time)

    source scripts/bootstrap.sh
  3. Choose how you want to build the Android CHIPTool. There are two ways: from script, or from source within Android Studio.

Building Android CHIPTool from scripts

This is the simplest option. In the command line, run the following command from the top CHIP directory:

./scripts/build/build_examples.py --target android-arm64-chip-tool build

Note: It has been noticed that this step may fail on the first try, but running the second time will successfully build the apk.

See the table above for other values of TARGET_CPU.

The debug Android package app-debug.apk will be generated at out/android-$TARGET_CPU-chip-tool/outputs/apk/debug/, and can be installed with

adb install out/android-$TARGET_CPU-chip-tool/outputs/apk/debug/app-debug.apk

You can use Android Studio to edit the Android CHIPTool app itself and run it after build_examples.py, but you will not be able to edit Matter Android code from src/controller/java, or other Matter C++ code within Android Studio.

Building Android CHIPTool from Android Studio

This option allows Android Studio to build the core Matter code from source, which allows us to directly edit core Matter code in-IDE.

  1. In the command line, run the following command from the top Matter directory:

    TARGET_CPU=arm64 ./scripts/examples/android_app_ide.sh

    See the table above for other values of TARGET_CPU.

  2. Modify the matterSdkSourceBuild variable to true, matterBuildSrcDir point to the appropriate output directory (e.g. ../../../../out/android_arm64), and matterSourceBuildAbiFilters to the desired ABIs in src/android/CHIPTool/gradle.properties

3) Open the project in Android Studio and run Sync Project with Gradle Files.

4) Use one of the following options to build an Android package:

- Click **Make Project** in Android Studio.
- Run the following command in the command line:

    ```shell
    cd src/android/CHIPTool
    ./gradlew build
    ```

The debug Android package app-debug.apk will be generated at src/android/CHIPTool/app/build/outputs/apk/debug/, and can be installed with

adb install src/android/CHIPTool/app/build/outputs/apk/debug/app-debug.apk

or

(cd src/android/CHIPTool && ./gradlew installDebug)

BLE Commissioning

Note: The QR code will be provided when booting, for example:

chip[SVR] SetupQRCode: [MT:-24J042C00KA0648G00]
chip[SVR] Copy/paste the below URL in a browser to see the QR Code:
chip[SVR] https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00

Copy/paste the URL in a browser and a scannable QR code will be displayed.