From b699d8fd6b14304b4f14465d0885c9e59bae135e Mon Sep 17 00:00:00 2001 From: likunqiao Date: Wed, 26 Oct 2022 14:40:02 +0800 Subject: [PATCH] zigbee: update Zigbee example signal handler API * update API for new esp-zigbee-lib * enable ci test --- examples/zigbee/.build-test-rules.yml | 10 --- examples/zigbee/esp_zigbee_gateway/README.md | 14 ++-- .../main/esp_zigbee_gateway.c | 60 ++++++++--------- .../esp_zigbee_gateway/main/idf_component.yml | 4 +- .../esp_zigbee_rcp/main/esp_zigbee_rcp.c | 35 +++------- .../esp_zigbee_rcp/main/esp_zigbee_rcp.h | 2 +- .../esp_zigbee_rcp/main/idf_component.yml | 3 +- .../zigbee/esp_zigbee_rcp/sdkconfig.defaults | 1 + .../light_sample/HA_on_off_light/README.md | 2 + .../HA_on_off_light/main/esp_zb_light.c | 50 ++++++--------- .../HA_on_off_light/main/esp_zb_light.h | 4 +- .../HA_on_off_light/main/idf_component.yml | 4 +- .../HA_on_off_light/sdkconfig.defaults | 1 + .../light_sample/HA_on_off_switch/README.md | 3 +- .../HA_on_off_switch/main/esp_zb_switch.c | 64 ++++++++----------- .../HA_on_off_switch/main/idf_component.yml | 4 +- .../HA_on_off_switch/sdkconfig.defaults | 1 + 17 files changed, 112 insertions(+), 150 deletions(-) diff --git a/examples/zigbee/.build-test-rules.yml b/examples/zigbee/.build-test-rules.yml index f6934ba117..f173546a72 100644 --- a/examples/zigbee/.build-test-rules.yml +++ b/examples/zigbee/.build-test-rules.yml @@ -10,18 +10,8 @@ examples/zigbee/esp_zigbee_rcp: enable: - if: IDF_TARGET == "esp32h4" reason: should able to run on esp32h4 - disable: - - if: IDF_TARGET == "esp32h4" - temporary: true - # TODO: rename esp32h2 to esp32h4 [IDF-6101] - reason: waiting for esp32h2 in the managed component be renamed to esp32h4 examples/zigbee/light_sample: enable: - if: IDF_TARGET == "esp32h4" reason: should able to run on esp32h4 - disable: - - if: IDF_TARGET == "esp32h4" - temporary: true - # TODO: rename esp32h2 to esp32h4 [IDF-6101] - reason: waiting for esp32h2 in the managed component be renamed to esp32h4 diff --git a/examples/zigbee/esp_zigbee_gateway/README.md b/examples/zigbee/esp_zigbee_gateway/README.md index 75285d2584..9f15b9d28e 100644 --- a/examples/zigbee/esp_zigbee_gateway/README.md +++ b/examples/zigbee/esp_zigbee_gateway/README.md @@ -43,13 +43,13 @@ As you run the example, you will see the following log: esp_zigbee_gateway: ``` -I (660) ESP_ZB_GATEWAY: status: -1 -I (670) ESP_ZB_GATEWAY: Zigbee stack initialized -I (680) ESP_ZB_GATEWAY: Zigbee rcp device booted -I (1280) ESP_ZB_GATEWAY: Start network formation -I (3060) ESP_ZB_GATEWAY: Formed network successfully (ieee extended address: f9:54:2d:01:a0:03:f7:84, PAN ID: 0x8651) -I (4060) ESP_ZB_GATEWAY: status: 0 -I (4400) ESP_ZB_GATEWAY: Network steering started +I (660) ESP_ZB_GATEWAY: status: -1 +I (670) ESP_ZB_GATEWAY: Zigbee stack initialized +I (680) ESP_ZB_GATEWAY: Zigbee rcp device booted +I (1280) ESP_ZB_GATEWAY: Start network formation +I (3060) ESP_ZB_GATEWAY: Formed network successfully (ieee extended address: f9:54:2d:01:a0:03:f7:84, PAN ID: 0x8651) +I (4060) ESP_ZB_GATEWAY: status: 0 +I (4400) ESP_ZB_GATEWAY: Network steering started ``` ## Gateway Functions diff --git a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c index 57f337812f..b1c7d4a318 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c +++ b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c @@ -52,64 +52,60 @@ static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); } -void zboss_signal_handler(uint8_t bufid) +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { - zb_zdo_app_signal_hdr_t *p_sg_p = NULL; - zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, &p_sg_p); - zb_ret_t status = ZB_GET_APP_SIGNAL_STATUS(bufid); - zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; - zb_zdo_signal_macsplit_dev_boot_params_t *rcp_version = NULL; + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = *p_sg_p; + esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; + esp_zb_zdo_signal_macsplit_dev_boot_params_t *rcp_version = NULL; - switch (sig) { - case ZB_ZDO_SIGNAL_SKIP_STARTUP: + switch (sig_type) { + case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: ESP_LOGI(TAG, "Zigbee stack initialized"); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); break; - case ZB_MACSPLIT_DEVICE_BOOT: + case ESP_ZB_MACSPLIT_DEVICE_BOOT: ESP_LOGI(TAG, "Zigbee rcp device booted"); - rcp_version = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_macsplit_dev_boot_params_t); + rcp_version = (esp_zb_zdo_signal_macsplit_dev_boot_params_t*)esp_zb_app_signal_get_params(p_sg_p); ESP_LOGI(TAG, "Running RCP Version:%s", rcp_version->version_str); break; - case ZB_BDB_SIGNAL_DEVICE_FIRST_START: - case ZB_BDB_SIGNAL_DEVICE_REBOOT: - if (status == RET_OK) { + case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: + case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: + if (err_status == ESP_OK) { ESP_LOGI(TAG, "Start network formation"); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_FORMATION); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", status); + ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", err_status); } break; - case ZB_BDB_SIGNAL_FORMATION: - if (status == RET_OK) { - zb_ieee_addr_t ieee_address; + case ESP_ZB_BDB_SIGNAL_FORMATION: + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t ieee_address; esp_zb_get_long_address(ieee_address); ESP_LOGI(TAG, "Formed network successfully (ieee extended address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx)", ieee_address[7], ieee_address[6], ieee_address[5], ieee_address[4], ieee_address[3], ieee_address[2], ieee_address[1], ieee_address[0], - ZB_PIBCACHE_PAN_ID()); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING); + esp_zb_get_pan_id()); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); } else { - ESP_LOGI(TAG, "Restart network formation (status: %d)", status); - ZB_SCHEDULE_APP_ALARM((zb_callback_t)bdb_start_top_level_commissioning_cb, ZB_BDB_NETWORK_FORMATION, ZB_TIME_ONE_SECOND); + ESP_LOGI(TAG, "Restart network formation (status: %d)", err_status); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_FORMATION, 1000); } break; - case ZB_BDB_SIGNAL_STEERING: - if (status == RET_OK) { + case ESP_ZB_BDB_SIGNAL_STEERING: + if (err_status == ESP_OK) { ESP_LOGI(TAG, "Network steering started"); } break; - case ZB_ZDO_SIGNAL_DEVICE_ANNCE: - dev_annce_params = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_device_annce_params_t); + case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE: + dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t *)esp_zb_app_signal_get_params(p_sg_p); ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr); break; default: - ESP_LOGI(TAG, "status: %d", status); + ESP_LOGI(TAG, "ZDO signal: %d, status: %d", sig_type, err_status); break; } - /* All callbacks should either reuse or free passed buffers. If bufid == 0, the buffer is invalid (not passed) */ - if (bufid) { - zb_buf_free(bufid); - } } static void esp_zb_task(void *pvParameters) diff --git a/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml b/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml index 9de7031828..8364ef9303 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml +++ b/examples/zigbee/esp_zigbee_gateway/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "~0.1.0" - espressif/esp-zigbee-lib: "~0.2.0" + espressif/esp-zboss-lib: "~0.2.0" + espressif/esp-zigbee-lib: "~0.3.0" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c b/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c index 132dfa817d..d17089ea39 100644 --- a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c +++ b/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.c @@ -46,38 +46,23 @@ #endif static const char *TAG = "ESP_ZB_RCP"; -void zboss_signal_handler(uint8_t bufid) +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { - zb_zdo_app_signal_hdr_t *sg_p = NULL; - /* get application signal from the buffer */ - zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, &sg_p); - - if (ZB_GET_APP_SIGNAL_STATUS(bufid) == 0) { - switch (sig) { - case ZB_COMMON_SIGNAL_CAN_SLEEP: -#if defined(ZB_USE_SLEEP) - zb_sleep_now(); -#endif - break; - default: break; - } - } else if (sig == ZB_ZDO_SIGNAL_PRODUCTION_CONFIG_READY) { + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = *p_sg_p; + if (err_status == ESP_OK) { + } else if (sig_type == ESP_ZB_ZDO_SIGNAL_PRODUCTION_CONFIG_READY) { ESP_LOGI(TAG, "Production config is not present or invalid"); } else { - ESP_LOGI(TAG, "Device started FAILED status %d", ZB_GET_APP_SIGNAL_STATUS(bufid)); - } - - if (bufid) { - zb_buf_free(bufid); + ESP_LOGI(TAG, "Device started FAILED status %d", err_status); } } -static void esp_zb_task(void * pvParameters) +static void esp_zb_task(void *pvParameters) { - ZB_INIT("esp_zigbee_rcp"); - while (1) { - zb_sched_loop_iteration(); - } + esp_zb_rcp_init(); + esp_zb_rcp_main_loop_iteration(); } void app_main(void) diff --git a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h b/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h index 78dda0f134..c59bd98d81 100644 --- a/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h +++ b/examples/zigbee/esp_zigbee_rcp/main/esp_zigbee_rcp.h @@ -34,7 +34,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "zboss_api.h" +#include "esp_zigbee_core.h" #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ { \ diff --git a/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml b/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml index b8568f3c4a..8364ef9303 100644 --- a/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml +++ b/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml @@ -1,6 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "~0.1.0" + espressif/esp-zboss-lib: "~0.2.0" + espressif/esp-zigbee-lib: "~0.3.0" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults b/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults index 693d709e85..45df78c118 100644 --- a/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults +++ b/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults @@ -1,3 +1,4 @@ +CONFIG_IDF_TARGET="esp32h4" # # Partition Table # diff --git a/examples/zigbee/light_sample/HA_on_off_light/README.md b/examples/zigbee/light_sample/HA_on_off_light/README.md index 05d4691e63..689eb0489d 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/README.md +++ b/examples/zigbee/light_sample/HA_on_off_light/README.md @@ -30,6 +30,7 @@ Build the project, flash it to the board, and start the monitor tool to view the As you run the example, you will see the following log: light bulb: +``` I (918) ESP_ZB_LIGHT: status: 255 I (901) ESP_ZB_LIGHT: Zigbee stack initialized I (901) ESP_ZB_LIGHT: Start network steering @@ -40,6 +41,7 @@ I (7331) ESP_ZB_LIGHT: on/off light set to 1 I (8251) ESP_ZB_LIGHT: on/off light set to 0 I (9111) ESP_ZB_LIGHT: on/off light set to 1 I (9671) ESP_ZB_LIGHT: on/off light set to 0 +``` ## Light Control Functions diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c index fdb44b4fb5..61474a9ed6 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c +++ b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.c @@ -38,7 +38,7 @@ #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "esp_zigbee_ha_standard.h" +#include "ha/esp_zigbee_ha_standard.h" #include "esp_zb_light.h" /** @@ -57,9 +57,9 @@ static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) void attr_cb(uint8_t status, uint8_t endpoint, uint16_t cluster_id, uint16_t attr_id, void *new_value) { - if (cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF) { + if (cluster_id == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) { uint8_t value = *(uint8_t*)new_value; - if (attr_id == ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID) { + if (attr_id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID) { /* implemented light on/off control */ ESP_LOGI(TAG, "on/off light set to %hd", value); light_driver_set_power((bool)value); @@ -70,50 +70,42 @@ void attr_cb(uint8_t status, uint8_t endpoint, uint16_t cluster_id, uint16_t att } } -/** - * @brief Zigbee stack event signal handler. - * - * @param bufid Zigbee stack buffer id used to pass signal. - */ -void zboss_signal_handler(uint8_t bufid) +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { - zb_uint8_t status = ZB_GET_APP_SIGNAL_STATUS(bufid); - zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, NULL); - - switch (sig) { - case ZB_ZDO_SIGNAL_SKIP_STARTUP: + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = *p_sg_p; + switch (sig_type) { + case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: ESP_LOGI(TAG, "Zigbee stack initialized"); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); break; - case ZB_BDB_SIGNAL_DEVICE_FIRST_START: - case ZB_BDB_SIGNAL_DEVICE_REBOOT: - if (status == RET_OK) { + case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: + case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: + if (err_status == ESP_OK) { ESP_LOGI(TAG, "Start network steering"); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", status); + ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", err_status); } break; - case ZB_BDB_SIGNAL_STEERING: - if (status == RET_OK) { - zb_ext_pan_id_t extended_pan_id; + case ESP_ZB_BDB_SIGNAL_STEERING: + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t extended_pan_id; esp_zb_get_extended_pan_id(extended_pan_id); ESP_LOGI(TAG, "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx)", extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], esp_zb_get_pan_id()); } else { - ESP_LOGI(TAG, "Network steering was not successful (status: %d)", status); - ZB_SCHEDULE_APP_ALARM((zb_callback_t)bdb_start_top_level_commissioning_cb, ZB_BDB_NETWORK_STEERING, ZB_TIME_ONE_SECOND); + ESP_LOGI(TAG, "Network steering was not successful (status: %d)", err_status); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000); } break; default: - ESP_LOGI(TAG, "status: %d", status); + ESP_LOGI(TAG, "ZDO signal: %d, status: %d", sig_type, err_status); break; } - if (bufid) { - zb_buf_free(bufid); - } } static void esp_zb_task(void *pvParameters) diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h index c1a3f5ab7d..82c3b2bc77 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h +++ b/examples/zigbee/light_sample/HA_on_off_light/main/esp_zb_light.h @@ -40,8 +40,8 @@ /* Zigbee configuration */ #define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ -#define ED_AGING_TIMEOUT ED_AGING_TIMEOUT_64MIN -#define ED_KEEP_ALIVE ZB_MILLISECONDS_TO_BEACON_INTERVAL(3000) +#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN +#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */ #define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */ #define ESP_ZB_ZED_CONFIG() \ diff --git a/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml b/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml index e581cb28cb..81adebd889 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml +++ b/examples/zigbee/light_sample/HA_on_off_light/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zigbee-lib: "~0.2.0" - espressif/esp-zboss-lib: "~0.1.0" + espressif/esp-zigbee-lib: "~0.3.0" + espressif/esp-zboss-lib: "~0.2.0" espressif/led_strip: "~2.0.0" ## Required IDF version idf: diff --git a/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults b/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults index bd6d5f604c..d0c6dc6308 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults +++ b/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults @@ -1,3 +1,4 @@ +CONFIG_IDF_TARGET="esp32h4" # # Partition Table # diff --git a/examples/zigbee/light_sample/HA_on_off_switch/README.md b/examples/zigbee/light_sample/HA_on_off_switch/README.md index 23696ea9f0..7a4f168460 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/README.md +++ b/examples/zigbee/light_sample/HA_on_off_switch/README.md @@ -30,6 +30,7 @@ Build the project, flash it to the board, and start the monitor tool to view the As you run the example, you will see the following log: light switch: +``` I (318) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2 I (328) system_api: Base MAC address is not set I (328) system_api: read default base MAC address from EFUSE @@ -52,7 +53,7 @@ I (9458) ESP_ZB_ON_OFF_SWITCH: send move to on_off toggle command I (10088) ESP_ZB_ON_OFF_SWITCH: send move to on_off toggle command I (10588) ESP_ZB_ON_OFF_SWITCH: send move to on_off toggle command I (11098) ESP_ZB_ON_OFF_SWITCH: send move to on_off toggle command - +``` ## Light Control Functions diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c index 26ecad681c..f8e398cfde 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.c @@ -38,7 +38,7 @@ #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "esp_zigbee_ha_standard.h" +#include "ha/esp_zigbee_ha_standard.h" #include "esp_zb_switch.h" /** @@ -79,7 +79,7 @@ static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) cmd_req.zcl_basic_cmd.dst_endpoint = on_off_light.endpoint; cmd_req.zcl_basic_cmd.src_endpoint = HA_ONOFF_SWITCH_ENDPOINT; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; - cmd_req.on_off_cmd_id = ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; + cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; ESP_EARLY_LOGI(TAG, "send 'on_off toggle' command"); esp_zb_zcl_on_off_cmd_req(&cmd_req); } @@ -93,71 +93,63 @@ static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) void user_find_cb(uint8_t zdo_status, uint16_t addr, uint8_t endpoint) { ESP_LOGI(TAG, "User find cb: address:0x%x, endpoint:%d, response_status:%d", addr, endpoint, zdo_status); - if (zdo_status == ZB_ZDP_STATUS_SUCCESS) { + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { on_off_light.endpoint = endpoint; on_off_light.short_addr = addr; } } -/** - * @brief Zigbee stack event signal handler. - * - * @param bufid Zigbee stack buffer id used to pass signal. - */ -void zboss_signal_handler(uint8_t bufid) +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { - zb_zdo_app_signal_hdr_t *p_sg_p = NULL; - zb_uint8_t status = ZB_GET_APP_SIGNAL_STATUS(bufid); - zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, &p_sg_p); - zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; - switch (sig) { - case ZB_ZDO_SIGNAL_SKIP_STARTUP: + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = *p_sg_p; + esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; + switch (sig_type) { + case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: ESP_LOGI(TAG, "Zigbee stack initialized"); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); break; - case ZB_BDB_SIGNAL_DEVICE_FIRST_START: - case ZB_BDB_SIGNAL_DEVICE_REBOOT: - if (status == RET_OK) { + case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: + case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: + if (err_status == ESP_OK) { ESP_LOGI(TAG, "Start network formation"); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_FORMATION); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", status); + ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", err_status); } break; - case ZB_BDB_SIGNAL_FORMATION: - if (status == RET_OK) { - zb_ext_pan_id_t extended_pan_id; + case ESP_ZB_BDB_SIGNAL_FORMATION: + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t extended_pan_id; esp_zb_get_extended_pan_id(extended_pan_id); ESP_LOGI(TAG, "Formed network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx)", extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], esp_zb_get_pan_id()); - esp_zb_bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); } else { - ESP_LOGI(TAG, "Restart network formation (status: %d)", status); - ZB_SCHEDULE_APP_ALARM((zb_callback_t)bdb_start_top_level_commissioning_cb, ZB_BDB_NETWORK_FORMATION, ZB_TIME_ONE_SECOND); + ESP_LOGI(TAG, "Restart network formation (status: %d)", err_status); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_FORMATION, 1000); } break; - case ZB_BDB_SIGNAL_STEERING: - if (status == RET_OK) { + case ESP_ZB_BDB_SIGNAL_STEERING: + if (err_status == ESP_OK) { ESP_LOGI(TAG, "Network steering started"); } break; - case ZB_ZDO_SIGNAL_DEVICE_ANNCE: - dev_annce_params = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_device_annce_params_t); + case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE: + dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t *)esp_zb_app_signal_get_params(p_sg_p); ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr); - esp_zb_zdo_match_desc_req_param_t cmd_req; + esp_zb_zdo_match_desc_req_param_t cmd_req; cmd_req.dst_nwk_addr = dev_annce_params->device_short_addr; cmd_req.addr_of_interest = dev_annce_params->device_short_addr; esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb); break; default: - ESP_LOGI(TAG, "status: %d", status); + ESP_LOGI(TAG, "ZDO signal: %d, status: %d", sig_type, err_status); break; } - if (bufid) { - zb_buf_free(bufid); - } } static void esp_zb_task(void *pvParameters) diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml b/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml index 4a83c46a9d..38f6767cf4 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zigbee-lib: "~0.2.0" - espressif/esp-zboss-lib: "~0.1.0" + espressif/esp-zigbee-lib: "~0.3.0" + espressif/esp-zboss-lib: "~0.2.0" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults b/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults index 84faf10eb9..aa37da8783 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults +++ b/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults @@ -1,3 +1,4 @@ +CONFIG_IDF_TARGET="esp32h4" # # Partition Table #