Skip to content

Commit 50ef6f4

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

21 files changed

+1157
-50
lines changed

boards.txt

+39-38
Large diffs are not rendered by default.

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

+4-1
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

+10-5
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

+4-1
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

+21-5
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.

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

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Arduino-ESP32 Zigbee Temperature Sensor Example
2+
3+
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) temperature sensor.
4+
5+
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_temperature_sensor.**
6+
7+
# Supported Targets
8+
9+
Currently, this example supports the following targets.
10+
11+
| Supported Targets | ESP32-C6 | ESP32-H2 |
12+
| ----------------- | -------- | -------- |
13+
14+
## Temperature Sensor Functions
15+
16+
Note:
17+
* This board means the board (e.g. ESP32-H2) loaded with `Zigbee_Temperature_Sensor` example.
18+
* The remote board means the board (e.g. ESP32-H2) loaded with `Zigbee_Thermostat` example.
19+
20+
Functions:
21+
* After this board first starts up, it would be configured locally to report the temperature on 1 degree change and no periodic reporting to the remote board.
22+
* By clicking the switch button (BOOT) on this board, this board will immediately send a report of the current measured temperature to the remote board.
23+
24+
## Hardware Required
25+
26+
* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee coordinator (loaded with `Zigbee_Thermostat` example)
27+
* A USB cable for power supply and programming
28+
* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee end device (loaded with `Zigbee_Temperature_Sensor` example)
29+
30+
### Configure the Project
31+
32+
In this example, the internal temperature sensor task is reading the chip temperature.
33+
Set the Button Switch GPIO by changing the `GPIO_INPUT_IO_TOGGLE_SWITCH` definition. By default, it's the `GPIO_NUM_9` (BOOT button on ESP32-C6 and ESP32-H2).
34+
35+
#### Using Arduino IDE
36+
37+
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
38+
39+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
40+
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
41+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
42+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
43+
44+
## Troubleshooting
45+
46+
If the End device flashed with this example is not connecting to the coordinator, erase the flash before flashing it to the board. It is recommended to do this if you did changes to the coordinator.
47+
You can do the following:
48+
49+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`
50+
* In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
51+
52+
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.
53+
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
54+
55+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
56+
57+
* **LED not blinking:** Check the wiring connection and the IO selection.
58+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
59+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
60+
61+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
62+
63+
## Contribute
64+
65+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
66+
67+
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
68+
69+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
70+
71+
## Resources
72+
73+
The ESP Zigbee SDK provides more examples:
74+
* ESP Zigbee SDK Docs: [Link](https://docs.espressif.com/projects/esp-zigbee-sdk)
75+
* ESP Zigbee SDK Repo: [Link](https://github.com/espressif/esp-zigbee-sdk)
76+
77+
* Official ESP32 Forum: [Link](https://esp32.com)
78+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
79+
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
80+
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
81+
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
82+
* ESP32-S3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf)
83+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)

0 commit comments

Comments
 (0)