mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
zigbee: update Zigbee example signal handler API
* update API for new esp-zigbee-lib * enable ci test
This commit is contained in:
parent
c9b77bc662
commit
b699d8fd6b
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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() \
|
||||
{ \
|
||||
|
@ -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"
|
||||
|
@ -1,3 +1,4 @@
|
||||
CONFIG_IDF_TARGET="esp32h4"
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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() \
|
||||
|
@ -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:
|
||||
|
@ -1,3 +1,4 @@
|
||||
CONFIG_IDF_TARGET="esp32h4"
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -1,3 +1,4 @@
|
||||
CONFIG_IDF_TARGET="esp32h4"
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user