Matter application development by Beken

[中文]

Below is an overall view of Beken Matter’s solution

beken matter support

Beken Matter Solution

Basic introduction to bk_matter repo

You can configure CONFIG_MATTER_EXAMPLE in the configuration file projects/matter/config/common.config to compile the specified Matter device type. Such as Lighting, Plug, etc.

The source code of the relevant example can be found at components/matter/connectedhomeip/examples/$(CONFIG_MATTER_EXAMPLE)/beken and can be customized for development.

In bk_matter, the Matter core is included as a component in components/matter ; The standard Matter SDK is in components/matter/connectedhomeip .

The only places you need to care about in the Matter SDK are as follows:

  • examples/{CONFIG_MATTER_EXAMPLE}/beken Demos of some applications implemented by beken

  • src/platform/Beken contains Beken’s adaptation of Matter, including the implementation of interfaces such as ble, wifi, kv storage, and so on.

  • examples/platform/beken are some generic api’s for the beken implementation of the matter application.

When compiling matter in armino, you first need to enable the matter component (CONFIG_SUPPORT_MATTER=y), and when compiling, armino will call components/matter/CMakeLists.txt, which in turn will call components/matter/libCHIP.mk script that compiles the gn project in the directory components/matter/connectedhomeip/examples/{MATTER_EXAMPLE}/beken and generates the file libMatter.a. The function ChipTest is included to initialize and start the matter-related processes.

Matter Lighting example

Below are the supported device types for Lighting’s children, it is usually recommended to develop Extended Color Light (0x010D), which contains the most comprehensive cluster.

  • On/Off Light(0x0100)

  • Dimmable Light(0x0101)

  • Color Temperature Light(0x010C)

  • Extended Color Light(0x010D)

Device Information and Restoring Factory Devices

  • Device power-up: when a device that is not networked is powered up, it will start the Matter service and automatically broadcast BLE (it will stop after 15 minutes by default.) For a device that is already networked, the device will not broadcast BLE when it is powered up, but it will automatically connect to a saved router and broadcast its own Matter service within that network.

  • Printing device information: Users can view basic information about a device onbording by typing matter_show into the serial CLI. the following example can be typed into a browser at website view Scanning QR Code.

matter_show
chip[DL] Device Configuration:
chip[DL] Serial Number: BK000001
chip[DL] Vendor ID: 65521 (0xfff1)
chip[DL] Product ID: 32773 (0x8005)
chip[DL] Setup Passcode: 20202021
chip[DL] Setup Discriminator: 3840 (0x0f00)
chip[SVR] SetupQRCode: [MT:6FCJ142C00KA0648G00]
chip[SVR] Copy/paste the below URL in a browser to see the QR Code:
chip[SVR] https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A6FCJ142C00KA0648G00
chip[SVR] Manual pairing code: [34970112332]
  • Restore factory settings: If the device has already been paired, users can enter matter_factory_reset on the CLI to erase the pairing information, and the device will reboot and restore the pairing status automatically.

matter_factory_reset

Pair Test

There’s a lesson to be learned here:

  1. chip-tool

  2. Apple/Google/Amazon

secondary development

If a customer wants to develop a Matter light bulb, they can modify the existing application and only need to adapt the hardware parts related to their product in the following file.

Of course, it is also possible to start development of a completely new device based on the Developing a new device type for Matter from scratch .

on command

matter OnCommand

The callback function is set at matter initialization with the function PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb)); . After the controller sends the OnCommand, in the OnOffCluster implementation, Matter will call the relevant functions according to the above flow, and finally to the PostAttributeChangeCallback function in the code below, calling line 33. Operate the device to perform the relevant action.

DeviceCallbacks.cpp
 1void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
 2                                                     uint8_t type, uint16_t size, uint8_t * value)
 3{
 4    ChipLogProgress(DeviceLayer, "[%s] cluster ID: " ChipLogFormatMEI, TAG, ChipLogValueMEI(clusterId));
 5    switch (clusterId)
 6    {
 7    case Clusters::OnOff::Id:
 8        OnOnOffPostAttributeChangeCallback(endpointId, attributeId, value);
 9        break;
10
11    case Clusters::LevelControl::Id:
12        OnLevelControlAttributeChangeCallback(endpointId, attributeId, value);
13        break;
14
15    case Clusters::ColorControl::Id:
16        OnColorControlAttributeChangeCallback(endpointId, attributeId, value);
17        break;
18
19    default:
20        ChipLogProgress(Zcl, "Unknown cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));
21        break;
22    }
23}
24
25void AppDeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value)
26{
27    VerifyOrExit(attributeId == Clusters::OnOff::Attributes::OnOff::Id,
28                 ChipLogError(DeviceLayer, "[%s] Unhandled Attribute ID: '0x%04lx", TAG, attributeId));
29    VerifyOrExit(endpointId == 1 || endpointId == 2,
30                 ChipLogError(DeviceLayer, "[%s] Unexpected EndPoint ID: `0x%02x'", TAG, endpointId));
31
32    // At this point we can assume that value points to a bool value.
33    BkLightingMgr().SetOnOff(*value);
34
35exit:
36    return;
37}

Matter Controller example

Matter Controller usually serves as the Matter hub and is used to implement paired Matter devices. The Beken implementation Controller can support compilation and running on bk7235, bk7256, and bk7258. The following are some commonly used cli, used for pairing control and other operations.

  • Commissioning into a Wi-Fi network over Bluetooth LE

matter pair ble-wifi <pairing-code>
  • control OnOff

matter onoff <node-id> <1/0>
  • control level

matter setlevel <node-id> <level-value>
  • show fabric information

matter fabric
  • list devices

matter listdevices