mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-05 16:32:34 +00:00
feat(zigbee): Upgrade the Zigbee lib to v1.6 for Zigbee examples
- Optimize the Zigbee light, switch and gateway examples - Remove the esp_zigbee_rcp example
This commit is contained in:
@@ -34,24 +34,28 @@ 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:
|
||||
|
||||
```
|
||||
I (394) main_task: Calling app_main()
|
||||
I (404) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
|
||||
I (404) phy_init: phy_version 220,2dbbbe7,Sep 25 2023,20:39:25
|
||||
I (464) phy: libbtbb version: 90c587c, Sep 25 2023, 20:39:57
|
||||
I (474) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL
|
||||
I (474) ESP_ZB_COLOR_DIMM_LIGHT: Zigbee stack initialized
|
||||
I (484) ESP_ZB_COLOR_DIMM_LIGHT: Start network steering
|
||||
I (484) main_task: Returned from app_main()
|
||||
I (9614) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
|
||||
I (9834) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
|
||||
I (9834) ESP_ZB_COLOR_DIMM_LIGHT: Joined network successfully (Extended PAN ID: 60:55:f9:00:00:f6:07:b4, PAN ID: 0x2a74, Channel:13)
|
||||
I (32944) ESP_ZB_COLOR_DIMM_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (32944) ESP_ZB_COLOR_DIMM_LIGHT: Light sets to On
|
||||
I (33984) ESP_ZB_COLOR_DIMM_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (33984) ESP_ZB_COLOR_DIMM_LIGHT: Light sets to Off
|
||||
I (35304) ESP_ZB_COLOR_DIMM_LIGHT: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
|
||||
I (35534) ESP_ZB_COLOR_DIMM_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (35534) ESP_ZB_COLOR_DIMM_LIGHT: Light sets to On
|
||||
I (403) app_start: Starting scheduler on CPU0
|
||||
I (408) main_task: Started on CPU0
|
||||
I (408) main_task: Calling app_main()
|
||||
I (428) phy: phy_version: 230,2, 9aae6ea, Jan 15 2024, 11:17:12
|
||||
I (428) phy: libbtbb version: 944f18e, Jan 15 2024, 11:17:25
|
||||
I (438) main_task: Returned from app_main()
|
||||
I (548) ESP_ZB_ON_OFF_LIGHT: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL
|
||||
I (548) ESP_ZB_ON_OFF_LIGHT: Initialize Zigbee stack
|
||||
W (548) rmt: channel resolution loss, real=10666666
|
||||
I (558) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
|
||||
I (548) ESP_ZB_ON_OFF_LIGHT: Deferred driver initialization successful
|
||||
I (568) ESP_ZB_ON_OFF_LIGHT: Device started up in factory-reset mode
|
||||
I (578) ESP_ZB_ON_OFF_LIGHT: Start network steering
|
||||
I (3558) ESP_ZB_ON_OFF_LIGHT: Joined network successfully (Extended PAN ID: 74:4d:bd:ff:fe:63:f7:30, PAN ID: 0x13af, Channel:13, Short Address: 0x7c16)
|
||||
I (10238) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (10238) ESP_ZB_ON_OFF_LIGHT: Light sets to On
|
||||
I (10798) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (10798) ESP_ZB_ON_OFF_LIGHT: Light sets to Off
|
||||
I (11228) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (11228) ESP_ZB_ON_OFF_LIGHT: Light sets to On
|
||||
I (11618) ESP_ZB_ON_OFF_LIGHT: Received message: endpoint(10), cluster(0x6), attribute(0x0), data size(1)
|
||||
I (11618) ESP_ZB_ON_OFF_LIGHT: Light sets to Off
|
||||
```
|
||||
|
||||
## Light Control Functions
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS
|
||||
"esp_zb_light.c"
|
||||
"light_driver.c"
|
||||
INCLUDE_DIRS "."
|
||||
SRC_DIRS "." "../../../common/zcl_utility/src"
|
||||
INCLUDE_DIRS "." "../../../common/zcl_utility/include"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
* SPDX-License-Identifier: LicenseRef-Included
|
||||
*
|
||||
* Zigbee HA_on_off_light Example
|
||||
*
|
||||
@@ -11,7 +11,6 @@
|
||||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_check.h"
|
||||
@@ -26,9 +25,15 @@
|
||||
|
||||
static const char *TAG = "ESP_ZB_ON_OFF_LIGHT";
|
||||
/********************* Define functions **************************/
|
||||
static esp_err_t deferred_driver_init(void)
|
||||
{
|
||||
light_driver_init(LIGHT_DEFAULT_OFF);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask));
|
||||
ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee commissioning");
|
||||
}
|
||||
|
||||
void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
|
||||
@@ -38,12 +43,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
|
||||
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_LOGI(TAG, "Initialize Zigbee stack");
|
||||
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION);
|
||||
break;
|
||||
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
|
||||
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
|
||||
if (err_status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful");
|
||||
ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non");
|
||||
if (esp_zb_bdb_is_factory_new()) {
|
||||
ESP_LOGI(TAG, "Start network steering");
|
||||
@@ -119,11 +125,17 @@ static void esp_zb_task(void *pvParameters)
|
||||
esp_zb_init(&zb_nwk_cfg);
|
||||
esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG();
|
||||
esp_zb_ep_list_t *esp_zb_on_off_light_ep = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg);
|
||||
zcl_basic_manufacturer_info_t info = {
|
||||
.manufacturer_name = ESP_MANUFACTURER_NAME,
|
||||
.model_identifier = ESP_MODEL_IDENTIFIER,
|
||||
};
|
||||
|
||||
esp_zcl_utility_add_ep_basic_manufacturer_info(esp_zb_on_off_light_ep, HA_ESP_LIGHT_ENDPOINT, &info);
|
||||
esp_zb_device_register(esp_zb_on_off_light_ep);
|
||||
esp_zb_core_action_handler_register(zb_action_handler);
|
||||
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
|
||||
ESP_ERROR_CHECK(esp_zb_start(false));
|
||||
esp_zb_main_loop_iteration();
|
||||
esp_zb_stack_main_loop();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
@@ -134,6 +146,5 @@ void app_main(void)
|
||||
};
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
|
||||
light_driver_init(LIGHT_DEFAULT_OFF);
|
||||
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
* SPDX-License-Identifier: LicenseRef-Included
|
||||
*
|
||||
* Zigbee HA_on_off_light Example
|
||||
*
|
||||
@@ -14,13 +14,18 @@
|
||||
|
||||
#include "esp_zigbee_core.h"
|
||||
#include "light_driver.h"
|
||||
#include "zcl_utility.h"
|
||||
|
||||
/* Zigbee configuration */
|
||||
#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
|
||||
#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_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */
|
||||
#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
|
||||
#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN /* aging timeout of device */
|
||||
#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_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */
|
||||
|
||||
/* Basic manufacturer information */
|
||||
#define ESP_MANUFACTURER_NAME "\x09""ESPRESSIF" /* Customized manufacturer name */
|
||||
#define ESP_MODEL_IDENTIFIER "\x07"CONFIG_IDF_TARGET /* Customized model identifier */
|
||||
|
||||
#define ESP_ZB_ZED_CONFIG() \
|
||||
{ \
|
||||
@@ -34,10 +39,10 @@
|
||||
|
||||
#define ESP_ZB_DEFAULT_RADIO_CONFIG() \
|
||||
{ \
|
||||
.radio_mode = RADIO_MODE_NATIVE, \
|
||||
.radio_mode = ZB_RADIO_MODE_NATIVE, \
|
||||
}
|
||||
|
||||
#define ESP_ZB_DEFAULT_HOST_CONFIG() \
|
||||
{ \
|
||||
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
|
||||
.host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, \
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
espressif/esp-zboss-lib: "1.0.9"
|
||||
espressif/esp-zigbee-lib: "1.0.9"
|
||||
espressif/esp-zboss-lib: "~1.6.0"
|
||||
espressif/esp-zigbee-lib: "~1.6.0"
|
||||
espressif/led_strip: "~2.0.0"
|
||||
## Required IDF version
|
||||
idf:
|
||||
|
||||
@@ -34,31 +34,34 @@ 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:
|
||||
|
||||
```
|
||||
I (388) main_task: Calling app_main()
|
||||
I (398) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
|
||||
I (398) phy_init: phy_version 220,2dbbbe7,Sep 25 2023,20:39:25
|
||||
I (478) phy: libbtbb version: 90c587c, Sep 25 2023, 20:39:57
|
||||
I (488) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL
|
||||
I (488) ESP_ZB_ON_OFF_SWITCH: Zigbee stack initialized
|
||||
I (488) ESP_ZB_ON_OFF_SWITCH: Start network formation
|
||||
I (498) main_task: Returned from app_main()
|
||||
I (998) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
|
||||
I (998) ESP_ZB_ON_OFF_SWITCH: Formed network successfully (Extended PAN ID: 60:55:f9:00:00:f6:07:b4, PAN ID: 0x2a74, Channel:13)
|
||||
I (1468) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
|
||||
I (1468) ESP_ZB_ON_OFF_SWITCH: Network steering started
|
||||
I (14228) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Device Associated (0x12), status: ESP_OK
|
||||
I (14728) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Update (0x30), status: ESP_OK
|
||||
I (14788) ESP_ZB_ON_OFF_SWITCH: New device commissioned or rejoined (short: 0xe399)
|
||||
I (14858) ESP_ZB_ON_OFF_SWITCH: Found light
|
||||
I (14858) ESP_ZB_ON_OFF_SWITCH: Try to bind On/Off
|
||||
I (14858) ESP_ZB_ON_OFF_SWITCH: Bound successfully!
|
||||
I (14858) ESP_ZB_ON_OFF_SWITCH: The light originating from address(0xe399) on endpoint(10)
|
||||
I (15338) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
|
||||
I (15408) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Permit Join (0x36), status: ESP_OK
|
||||
I (35838) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NLME Status Indication (0x32), status: ESP_OK
|
||||
I (38548) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
I (39598) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
I (41148) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
I (441) main_task: Started on CPU0
|
||||
I (441) main_task: Calling app_main()
|
||||
I (461) phy: phy_version: 230,2, 9aae6ea, Jan 15 2024, 11:17:12
|
||||
I (461) phy: libbtbb version: 944f18e, Jan 15 2024, 11:17:25
|
||||
I (471) main_task: Returned from app_main()
|
||||
I (601) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL
|
||||
I (601) ESP_ZB_ON_OFF_SWITCH: Initialize Zigbee stack
|
||||
I (611) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
|
||||
I (611) ESP_ZB_ON_OFF_SWITCH: Deferred driver initialization successful
|
||||
I (621) ESP_ZB_ON_OFF_SWITCH: Device started up in factory-reset mode
|
||||
I (621) ESP_ZB_ON_OFF_SWITCH: Start network formation
|
||||
W (781) ESP_ZB_ON_OFF_SWITCH: Network(0x13af) closed, devices joining not allowed.
|
||||
I (781) ESP_ZB_ON_OFF_SWITCH: Formed network successfully (Extended PAN ID: 74:4d:bd:ff:fe:63:f7:30, PAN ID: 0x13af, Channel:13, Short Address: 0x0000)
|
||||
I (1391) ESP_ZB_ON_OFF_SWITCH: Network(0x13af) is open for 180 seconds
|
||||
I (1391) ESP_ZB_ON_OFF_SWITCH: Network steering started
|
||||
I (9561) ESP_ZB_ON_OFF_SWITCH: ZDO signal: NWK Device Associated (0x12), status: ESP_OK
|
||||
I (9561) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Update (0x30), status: ESP_OK
|
||||
I (9601) ESP_ZB_ON_OFF_SWITCH: New device commissioned or rejoined (short: 0x7c16)
|
||||
I (9671) ESP_ZB_ON_OFF_SWITCH: Found light
|
||||
I (9671) ESP_ZB_ON_OFF_SWITCH: Try to bind On/Off
|
||||
I (9681) ESP_ZB_ON_OFF_SWITCH: Bound successfully!
|
||||
I (9681) ESP_ZB_ON_OFF_SWITCH: The light originating from address(0x7c16) on endpoint(10)
|
||||
I (9751) ESP_ZB_ON_OFF_SWITCH: ZDO signal: ZDO Device Authorized (0x2f), status: ESP_OK
|
||||
I (9781) ESP_ZB_ON_OFF_SWITCH: Network(0x13af) is open for 180 seconds
|
||||
I (16451) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
I (17011) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
I (17441) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
I (17831) ESP_ZB_ON_OFF_SWITCH: Send 'on_off toggle' command
|
||||
```
|
||||
|
||||
## Light Control Functions
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS
|
||||
"esp_zb_switch.c"
|
||||
"switch_driver.c"
|
||||
INCLUDE_DIRS "."
|
||||
SRC_DIRS "." "../../../common/zcl_utility/src"
|
||||
INCLUDE_DIRS "." "../../../common/zcl_utility/include"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
* SPDX-License-Identifier: LicenseRef-Included
|
||||
*
|
||||
* Zigbee HA_on_off_switch Example
|
||||
*
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "string.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "ha/esp_zigbee_ha_standard.h"
|
||||
@@ -35,7 +37,7 @@ static switch_func_pair_t button_func_pair[] = {
|
||||
|
||||
static const char *TAG = "ESP_ZB_ON_OFF_SWITCH";
|
||||
|
||||
static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair)
|
||||
static void zb_buttons_handler(switch_func_pair_t *button_func_pair)
|
||||
{
|
||||
if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
|
||||
/* implemented light switch toggle functionality */
|
||||
@@ -43,14 +45,23 @@ static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair)
|
||||
cmd_req.zcl_basic_cmd.src_endpoint = HA_ONOFF_SWITCH_ENDPOINT;
|
||||
cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
|
||||
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_lock_acquire(portMAX_DELAY);
|
||||
esp_zb_zcl_on_off_cmd_req(&cmd_req);
|
||||
esp_zb_lock_release();
|
||||
ESP_EARLY_LOGI(TAG, "Send 'on_off toggle' command");
|
||||
}
|
||||
}
|
||||
|
||||
static esp_err_t deferred_driver_init(void)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG,
|
||||
"Failed to initialize switch driver");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask));
|
||||
ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, , TAG, "Failed to start Zigbee bdb commissioning");
|
||||
}
|
||||
|
||||
static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx)
|
||||
@@ -94,17 +105,19 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
|
||||
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_LOGI(TAG, "Initialize Zigbee stack");
|
||||
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION);
|
||||
break;
|
||||
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
|
||||
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
|
||||
if (err_status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful");
|
||||
ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non");
|
||||
if (esp_zb_bdb_is_factory_new()) {
|
||||
ESP_LOGI(TAG, "Start network formation");
|
||||
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION);
|
||||
} else {
|
||||
esp_zb_bdb_open_network(180);
|
||||
ESP_LOGI(TAG, "Device rebooted");
|
||||
}
|
||||
} else {
|
||||
@@ -161,10 +174,16 @@ static void esp_zb_task(void *pvParameters)
|
||||
esp_zb_init(&zb_nwk_cfg);
|
||||
esp_zb_on_off_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_ON_OFF_SWITCH_CONFIG();
|
||||
esp_zb_ep_list_t *esp_zb_on_off_switch_ep = esp_zb_on_off_switch_ep_create(HA_ONOFF_SWITCH_ENDPOINT, &switch_cfg);
|
||||
zcl_basic_manufacturer_info_t info = {
|
||||
.manufacturer_name = ESP_MANUFACTURER_NAME,
|
||||
.model_identifier = ESP_MODEL_IDENTIFIER,
|
||||
};
|
||||
|
||||
esp_zcl_utility_add_ep_basic_manufacturer_info(esp_zb_on_off_switch_ep, HA_ONOFF_SWITCH_ENDPOINT, &info);
|
||||
esp_zb_device_register(esp_zb_on_off_switch_ep);
|
||||
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
|
||||
ESP_ERROR_CHECK(esp_zb_start(false));
|
||||
esp_zb_main_loop_iteration();
|
||||
esp_zb_stack_main_loop();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
@@ -175,6 +194,6 @@ void app_main(void)
|
||||
};
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
|
||||
switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_zb_buttons_handler);
|
||||
|
||||
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
* SPDX-License-Identifier: LicenseRef-Included
|
||||
*
|
||||
* Zigbee HA_on_off_switch Example
|
||||
*
|
||||
@@ -13,12 +13,17 @@
|
||||
*/
|
||||
#include "esp_zigbee_core.h"
|
||||
#include "switch_driver.h"
|
||||
#include "zcl_utility.h"
|
||||
|
||||
/* Zigbee configuration */
|
||||
#define MAX_CHILDREN 10 /* the max amount of connected devices */
|
||||
#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
|
||||
#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */
|
||||
#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */
|
||||
#define MAX_CHILDREN 10 /* the max amount of connected devices */
|
||||
#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
|
||||
#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */
|
||||
#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */
|
||||
|
||||
/* Basic manufacturer information */
|
||||
#define ESP_MANUFACTURER_NAME "\x09""ESPRESSIF" /* Customized manufacturer name */
|
||||
#define ESP_MODEL_IDENTIFIER "\x07"CONFIG_IDF_TARGET /* Customized model identifier */
|
||||
|
||||
#define ESP_ZB_ZC_CONFIG() \
|
||||
{ \
|
||||
@@ -31,10 +36,10 @@
|
||||
|
||||
#define ESP_ZB_DEFAULT_RADIO_CONFIG() \
|
||||
{ \
|
||||
.radio_mode = RADIO_MODE_NATIVE, \
|
||||
.radio_mode = ZB_RADIO_MODE_NATIVE, \
|
||||
}
|
||||
|
||||
#define ESP_ZB_DEFAULT_HOST_CONFIG() \
|
||||
{ \
|
||||
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
|
||||
.host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, \
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
espressif/esp-zboss-lib: "1.0.9"
|
||||
espressif/esp-zigbee-lib: "1.0.9"
|
||||
espressif/esp-zboss-lib: "~1.6.0"
|
||||
espressif/esp-zigbee-lib: "~1.6.0"
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: ">=5.0.0"
|
||||
|
||||
@@ -67,7 +67,7 @@ static void IRAM_ATTR gpio_isr_handler(void *arg)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable GPIO (switchs refer to) isr
|
||||
* @brief Enable GPIO (switches refer to) isr
|
||||
*
|
||||
* @param enabled enable isr if true.
|
||||
*/
|
||||
@@ -159,7 +159,7 @@ static bool switch_driver_gpio_init(switch_func_pair_t *button_func_pair, uint8_
|
||||
return false;
|
||||
}
|
||||
/* start gpio task */
|
||||
xTaskCreate(switch_driver_button_detected, "button_detected", 2048, NULL, 10, NULL);
|
||||
xTaskCreate(switch_driver_button_detected, "button_detected", 4096, NULL, 10, NULL);
|
||||
/* install gpio isr service */
|
||||
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
|
||||
for (int i = 0; i < button_num; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user