zigbee: support esp32h2

* new set Zigbee channel API/ get Zigbee channel add
* add esp32h2 build rule for zigbee example
This commit is contained in:
likunqiao 2023-03-20 17:04:37 +08:00
parent 288332d6a9
commit 05a72ecb2d
10 changed files with 26 additions and 19 deletions

View File

@ -8,10 +8,10 @@ examples/zigbee/esp_zigbee_gateway:
examples/zigbee/esp_zigbee_rcp:
enable:
- if: IDF_TARGET in ["esp32h4", "esp32c6"]
reason: should able to run on esp32h4 and esp32c6
- if: IDF_TARGET in ["esp32h4", "esp32c6", "esp32h2"]
reason: should able to run on esp32h4 esp32h2 and esp32c6
examples/zigbee/light_sample:
enable:
- if: IDF_TARGET in ["esp32h4", "esp32c6"]
reason: should able to run on esp32h4 and esp32c6
- if: IDF_TARGET in ["esp32h4", "esp32c6", "esp32h2"]
reason: should able to run on esp32h4 esp32h2 and esp32c6

View File

@ -83,10 +83,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
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)",
ESP_LOGI(TAG, "Formed network successfully (ieee_address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d)",
ieee_address[7], ieee_address[6], ieee_address[5], ieee_address[4],
ieee_address[3], ieee_address[2], ieee_address[1], ieee_address[0],
esp_zb_get_pan_id());
esp_zb_get_pan_id(), esp_zb_get_current_channel());
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
} else {
ESP_LOGI(TAG, "Restart network formation (status: %d)", err_status);
@ -114,6 +114,7 @@ static void esp_zb_task(void *pvParameters)
esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG();
esp_zb_init(&zb_nwk_cfg);
/* initiate Zigbee Stack start without zb_send_no_autostart_signal auto-start */
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_ERROR_CHECK(esp_zb_start(false));
esp_zb_main_loop_iteration();
}

View File

@ -40,7 +40,8 @@
/* 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 INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 13) /* Zigbee primary channel mask use in the example */
#define ESP_ZB_ZC_CONFIG() \
{ \

View File

@ -1,5 +1,5 @@
| Supported Targets | ESP32-C6 | ESP32-H4 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-H4 |
| ----------------- | -------- | -------- | -------- |
# Rcp Example

View File

@ -1,5 +1,5 @@
| Supported Targets | ESP32-C6 | ESP32-H4 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-H4 |
| ----------------- | -------- | -------- | -------- |
# Light Bulb Example

View File

@ -59,7 +59,7 @@ 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 == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
uint8_t value = *(uint8_t*)new_value;
uint8_t value = *(uint8_t *)new_value;
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);
@ -87,17 +87,18 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
ESP_LOGI(TAG, "Start 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)", err_status);
/* commissioning failed */
ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %d)", err_status);
}
break;
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)",
ESP_LOGI(TAG, "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d)",
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_get_pan_id(), esp_zb_get_current_channel());
} else {
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);
@ -119,6 +120,7 @@ static void esp_zb_task(void *pvParameters)
esp_zb_ep_list_t *esp_zb_on_off_light_ep = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg);
esp_zb_device_register(esp_zb_on_off_light_ep);
esp_zb_device_add_set_attr_value_cb(attr_cb);
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_ERROR_CHECK(esp_zb_start(false));
esp_zb_main_loop_iteration();
}

View File

@ -43,6 +43,7 @@
#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 (1l << 13) /* Zigbee primary channel mask use in the example */
#define ESP_ZB_ZED_CONFIG() \
{ \

View File

@ -1,5 +1,5 @@
| Supported Targets | ESP32-C6 | ESP32-H4 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-H4 |
| ----------------- | -------- | -------- | -------- |
# Light Switch Example

View File

@ -124,10 +124,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
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)",
ESP_LOGI(TAG, "Formed network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d)",
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_get_pan_id(), esp_zb_get_current_channel());
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
} else {
ESP_LOGI(TAG, "Restart network formation (status: %d)", err_status);
@ -162,6 +162,7 @@ static void esp_zb_task(void *pvParameters)
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);
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();
}

View File

@ -41,6 +41,7 @@
#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 ESP_ZB_ZC_CONFIG() \
{ \