From 05a72ecb2d74816dcec87d48f4315d2d05d63483 Mon Sep 17 00:00:00 2001 From: likunqiao Date: Mon, 20 Mar 2023 17:04:37 +0800 Subject: [PATCH] zigbee: support esp32h2 * new set Zigbee channel API/ get Zigbee channel add * add esp32h2 build rule for zigbee example --- examples/zigbee/.build-test-rules.yml | 8 ++++---- .../esp_zigbee_gateway/main/esp_zigbee_gateway.c | 5 +++-- .../esp_zigbee_gateway/main/esp_zigbee_gateway.h | 3 ++- examples/zigbee/esp_zigbee_rcp/README.md | 4 ++-- examples/zigbee/light_sample/HA_on_off_light/README.md | 4 ++-- .../light_sample/HA_on_off_light/main/esp_zb_light.c | 10 ++++++---- .../light_sample/HA_on_off_light/main/esp_zb_light.h | 1 + .../zigbee/light_sample/HA_on_off_switch/README.md | 4 ++-- .../light_sample/HA_on_off_switch/main/esp_zb_switch.c | 5 +++-- .../light_sample/HA_on_off_switch/main/esp_zb_switch.h | 1 + 10 files changed, 26 insertions(+), 19 deletions(-) diff --git a/examples/zigbee/.build-test-rules.yml b/examples/zigbee/.build-test-rules.yml index f815e041c27d..b50f84619b64 100644 --- a/examples/zigbee/.build-test-rules.yml +++ b/examples/zigbee/.build-test-rules.yml @@ -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 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 a1b8bbe0774a..4f757ffcb2fb 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c +++ b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.c @@ -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(); } diff --git a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h index 4c22871a385a..46e4188a8c92 100644 --- a/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h +++ b/examples/zigbee/esp_zigbee_gateway/main/esp_zigbee_gateway.h @@ -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() \ { \ diff --git a/examples/zigbee/esp_zigbee_rcp/README.md b/examples/zigbee/esp_zigbee_rcp/README.md index 90ea0475fc3a..ba98d6d41084 100644 --- a/examples/zigbee/esp_zigbee_rcp/README.md +++ b/examples/zigbee/esp_zigbee_rcp/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32-C6 | ESP32-H4 | -| ----------------- | -------- | -------- | +| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-H4 | +| ----------------- | -------- | -------- | -------- | # Rcp Example 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 745874f830c6..2f481ee1aab9 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/README.md +++ b/examples/zigbee/light_sample/HA_on_off_light/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32-C6 | ESP32-H4 | -| ----------------- | -------- | -------- | +| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-H4 | +| ----------------- | -------- | -------- | -------- | # Light Bulb Example 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 0c38d7d8707b..391d115b549b 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 @@ -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(); } 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 e555e2ed1118..d4b89f57ef1d 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 @@ -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() \ { \ 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 e4078c061470..761486a733ea 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/README.md +++ b/examples/zigbee/light_sample/HA_on_off_switch/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32-C6 | ESP32-H4 | -| ----------------- | -------- | -------- | +| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-H4 | +| ----------------- | -------- | -------- | -------- | # Light Switch Example 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 3430f98423ce..a2ee868e6ae8 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 @@ -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(); } diff --git a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h index eeca2125b71a..7d89e241cd91 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h +++ b/examples/zigbee/light_sample/HA_on_off_switch/main/esp_zb_switch.h @@ -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() \ { \