esp-matter: General changes and fixes

Some of these are changes corresponding to the spec or to the documentation.
zigbee_bridge: Renamed bridge_zigbee to zigbee_bridge.
switch: Changed console commands to: matter esp bound/client invoke.
This commit is contained in:
Chirag Atal
2022-05-20 14:07:59 +05:30
committed by Shu Chen
parent ab1d30a2cb
commit 937bbd81fe
27 changed files with 89 additions and 61 deletions
+5 -5
View File
@@ -17,12 +17,12 @@ variables:
- git clone --recursive --single-branch -b v4.4.1 --reference-if-able /local_references/github/ https://github.com/espressif/esp-idf.git
- cd esp-idf
- ./install.sh
- . export.sh
- . ./export.sh
.setup_idf_v5_0: &setup_idf_v5_0
# - cd $REPOS_PATH # IDF_PATH is set to something else already?
# using commit 047903c612 of espressif/esp-idf github repo
# idf_v5_0 is used for bridge_zigbee_example and examples of ESP32-H2
# idf_v5_0 is used for zigbee_bridge example and examples of ESP32-H2
- git clone --recursive --reference-if-able /local_references/github/ https://github.com/espressif/esp-idf.git
- cd esp-idf
- git checkout 047903c612e2c7212693c0861966bf7c83430ebf
@@ -32,8 +32,8 @@ variables:
.setup_matter: &setup_matter
- cd $ESP_MATTER_PATH
- source connectedhomeip/connectedhomeip/scripts/bootstrap.sh
- . export.sh
- ./install.sh
- . ./export.sh
.build_matter_examples: &build_matter_examples
- export MATTER_EXAMPLES_PATH=$ESP_MATTER_PATH/connectedhomeip/connectedhomeip/examples
@@ -91,7 +91,7 @@ variables:
- cd $ESP_MATTER_PATH/examples/light
- idf.py --preview set-target esp32h2
- idf.py build
- cd $ESP_MATTER_PATH/examples/bridge_zigbee
- cd $ESP_MATTER_PATH/examples/zigbee_bridge
- idf.py set-target esp32
- idf.py build
@@ -61,6 +61,10 @@ esp_err_t connect(int fabric_index, int node_id, int remote_endpoint_id)
{
/* Get info */
FabricInfo *fabric_info = chip::Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabric_index);
if (!fabric_info) {
ESP_LOGE(TAG, "Couldn't find fabric info");
return ESP_FAIL;
}
PeerId peer_id = fabric_info->GetPeerIdForNode(node_id);
/* Find existing */
+2 -2
View File
@@ -68,7 +68,7 @@ for it to work. Check the example's "Additional Environment Setup" section for m
RainMaker Light <examples/rainmaker_light>
Switch <examples/switch>
Zap Light <examples/zap_light>
ZigBee Bridge <examples/bridge_zigbee>
ZigBee Bridge <examples/zigbee_bridge>
2.1.5 Flashing the Firmware
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -181,7 +181,7 @@ for it to work. Check the example's "Post Commissioning Setup" section for more
RainMaker Light <examples/rainmaker_light>
Switch <examples/switch>
Zap Light <examples/zap_light>
ZigBee Bridge <examples/bridge_zigbee>
ZigBee Bridge <examples/zigbee_bridge>
2.2.1.4 Cluster Control
+6 -6
View File
@@ -44,25 +44,25 @@ Switch specific console commands:
::
matter esp client send_to_binded <endpoint_id> <cluster_id> <command_id>
matter esp bound invoke <endpoint_id> <cluster_id> <command_id>
- Example: Off:
::
matter esp client send_to_binded 0x1 0x6 0x0
matter esp bound invoke 0x1 0x6 0x0
- Example: On:
::
matter esp client send_to_binded 0x1 0x6 0x1
matter esp bound invoke 0x1 0x6 0x1
- Example: Toggle:
::
matter esp client send_to_binded 0x1 0x6 0x2
matter esp bound invoke 0x1 0x6 0x2
3. Device Performance
---------------------
@@ -118,8 +118,8 @@ I cannot send commands to the light from my switch:
- Make sure the binding command was a success.
- Make sure you are passing the local endpoint_id, and not the remote
endpoint_id, to the cluster_update() API.
- If using device console, make sure you are running the ``send_to_binded``
command and not the ``send`` command. The send command is for devices
- If using device console, make sure you are running the ``bound invoke``
command and not the ``client invoke`` command. The client commands are for devices
which have not been binded.
- If you are still facing issues, reproduce the issue on the default
example for the device and then raise an `issue <https://github.com/espressif/esp-matter/issues>`. Make sure
+1 -1
View File
@@ -150,4 +150,4 @@ The LED on my devkit is not working:
RainMaker Light <examples/rainmaker_light>
Switch <examples/switch>
Zap Light <examples/zap_light>
ZigBee Bridge <examples/bridge_zigbee>
ZigBee Bridge <examples/zigbee_bridge>
+1 -1
View File
@@ -1,5 +1,5 @@
if(CONFIG_ZB_ENABLED)
set(srcs app_bridge_zigbee_device.cpp)
set(srcs app_zigbee_bridge_device.cpp)
endif()
idf_component_register(SRCS "${srcs}"
@@ -16,22 +16,22 @@
#include <esp_matter.h>
#include <string.h>
#include <app_bridge_zigbee_device.h>
#include <app_zigbee_bridge_device.h>
using esp_matter::node_t;
static const char *TAG = "esp_matter_bridge_zigbee";
static app_bridge_zigbee_device_t *device_list = NULL;
static const char *TAG = "esp_matter_zigbee_bridge";
static app_zigbee_bridge_device_t *device_list = NULL;
static uint8_t current_bridged_device_count = 0;
app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_t zigbee_endpointid,
app_zigbee_bridge_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_t zigbee_endpointid,
uint16_t zigbee_shortaddr)
{
if (current_bridged_device_count >= MAX_BRIDGED_DEVICE_COUNT) {
ESP_LOGE(TAG, "The device list is full, Could not add a zigbee bridged device");
return NULL;
}
app_bridge_zigbee_device_t *new_dev = (app_bridge_zigbee_device_t *)calloc(1, sizeof(app_bridge_zigbee_device_t));
app_zigbee_bridge_device_t *new_dev = (app_zigbee_bridge_device_t *)calloc(1, sizeof(app_zigbee_bridge_device_t));
new_dev->dev = esp_matter_bridge_create_device(node);
if (!(new_dev->dev)) {
ESP_LOGE(TAG, "Failed to create the basic bridged device");
@@ -48,7 +48,7 @@ app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_
uint16_t app_bridge_get_zigbee_shortaddr_by_matter_endpointid(int matter_endpointid)
{
app_bridge_zigbee_device_t *current_dev = device_list;
app_zigbee_bridge_device_t *current_dev = device_list;
while (current_dev) {
if (current_dev->dev && (current_dev->dev->endpoint_id == matter_endpointid)) {
return current_dev->zigbee_shortaddr;
@@ -60,7 +60,7 @@ uint16_t app_bridge_get_zigbee_shortaddr_by_matter_endpointid(int matter_endpoin
int app_bridge_get_matter_endpointid_by_zigbee_shortaddr(uint16_t zigbee_shortaddr)
{
app_bridge_zigbee_device_t *current_dev = device_list;
app_zigbee_bridge_device_t *current_dev = device_list;
while (current_dev) {
if (current_dev->zigbee_shortaddr == zigbee_shortaddr && current_dev->dev) {
return current_dev->dev->endpoint_id;
@@ -70,9 +70,9 @@ int app_bridge_get_matter_endpointid_by_zigbee_shortaddr(uint16_t zigbee_shortad
return -1;
}
app_bridge_zigbee_device_t *app_bridge_get_zigbee_device_by_matter_endpointid(int matter_endpointid)
app_zigbee_bridge_device_t *app_bridge_get_zigbee_device_by_matter_endpointid(int matter_endpointid)
{
app_bridge_zigbee_device_t *current_dev = device_list;
app_zigbee_bridge_device_t *current_dev = device_list;
while (current_dev) {
if (current_dev->dev && (current_dev->dev->endpoint_id == matter_endpointid)) {
return current_dev;
@@ -82,9 +82,9 @@ app_bridge_zigbee_device_t *app_bridge_get_zigbee_device_by_matter_endpointid(in
return NULL;
}
app_bridge_zigbee_device_t *app_bridge_get_zigbee_device_by_zigbee_shortaddr(uint16_t zigbee_shortaddr)
app_zigbee_bridge_device_t *app_bridge_get_zigbee_device_by_zigbee_shortaddr(uint16_t zigbee_shortaddr)
{
app_bridge_zigbee_device_t *current_dev = device_list;
app_zigbee_bridge_device_t *current_dev = device_list;
while (current_dev) {
if (current_dev->zigbee_shortaddr == zigbee_shortaddr && current_dev->dev) {
return current_dev;
@@ -94,10 +94,10 @@ app_bridge_zigbee_device_t *app_bridge_get_zigbee_device_by_zigbee_shortaddr(uin
return NULL;
}
esp_err_t app_bridge_remove_zigbee_device(app_bridge_zigbee_device_t *bridged_device)
esp_err_t app_bridge_remove_zigbee_device(app_zigbee_bridge_device_t *bridged_device)
{
esp_err_t error = ESP_OK;
app_bridge_zigbee_device_t *current_dev = NULL;
app_zigbee_bridge_device_t *current_dev = NULL;
if (!bridged_device) {
return ESP_ERR_INVALID_ARG;
}
@@ -19,23 +19,23 @@
using esp_matter::node_t;
typedef struct app_bridge_zigbee_device {
typedef struct app_zigbee_bridge_device {
esp_matter_bridge_device_t *dev;
uint8_t zigbee_endpointid;
uint16_t zigbee_shortaddr;
struct app_bridge_zigbee_device *next;
} app_bridge_zigbee_device_t;
struct app_zigbee_bridge_device *next;
} app_zigbee_bridge_device_t;
app_bridge_zigbee_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_t zigbee_endpointid,
app_zigbee_bridge_device_t *app_bridge_create_zigbee_device(node_t *node, uint8_t zigbee_endpointid,
uint16_t zigbee_shortaddr);
uint16_t app_bridge_get_zigbee_shortaddr_by_matter_endpointid(int matter_endpointid);
int app_bridge_get_matter_endpointid_by_zigbee_shortaddr(uint16_t zigbee_shortaddr);
app_bridge_zigbee_device_t *app_bridge_get_zigbee_device_by_matter_endpointid(int matter_endpointid);
app_zigbee_bridge_device_t *app_bridge_get_zigbee_device_by_matter_endpointid(int matter_endpointid);
app_bridge_zigbee_device_t *app_bridge_get_zigbee_device_by_zigbee_shortaddr(uint16_t zigbee_shortaddr);
app_zigbee_bridge_device_t *app_bridge_get_zigbee_device_by_zigbee_shortaddr(uint16_t zigbee_shortaddr);
esp_err_t app_bridge_remove_zigbee_device(app_bridge_zigbee_device_t *bridged_device);
esp_err_t app_bridge_remove_zigbee_device(app_zigbee_bridge_device_t *bridged_device);
#endif
+4 -4
View File
@@ -34,7 +34,7 @@ note:
After the binding is successful you can send the following command to control light from switch
```
> matter esp client send_to_binded <endpoint_id> <cluster_id> <command_id>
> matter esp bound invoke <endpoint_id> <cluster_id> <command_id>
```
here, endpoint_id, cluster_id, command_id of switch must be given in hex format
@@ -43,17 +43,17 @@ e.g.
- Power Off command
```
> matter esp client send_to_binded 0x0001 0x0006 0x0000
> matter esp bound invoke 0x0001 0x0006 0x0000
```
- Power On command
```
> matter esp client send_to_binded 0x0001 0x0006 0x0001
> matter esp bound invoke 0x0001 0x0006 0x0001
```
- Toggle command
```
> matter esp client send_to_binded 0x0001 0x0006 0x0002
> matter esp bound invoke 0x0001 0x0006 0x0002
```
+38 -14
View File
@@ -29,16 +29,14 @@ extern int switch_endpoint_id;
static int g_cluster_id = kInvalidClusterId;
static int g_command_id = kInvalidCommandId;
static esp_err_t app_driver_console_handler(int argc, char **argv)
static esp_err_t app_driver_bound_console_handler(int argc, char **argv)
{
if (argc == 1 && strncmp(argv[0], "help", sizeof("help")) == 0) {
printf("Driver commands:\n"
printf("Bound commands:\n"
"\thelp: Print help\n"
"\tsend_to_binded: <endpoint_id> <cluster_id> <command_id>. "
"Example: matter esp client send_to_binded 0x0001 0x0006 0x0002.\n"
"\tsend: <fabric_index> <remote_node_id> <remote_endpoint_id> <cluster_id> <command_id>. "
"Example: matter esp client send 0x0001 0xBC5C01 0x0001 0x0006 0x0002.\n");
} else if (argc == 4 && strncmp(argv[0], "send_to_binded", sizeof("send_to_binded")) == 0) {
"\tinvoke: <endpoint_id> <cluster_id> <command_id>. "
"Example: matter esp bound invoke 0x0001 0x0006 0x0002.\n");
} else if (argc == 4 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) {
int endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
int cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
int command_id = strtol((const char *)&argv[3][2], NULL, 16);
@@ -46,7 +44,21 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
g_cluster_id = cluster_id;
g_command_id = command_id;
client::cluster_update(endpoint_id, cluster_id);
} else if (argc == 6 && strncmp(argv[0], "send", sizeof("send")) == 0) {
} else {
ESP_LOGE(TAG, "Incorrect arguments. Check help for more details.");
return ESP_ERR_INVALID_ARG;
}
return ESP_OK;
}
static esp_err_t app_driver_client_console_handler(int argc, char **argv)
{
if (argc == 1 && strncmp(argv[0], "help", sizeof("help")) == 0) {
printf("Client commands:\n"
"\thelp: Print help\n"
"\tinvoke: <fabric_index> <remote_node_id> <remote_endpoint_id> <cluster_id> <command_id>. "
"Example: matter esp client invoke 0x0001 0xBC5C01 0x0001 0x0006 0x0002.\n");
} else if (argc == 6 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) {
int fabric_index = strtol((const char *)&argv[1][2], NULL, 16);
int node_id = strtol((const char *)&argv[2][2], NULL, 16);
int remote_endpoint_id = strtol((const char *)&argv[3][2], NULL, 16);
@@ -65,13 +77,25 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
static void app_driver_register_commands()
{
esp_matter_console_command_t command = {
.name = "client",
.description = "This can be used to simulate on-device control. Usage: matter esp client <driver_command>. "
"Driver commands: help, send, send_to_binded",
.handler = app_driver_console_handler,
/* Add console command for bound devices */
esp_matter_console_command_t bound_command = {
.name = "bound",
.description = "This can be used to simulate on-device control for bound devices."
"Usage: matter esp bound <bound_command>. "
"Bound commands: help, invoke",
.handler = app_driver_bound_console_handler,
};
esp_matter_console_add_command(&command);
esp_matter_console_add_command(&bound_command);
/* Add console command for client to control non-bound devices */
esp_matter_console_command_t client_command = {
.name = "client",
.description = "This can be used to simulate on-device control for client devices."
"Usage: matter esp client <client_command>. "
"Client commands: help, invoke",
.handler = app_driver_client_console_handler,
};
esp_matter_console_add_command(&client_command);
}
void app_driver_client_command_callback(client::peer_device_t *peer_device, int remote_endpoint_id, void *priv_data)
@@ -36,7 +36,7 @@ set(EXTRA_COMPONENT_DIRS
"${ESP_MATTER_PATH}/device_hal/device"
${extra_components_dirs_append})
project(bridge_zigbee)
project(zigbee_bridge)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H;-fpermissive" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)
@@ -15,7 +15,7 @@
#include <esp_matter_ota.h>
#include <esp_route_hook.h>
#include <app_bridge_zigbee_device.h>
#include <app_zigbee_bridge_device.h>
#include <app_qrcode.h>
#include <app_zboss.h>
@@ -111,7 +111,7 @@ void zboss_signal_handler(zb_bufid_t bufid)
void zboss_task()
{
ZB_INIT("bridge zigbee");
ZB_INIT("zigbee bridge");
zb_set_network_coordinator_role(IEEE_CHANNEL_MASK);
zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG);
zb_set_max_children(MAX_CHILDREN);
@@ -12,7 +12,7 @@
#include <esp_log.h>
#include <esp_matter.h>
#include <app_bridge_zigbee_device.h>
#include <app_zigbee_bridge_device.h>
#include <app_zboss.h>
#include <esp_matter_core.h>
#include <zboss_api_buf.h>
@@ -56,7 +56,7 @@ void zigbee_bridge_match_bridged_onoff_light_cb(zb_bufid_t bufid)
ESP_LOGI(TAG, "Bridged node for 0x%04x zigbee device on endpoint %d has been created", p_ind->src_addr,
app_bridge_get_matter_endpointid_by_zigbee_shortaddr(p_ind->src_addr));
} else {
app_bridge_zigbee_device_t *dev = app_bridge_create_zigbee_device(node, *p_match_ep, p_ind->src_addr);
app_zigbee_bridge_device_t *dev = app_bridge_create_zigbee_device(node, *p_match_ep, p_ind->src_addr);
ESP_GOTO_ON_FALSE(dev, ESP_FAIL, exit, TAG, "Failed to create zigbee bridged device (on_off light)");
ESP_GOTO_ON_ERROR(init_bridged_onoff_light(dev->dev), exit, TAG, "Failed to initialize the bridged node");
ESP_LOGI(TAG, "Create/Update bridged node for 0x%04x zigbee device on endpoint %d", p_ind->src_addr,
@@ -106,7 +106,7 @@ void zigbee_bridge_match_bridged_onoff_light_timeout(zb_bufid_t bufid)
void zigbee_bridge_send_on(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr)
{
app_bridge_zigbee_device_t *dev = app_bridge_get_zigbee_device_by_zigbee_shortaddr(zigbee_shortaddr);
app_zigbee_bridge_device_t *dev = app_bridge_get_zigbee_device_by_zigbee_shortaddr(zigbee_shortaddr);
ZB_ZCL_ON_OFF_SEND_REQ(buf, zigbee_shortaddr, ZB_APS_ADDR_MODE_16_ENDP_PRESENT, dev->zigbee_endpointid,
dev->dev->endpoint_id, ZB_AF_HA_PROFILE_ID, ZB_ZCL_DISABLE_DEFAULT_RESPONSE,
ZB_ZCL_CMD_ON_OFF_ON_ID, NULL);
@@ -114,7 +114,7 @@ void zigbee_bridge_send_on(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr)
void zigbee_bridge_send_off(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr)
{
app_bridge_zigbee_device_t *dev = app_bridge_get_zigbee_device_by_zigbee_shortaddr(zigbee_shortaddr);
app_zigbee_bridge_device_t *dev = app_bridge_get_zigbee_device_by_zigbee_shortaddr(zigbee_shortaddr);
ZB_ZCL_ON_OFF_SEND_REQ(buf, zigbee_shortaddr, ZB_APS_ADDR_MODE_16_ENDP_PRESENT, dev->zigbee_endpointid,
dev->dev->endpoint_id, ZB_AF_HA_PROFILE_ID, ZB_ZCL_DISABLE_DEFAULT_RESPONSE,
ZB_ZCL_CMD_ON_OFF_OFF_ID, NULL);
@@ -122,7 +122,7 @@ void zigbee_bridge_send_off(zb_uint8_t buf, zb_uint16_t zigbee_shortaddr)
esp_err_t zigbee_bridge_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t *val)
{
app_bridge_zigbee_device_t *zigbee_device = app_bridge_get_zigbee_device_by_matter_endpointid(endpoint_id);
app_zigbee_bridge_device_t *zigbee_device = app_bridge_get_zigbee_device_by_matter_endpointid(endpoint_id);
if (zigbee_device && zigbee_device->dev && zigbee_device->dev->endpoint) {
if (cluster_id == OnOff::Id) {
if (attribute_id == OnOff::Attributes::OnOff::Id) {