Skip to content

Commit 50ef6f4

Browse files
authored
Zigbee examples update (espressif#9627)
1 parent 356e738 commit 50ef6f4

File tree

21 files changed

+1157
-50
lines changed

21 files changed

+1157
-50
lines changed

boards.txt

Lines changed: 39 additions & 38 deletions
Large diffs are not rendered by default.

libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Arduino-ESP32 Zigbee Light Bulb Example
22

3-
This example shows how to configure the Zigbee end device and use it as a HA on/off light bulb.
3+
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) on/off light bulb.
44

55
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_light.**
66

@@ -39,6 +39,9 @@ You can do the following:
3939
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`
4040
* In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
4141

42+
By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices.
43+
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
44+
4245
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
4346

4447
* **LED not blinking:** Check the wiring connection and the IO selection.

libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
}
5050

5151
#define ESP_ZB_DEFAULT_RADIO_CONFIG() \
52-
{ .radio_mode = RADIO_MODE_NATIVE, }
52+
{ .radio_mode = ZB_RADIO_MODE_NATIVE, }
5353

5454
#define ESP_ZB_DEFAULT_HOST_CONFIG() \
55-
{ .host_connection_mode = HOST_CONNECTION_MODE_NONE, }
55+
{ .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, }
5656

5757
/* Zigbee configuration */
5858
#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
@@ -78,8 +78,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
7878
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
7979
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
8080
if (err_status == ESP_OK) {
81-
log_i("Start network steering");
82-
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
81+
log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non");
82+
if (esp_zb_bdb_is_factory_new()) {
83+
log_i("Start network formation");
84+
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
85+
} else {
86+
log_i("Device rebooted");
87+
}
8388
} else {
8489
/* commissioning failed */
8590
log_w("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status));
@@ -122,7 +127,7 @@ static void esp_zb_task(void *pvParameters) {
122127
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
123128

124129
//Erase NVRAM before creating connection to new Coordinator
125-
//esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator
130+
esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator
126131

127132
ESP_ERROR_CHECK(esp_zb_start(false));
128133
esp_zb_main_loop_iteration();

libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Arduino-ESP32 Zigbee Light Switch Example
22

3-
This example shows how to configure Zigbee Coordinator and use it as an HA on/off light switch.
3+
This example shows how to configure Zigbee Coordinator and use it as a Home Automation (HA) on/off light switch.
44

55
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_switch.**
66

@@ -39,6 +39,9 @@ You can do the following:
3939
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
4040
* In the `Zigbee_Light_Bulb` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
4141

42+
By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices.
43+
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
44+
4245
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
4346

4447
* **LED not blinking:** Check the wiring connection and the IO selection.

libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SW
7575
}
7676

7777
#define ESP_ZB_DEFAULT_RADIO_CONFIG() \
78-
{ .radio_mode = RADIO_MODE_NATIVE, }
78+
{ .radio_mode = ZB_RADIO_MODE_NATIVE, }
7979

8080
#define ESP_ZB_DEFAULT_HOST_CONFIG() \
81-
{ .host_connection_mode = HOST_CONNECTION_MODE_NONE, }
81+
{ .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, }
8282

8383
typedef struct light_bulb_device_params_s {
8484
esp_zb_ieee_addr_t ieee_addr;
@@ -92,7 +92,7 @@ typedef struct light_bulb_device_params_s {
9292
#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */
9393
#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */
9494

95-
/********************* Define functions **************************/
95+
/********************* Zigbee functions **************************/
9696
static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) {
9797
if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
9898
/* implemented light switch toggle functionality */
@@ -153,8 +153,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
153153
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
154154
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
155155
if (err_status == ESP_OK) {
156-
log_i("Start network formation");
157-
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION);
156+
log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non");
157+
if (esp_zb_bdb_is_factory_new()) {
158+
log_i("Start network formation");
159+
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION);
160+
} else {
161+
log_i("Device rebooted");
162+
log_i("Openning network for joining for %d seconds", 180);
163+
esp_zb_bdb_open_network(180);
164+
}
158165
} else {
159166
log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status));
160167
}
@@ -187,6 +194,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
187194
cmd_req.addr_of_interest = dev_annce_params->device_short_addr;
188195
esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb, NULL);
189196
break;
197+
case ESP_ZB_NWK_SIGNAL_PERMIT_JOIN_STATUS:
198+
if (err_status == ESP_OK) {
199+
if (*(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)) {
200+
log_i("Network(0x%04hx) is open for %d seconds", esp_zb_get_pan_id(), *(uint8_t *)esp_zb_app_signal_get_params(p_sg_p));
201+
} else {
202+
log_w("Network(0x%04hx) closed, devices joining not allowed.", esp_zb_get_pan_id());
203+
}
204+
}
205+
break;
190206
default: log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); break;
191207
}
192208
}

libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32

Whitespace-only changes.

libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32c3

Whitespace-only changes.

libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32c6

Whitespace-only changes.

libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32h2

Whitespace-only changes.

libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32s2

Whitespace-only changes.

0 commit comments

Comments
 (0)