Unverified Commit 50ef6f43 authored by Jan Procházka's avatar Jan Procházka Committed by GitHub

Zigbee examples update (#9627)

parent 356e738e
This diff is collapsed.
# Arduino-ESP32 Zigbee Light Bulb Example # Arduino-ESP32 Zigbee Light Bulb Example
This example shows how to configure the Zigbee end device and use it as a HA on/off light bulb. This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) on/off light bulb.
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_light.** **This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_light.**
...@@ -39,6 +39,9 @@ You can do the following: ...@@ -39,6 +39,9 @@ You can do the following:
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled` * In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`
* In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. * In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
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.
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** ***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
* **LED not blinking:** Check the wiring connection and the IO selection. * **LED not blinking:** Check the wiring connection and the IO selection.
......
...@@ -49,10 +49,10 @@ ...@@ -49,10 +49,10 @@
} }
#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ #define ESP_ZB_DEFAULT_RADIO_CONFIG() \
{ .radio_mode = RADIO_MODE_NATIVE, } { .radio_mode = ZB_RADIO_MODE_NATIVE, }
#define ESP_ZB_DEFAULT_HOST_CONFIG() \ #define ESP_ZB_DEFAULT_HOST_CONFIG() \
{ .host_connection_mode = HOST_CONNECTION_MODE_NONE, } { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, }
/* Zigbee configuration */ /* Zigbee configuration */
#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ #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) { ...@@ -78,8 +78,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
if (err_status == ESP_OK) { if (err_status == ESP_OK) {
log_i("Start network steering"); log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); if (esp_zb_bdb_is_factory_new()) {
log_i("Start network formation");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
} else {
log_i("Device rebooted");
}
} else { } else {
/* commissioning failed */ /* commissioning failed */
log_w("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); 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) { ...@@ -122,7 +127,7 @@ static void esp_zb_task(void *pvParameters) {
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
//Erase NVRAM before creating connection to new Coordinator //Erase NVRAM before creating connection to new Coordinator
//esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator
ESP_ERROR_CHECK(esp_zb_start(false)); ESP_ERROR_CHECK(esp_zb_start(false));
esp_zb_main_loop_iteration(); esp_zb_main_loop_iteration();
......
# Arduino-ESP32 Zigbee Light Switch Example # Arduino-ESP32 Zigbee Light Switch Example
This example shows how to configure Zigbee Coordinator and use it as an HA on/off light switch. This example shows how to configure Zigbee Coordinator and use it as a Home Automation (HA) on/off light switch.
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_switch.** **This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_switch.**
...@@ -39,6 +39,9 @@ You can do the following: ...@@ -39,6 +39,9 @@ You can do the following:
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`. * In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
* In the `Zigbee_Light_Bulb` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. * In the `Zigbee_Light_Bulb` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
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.
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** ***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
* **LED not blinking:** Check the wiring connection and the IO selection. * **LED not blinking:** Check the wiring connection and the IO selection.
......
...@@ -75,10 +75,10 @@ static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SW ...@@ -75,10 +75,10 @@ static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SW
} }
#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ #define ESP_ZB_DEFAULT_RADIO_CONFIG() \
{ .radio_mode = RADIO_MODE_NATIVE, } { .radio_mode = ZB_RADIO_MODE_NATIVE, }
#define ESP_ZB_DEFAULT_HOST_CONFIG() \ #define ESP_ZB_DEFAULT_HOST_CONFIG() \
{ .host_connection_mode = HOST_CONNECTION_MODE_NONE, } { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, }
typedef struct light_bulb_device_params_s { typedef struct light_bulb_device_params_s {
esp_zb_ieee_addr_t ieee_addr; esp_zb_ieee_addr_t ieee_addr;
...@@ -92,7 +92,7 @@ typedef struct light_bulb_device_params_s { ...@@ -92,7 +92,7 @@ typedef struct light_bulb_device_params_s {
#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */ #define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */
#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ #define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */
/********************* Define functions **************************/ /********************* Zigbee functions **************************/
static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) { static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) {
if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
/* implemented light switch toggle functionality */ /* implemented light switch toggle functionality */
...@@ -153,8 +153,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { ...@@ -153,8 +153,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
if (err_status == ESP_OK) { if (err_status == ESP_OK) {
log_i("Start network formation"); log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); if (esp_zb_bdb_is_factory_new()) {
log_i("Start network formation");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION);
} else {
log_i("Device rebooted");
log_i("Openning network for joining for %d seconds", 180);
esp_zb_bdb_open_network(180);
}
} else { } else {
log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status));
} }
...@@ -187,6 +194,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { ...@@ -187,6 +194,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
cmd_req.addr_of_interest = dev_annce_params->device_short_addr; cmd_req.addr_of_interest = dev_annce_params->device_short_addr;
esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb, NULL); esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb, NULL);
break; break;
case ESP_ZB_NWK_SIGNAL_PERMIT_JOIN_STATUS:
if (err_status == ESP_OK) {
if (*(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)) {
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));
} else {
log_w("Network(0x%04hx) closed, devices joining not allowed.", esp_zb_get_pan_id());
}
}
break;
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; 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;
} }
} }
......
# Arduino-ESP32 Zigbee Temperature Sensor Example
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) temperature sensor.
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_temperature_sensor.**
# Supported Targets
Currently, this example supports the following targets.
| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |
## Temperature Sensor Functions
Note:
* This board means the board (e.g. ESP32-H2) loaded with `Zigbee_Temperature_Sensor` example.
* The remote board means the board (e.g. ESP32-H2) loaded with `Zigbee_Thermostat` example.
Functions:
* 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.
* 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.
## Hardware Required
* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee coordinator (loaded with `Zigbee_Thermostat` example)
* A USB cable for power supply and programming
* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee end device (loaded with `Zigbee_Temperature_Sensor` example)
### Configure the Project
In this example, the internal temperature sensor task is reading the chip temperature.
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).
#### Using Arduino IDE
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
* Before Compile/Verify, select the correct board: `Tools -> Board`.
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
## Troubleshooting
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.
You can do the following:
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`
* In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
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.
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
* **LED not blinking:** Check the wiring connection and the IO selection.
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
## Contribute
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
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!
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
## Resources
The ESP Zigbee SDK provides more examples:
* ESP Zigbee SDK Docs: [Link](https://docs.espressif.com/projects/esp-zigbee-sdk)
* ESP Zigbee SDK Repo: [Link](https://github.com/espressif/esp-zigbee-sdk)
* Official ESP32 Forum: [Link](https://esp32.com)
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
* ESP32-S3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf)
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
# Arduino-ESP32 Zigbee Thermostat Example
This example shows how to configure Zigbee Coordinator and use it as a Home Automation (HA) thermostat.
**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_thermostat.**
# Supported Targets
Currently, this example supports the following targets.
| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |
## Thermostat Functions
Note:
* This board means the board (e.g. ESP32-H2) loaded with `Zigbee_Thermostat` example.
* The remote board means the board (e.g. ESP32-H2) loaded with `Zigbee_Temperature_Sensor` example.
Functions:
* By clicking the switch button (BOOT) on this board, this board will read temperature value, temperature measurement range and temperature tolerance from the remote board. Also, this board will configure the remote board to report the measured temperature value every 10 seconds or every 2 degree changes.
## Hardware Required
* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee end device (loaded with Zigbee_Temperature_Sensor example).
* A USB cable for power supply and programming.
* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee coordinator (loaded with Zigbee_Thermostat example).
### Configure the Project
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).
#### Using Arduino IDE
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
* Before Compile/Verify, select the correct board: `Tools -> Board`.
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator)`.
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`.
* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port.
* Optional: Set debug level to info to see logs from Zigbee stack: `Tools -> Core Debug Level: Info`.
## Troubleshooting
If the End device flashed with the example `Zigbee_Temperature_Sensor` is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator.
You can do the following:
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
* In the `Zigbee_Temperature_Sensor` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function.
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.
You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function.
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
* **LED not blinking:** Check the wiring connection and the IO selection.
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
## Contribute
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
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!
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
## Resources
The ESP Zigbee SDK provides more examples:
* ESP Zigbee SDK Docs: [Link](https://docs.espressif.com/projects/esp-zigbee-sdk)
* ESP Zigbee SDK Repo: [Link](https://github.com/espressif/esp-zigbee-sdk)
* Official ESP32 Forum: [Link](https://esp32.com)
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
* ESP32-S3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf)
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment