Zigbee example: add rcp and gateway

* provide Zigbee rcp and Zigbee gateway example
 * minor comment fix for light example
This commit is contained in:
likunqiao 2021-12-16 17:42:19 +08:00 committed by bot
parent 637716b310
commit 8c577cd208
33 changed files with 723 additions and 80 deletions

View File

@ -0,0 +1,7 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp_zigbee_gateway)

View File

@ -0,0 +1,55 @@
# Gateway Example
(See the `README.md` file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to build a Zigbee Gateway device. It runs on a Wi-Fi SoC such as ESP32, ESP32-C3 and ESP32-S3, with an 802.15.4 SoC like ESP32-H2 running [esp_zigbee_rcp](../esp_zigbee_rcp) to provide 802.15.4 radio.
## Hardware Required
* One development board with ESP32 or ESP32-S3 SoC acting as Zigbee gateway (loaded with esp_zigbee_gateway example)
* A USB cable for power supply and programming
* Three jumper wires for UART (TX, RX and GND)
* Gateway doesn't function alone. Choose ESP32-H2 as Zigbee rcp (see [esp_zigbee_rcp example](../esp_zigbee_rcp))
* **Flash** Zigbee rcp on the ESP32-H2 DevKitC first **before** connecting to Zigbee gateway
* Connect the two SoCs via UART, below is an example setup with ESP32-DevKitC and ESP32-H2-DevKitC:
![Zigbee_gateway](../../openthread/ot_br/image/thread-border-router-esp32-esp32h2.jpg)
ESP32 pin | ESP32-H2 pin
------------- |-------------
GND | G
GPIO4 (RX) | TX
GPIO5 (TX) | RX
* TX, RX pin can be also configured by user in esp_zigbee_gateway.h
## Configure the project
Before project configuration and build, make sure to set the correct chip target using `idf.py set-target esp32` or `idf.py set-target esp32s3`
## Build and Flash
Build the project, flash it to the board, and start the monitor tool to view the serial output by running `idf.py -p PORT flash monitor`
(To exit the serial monitor, type ``Ctrl-]``.)
## Example Output
As you run the example, you will see the following log:
esp_zigbee_gateway:
I (660) ESP_ZB_GATEWAY: status: -1
I (670) ESP_ZB_GATEWAY: Zigbee stack initialized
I (680) ESP_ZB_GATEWAY: Zigbee rcp device booted
I (1280) ESP_ZB_GATEWAY: Start network formation
I (3060) ESP_ZB_GATEWAY: Formed network successfully (ieee extended address: f9:54:2d:01:a0:03:f7:84, PAN ID: 0x8651)
I (4060) ESP_ZB_GATEWAY: status: 0
I (4400) ESP_ZB_GATEWAY: Network steering started
## Gateway Functions
* After Zigbee gateway starts up, it will read MAC ieee address and Zigbee stack version number from the Zigbee rcp and start working together with Zigbee rcp via UART communication to form a Zigbee network
* More Gateway functionalities supporting Wi-Fi interaction will come later
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon

View File

@ -0,0 +1,2 @@
idf_component_register(SRCS "esp_zigbee_gateway.c"
INCLUDE_DIRS ".")

View File

@ -0,0 +1,141 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
* integrated circuit in a product or a software update for such product,
* must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_zigbee_gateway.h"
#if (!defined ZB_MACSPLIT_HOST && defined ZB_MACSPLIT_DEVICE)
#error Only Zigbee gateway hostdevice should be defined
#endif
static const char *TAG = "ESP_ZB_GATEWAY";
/********************* Define functions **************************/
static void bdb_start_top_level_commissioning_cb(zb_uint8_t mode_mask)
{
if (!bdb_start_top_level_commissioning(mode_mask)) {
ESP_LOGE(TAG, "In BDB commissioning, an error occurred (for example: the device has already been running)");
}
}
void zboss_signal_handler(zb_bufid_t bufid)
{
zb_zdo_app_signal_hdr_t *p_sg_p = NULL;
zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, &p_sg_p);
zb_ret_t status = ZB_GET_APP_SIGNAL_STATUS(bufid);
switch (sig) {
case ZB_ZDO_SIGNAL_SKIP_STARTUP:
ESP_LOGI(TAG, "Zigbee stack initialized");
bdb_start_top_level_commissioning(ZB_BDB_INITIALIZATION);
break;
case ZB_MACSPLIT_DEVICE_BOOT:
ESP_LOGI(TAG, "Zigbee rcp device booted");
break;
case ZB_BDB_SIGNAL_DEVICE_FIRST_START:
if (status == RET_OK) {
ESP_LOGI(TAG, "Start network formation");
bdb_start_top_level_commissioning(ZB_BDB_NETWORK_FORMATION);
} else {
ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %d)", status);
}
break;
case ZB_BDB_SIGNAL_FORMATION:
if (status == RET_OK) {
zb_ieee_addr_t ieee_address;
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)",
ieee_address[7], ieee_address[6], ieee_address[5], ieee_address[4],
ieee_address[3], ieee_address[2], ieee_address[1], ieee_address[0],
ZB_PIBCACHE_PAN_ID());
bdb_start_top_level_commissioning(ZB_BDB_NETWORK_STEERING);
} else {
ESP_LOGI(TAG, "Restart network formation (status: %d)", status);
ZB_SCHEDULE_APP_ALARM((zb_callback_t)bdb_start_top_level_commissioning_cb, ZB_BDB_NETWORK_FORMATION, ZB_TIME_ONE_SECOND);
}
break;
case ZB_BDB_SIGNAL_STEERING:
if (status == RET_OK) {
ESP_LOGI(TAG, "Network steering started");
}
break;
case ZB_ZDO_SIGNAL_DEVICE_ANNCE: {
zb_zdo_signal_device_annce_params_t *dev_annce_params = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_device_annce_params_t);
ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr);
}
break;
default:
ESP_LOGI(TAG, "status: %d", status);
break;
}
/* All callbacks should either reuse or free passed buffers. If bufid == 0, the buffer is invalid (not passed) */
if (bufid) {
zb_buf_free(bufid);
}
}
void zboss_task()
{
ZB_INIT("zigbee gateway");
zb_set_network_coordinator_role(IEEE_CHANNEL_MASK);
zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG);
zb_set_max_children(MAX_CHILDREN);
/* initiate Zigbee Stack start without zb_send_no_autostart_signal auto-start */
ESP_ERROR_CHECK(zboss_start_no_autostart());
while (1) {
zboss_main_loop_iteration();
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
void app_main()
{
zb_esp_platform_config_t config = {
.radio_config = ZB_ESP_DEFAULT_RADIO_CONFIG(),
.host_config = ZB_ESP_DEFAULT_HOST_CONFIG(),
};
/* load Zigbee gateway platform config to initialization */
ESP_ERROR_CHECK(zb_esp_platform_config(&config));
xTaskCreate(zboss_task, "zboss_main", 10240, xTaskGetCurrentTaskHandle(), 5, NULL);
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
* integrated circuit in a product or a software update for such product,
* must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "esp_err.h"
#include "zboss_api.h"
/* Zigbee Configuration */
#define IEEE_CHANNEL_MASK (1l << 13) /* ZigBee default setting is channel 13 for light example usage */
#define ERASE_PERSISTENT_CONFIG ZB_TRUE /* erase network devices before running example */
#define MAX_CHILDREN 10 /* the max amount of connected devices */
#define ZB_ESP_DEFAULT_RADIO_CONFIG() \
{ \
.radio_mode = RADIO_MODE_UART_RCP, \
.radio_uart_config = { \
.port = 1, \
.uart_config = \
{ \
.baud_rate = 115200, \
.data_bits = UART_DATA_8_BITS, \
.parity = UART_PARITY_DISABLE, \
.stop_bits = UART_STOP_BITS_1, \
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \
.rx_flow_ctrl_thresh = 0, \
.source_clk = UART_SCLK_APB, \
}, \
.rx_pin = 4, \
.tx_pin = 5, \
}, \
}
#define ZB_ESP_DEFAULT_HOST_CONFIG() \
{ \
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
}

View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-zboss-lib: "~=0.0.4"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
zb_storage, data, fat, , 128K,
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, 0x10000, 1M,
6 zb_storage, data, fat, , 128K,

View File

@ -0,0 +1,41 @@
#
# libsodium
#
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
# end of libsodium
#
# Partition Table
#
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table
#
# mbedTLS
#
CONFIG_MBEDTLS_HARDWARE_AES=n
CONFIG_MBEDTLS_HARDWARE_MPI=n
CONFIG_MBEDTLS_HARDWARE_SHA=n
CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y
# end of TLS Key Exchange Methods
CONFIG_MBEDTLS_ECJPAKE_C=y
# end of mbedTLS
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
#
# Zboss
#
CONFIG_ZB_ENABLED=y
CONFIG_ZB_ZCZR=y
CONFIG_ZB_RADIO_MACSPLIT_UART=y
# end of Zboss
# end of Component config

View File

@ -0,0 +1,7 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp_zigbee_rcp)

View File

@ -0,0 +1,32 @@
| Supported Targets | ESP32-H2 |
| ----------------- | -------- |
# Rcp Example
(See the `README.md` file in the upper level 'examples' directory for more information about examples.)
This test code shows how to configure Zigbee rcp (radio co-processor) device. Rcp doesn't function alone, it needs to work together with Zigbee gateway (see [esp_zigbee_gateway example](../esp_zigbee_gateway))
## Hardware Required
* One development board with ESP32-H2 SoC acting as Zigbee rcp (loaded with esp_zigbee_rcp example)
* A USB cable for power supply and programming
* Choose ESP32 or ESP32-S3 as Zigbee gateway. The connection and setup refer to the Zigbee gateway example for setup details (see [esp_zigbee_gateway example](../esp_zigbee_gateway))
* TX, RX pin can be also configured by user in esp_zigbee_rcp.h
## Configure the project
Before project configuration and build, make sure to set the correct chip target using `idf.py --preview set-target esp32h2`
## Build and Flash
Build the project, flash it to the board by running `idf.py -p <PORT> build flash`
## Rcp Functions
* After rcp starts up, it will send its own MAC ieee address and Zigbee stack version number to the Zigbee gateway and start working together with Zigbee gateway via UART communication
* For more log info please see Zigbee gateway side
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon

View File

@ -0,0 +1,2 @@
idf_component_register(SRCS "esp_zigbee_rcp.c"
INCLUDE_DIRS ".")

View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
* integrated circuit in a product or a software update for such product,
* must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "zb_scheduler.h"
#include "esp_zigbee_rcp.h"
#if (defined ZB_MACSPLIT_HOST && !defined ZB_MACSPLIT_DEVICE)
#error Only Zigbee rcp device should be defined
#endif
static const char *TAG = "ESP_ZB_RCP";
void zboss_signal_handler(zb_uint8_t param)
{
zb_zdo_app_signal_hdr_t *sg_p = NULL;
/* get application signal from the buffer */
zb_zdo_app_signal_type_t sig = zb_get_app_signal(param, &sg_p);
if (ZB_GET_APP_SIGNAL_STATUS(param) == 0) {
switch (sig) {
case ZB_COMMON_SIGNAL_CAN_SLEEP:
#if defined(ZB_USE_SLEEP)
zb_sleep_now();
#endif
break;
default: break;
}
} else if (sig == ZB_ZDO_SIGNAL_PRODUCTION_CONFIG_READY) {
ESP_LOGI(TAG, "Production config is not present or invalid");
} else {
ESP_LOGI(TAG, "Device started FAILED status %d", ZB_GET_APP_SIGNAL_STATUS(param));
}
if (param) {
zb_buf_free(param);
}
}
void zboss_task()
{
ZB_INIT("esp_zigbee_rcp");
while (1) {
zb_sched_loop_iteration();
}
}
void app_main()
{
zb_esp_platform_config_t config = {
.radio_config = ZB_ESP_DEFAULT_RADIO_CONFIG(),
.host_config = ZB_ESP_DEFAULT_HOST_CONFIG(),
};
/* load Zigbee rcp platform config to initialization */
ESP_ERROR_CHECK(zb_esp_platform_config(&config));
xTaskCreate(zboss_task, "zboss_main", 4096, xTaskGetCurrentTaskHandle(), 5, NULL);
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) CO LTD
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
* integrated circuit in a product or a software update for such product,
* must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "zboss_api.h"
#define ZB_ESP_DEFAULT_RADIO_CONFIG() \
{ \
.radio_mode = RADIO_MODE_NATIVE, \
}
#define ZB_ESP_DEFAULT_HOST_CONFIG() \
{ \
.host_connection_mode = HOST_CONNECTION_MODE_RCP_UART, \
.host_uart_config = { \
.port = 0, \
.uart_config = \
{ \
.baud_rate = 115200, \
.data_bits = UART_DATA_8_BITS, \
.parity = UART_PARITY_DISABLE, \
.stop_bits = UART_STOP_BITS_1, \
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \
.rx_flow_ctrl_thresh = 0, \
.source_clk = UART_SCLK_APB, \
}, \
.rx_pin = UART_PIN_NO_CHANGE, \
.tx_pin = UART_PIN_NO_CHANGE, \
}, \
}

View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-zboss-lib: "~=0.0.4"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
zb_storage, data, fat, , 128K,
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, 0x10000, 1M,
6 zb_storage, data, fat, , 128K,

View File

@ -0,0 +1,20 @@
CONFIG_IDF_TARGET="esp32h2"
#
# Partition Table
#
CONFIG_PARTITION_TABLE_SINGLE_APP=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table
#
# ZBOSS Source
#
CONFIG_ZB_ENABLED=y
CONFIG_ZB_RCP=y
CONFIG_ZB_CONSOLE_UART_BAUDRATE=115200
# end of ZBOSS Source
# end of Component config

View File

@ -1,7 +1,6 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS
$ENV{IDF_PATH}/examples/common_components/led_strip
)

View File

@ -16,9 +16,6 @@ This test code shows how to configure Zigbee router device and use it as a light
## Configure the project
[**Mandatory**] Download esp-zboss-lib packages from [Espressif's component serivce](https://components.espressif.com/).
You can add them to your project via `idf.py add-dependency espressif/esp-zboss-lib==0.0.2`
Before project configuration and build, make sure to set the correct chip target using `idf.py set-target esp32h2`.
## Build and Flash
@ -32,17 +29,17 @@ Build the project, flash it to the board, and start the monitor tool to view the
As you run the example, you will see the following log:
light bulb:
I (9638) ESP_ZB_LIGHT: status: 255
I (9638) ESP_ZB_LIGHT: Zigbee stack initialized
I (9648) ESP_ZB_LIGHT: Start network steering
I (12368) ESP_ZB_LIGHT: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
I (12398) ESP_ZB_LIGHT: status: 0
I (18158) ESP_ZB_LIGHT: on/off attribute setting to 1
I (19388) ESP_ZB_LIGHT: on/off attribute setting to 0
I (20418) ESP_ZB_LIGHT: on/off attribute setting to 1
I (21558) ESP_ZB_LIGHT: on/off attribute setting to 0
I (22478) ESP_ZB_LIGHT: on/off attribute setting to 1
I (23088) ESP_ZB_LIGHT: on/off attribute setting to 0
I (9638) ESP_ZB_LIGHT: status: 255
I (9638) ESP_ZB_LIGHT: Zigbee stack initialized
I (9648) ESP_ZB_LIGHT: Start network steering
I (12368) ESP_ZB_LIGHT: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
I (12398) ESP_ZB_LIGHT: status: 0
I (18158) ESP_ZB_LIGHT: on/off attribute setting to 1
I (19388) ESP_ZB_LIGHT: on/off attribute setting to 0
I (20418) ESP_ZB_LIGHT: on/off attribute setting to 1
I (21558) ESP_ZB_LIGHT: on/off attribute setting to 0
I (22478) ESP_ZB_LIGHT: on/off attribute setting to 1
I (23088) ESP_ZB_LIGHT: on/off attribute setting to 0
## Light Control Functions

View File

@ -215,12 +215,14 @@ static void esp_zb_light_cb(zb_bufid_t bufid)
void app_main()
{
zb_ret_t zb_err_code;
zb_ieee_addr_t g_ieee_addr;
zb_esp_platform_config_t config = {
.radio_config = ZB_ESP_DEFAULT_RADIO_CONFIG(),
.host_config = ZB_ESP_DEFAULT_HOST_CONFIG(),
};
ESP_ERROR_CHECK(zb_esp_platform_config(&config));
/* initialize Zigbee stack */
ZB_INIT("light_bulb");
esp_read_mac(g_ieee_addr, ESP_MAC_IEEE802154);
zb_set_long_address(g_ieee_addr);
zb_set_network_router_role(IEEE_CHANNEL_MASK);
zb_set_max_children(MAX_CHILDREN);
zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG);

View File

@ -35,8 +35,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "light_driver.h"
#include "zboss_api.h"
#include "light_driver.h"
/* Zigbee configuration */
#define IEEE_CHANNEL_MASK (1l << 13) /* Zigbee default setting is channel 13 for light example usage */
@ -67,3 +67,12 @@ typedef struct {
} bulb_device_ctx_t;
#define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */
#define ZB_ESP_DEFAULT_RADIO_CONFIG() \
{ \
.radio_mode = RADIO_MODE_NATIVE, \
}
#define ZB_ESP_DEFAULT_HOST_CONFIG() \
{ \
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
}

View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-zboss-lib: "~=0.0.4"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -35,9 +35,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "light_driver.h"
#include "led_strip.h"
#include "esp_log.h"
#include "led_strip.h"
#include "light_driver.h"
static led_strip_t *led_strip;

View File

@ -16,9 +16,6 @@ This test code shows how to configure Zigbee coordinator device.
## Configure the project
[**Mandatory**] Download esp-zboss-lib packages from [Espressif's component serivce](https://components.espressif.com/).
You can add them to your project via `idf.py add-dependency espressif/esp-zboss-lib==0.0.2`
Before project configuration and build, make sure to set the correct chip target using `idf.py set-target esp32h2`.
## Build and Flash
@ -32,20 +29,20 @@ Build the project, flash it to the board, and start the monitor tool to view the
As you run the example, you will see the following log:
light coodrinator:
I (9556) ESP_ZB_COORDINATOR: status: -1
I (9556) ESP_ZB_COORDINATOR: Zigbee stack initialized
I (9556) ESP_ZB_COORDINATOR: Start network formation
I (10066) ESP_ZB_COORDINATOR: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
I (10526) ESP_ZB_COORDINATOR: Network steering started
I (11306) ESP_ZB_COORDINATOR: status: 0
I (11806) ESP_ZB_COORDINATOR: status: 0
I (11886) ESP_ZB_COORDINATOR: New device commissioned or rejoined (short: 0x434a)
I (12386) ESP_ZB_COORDINATOR: status: 0
I (12486) ESP_ZB_COORDINATOR: status: 0
I (12896) ESP_ZB_COORDINATOR: status: 0
I (12946) ESP_ZB_COORDINATOR: New device commissioned or rejoined (short: 0x09c2)
I (13516) ESP_ZB_COORDINATOR: status: 0
I (26686) ESP_ZB_COORDINATOR: status: 0
I (9556) ESP_ZB_COORDINATOR: status: -1
I (9556) ESP_ZB_COORDINATOR: Zigbee stack initialized
I (9556) ESP_ZB_COORDINATOR: Start network formation
I (10066) ESP_ZB_COORDINATOR: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
I (10526) ESP_ZB_COORDINATOR: Network steering started
I (11306) ESP_ZB_COORDINATOR: status: 0
I (11806) ESP_ZB_COORDINATOR: status: 0
I (11886) ESP_ZB_COORDINATOR: New device commissioned or rejoined (short: 0x434a)
I (12386) ESP_ZB_COORDINATOR: status: 0
I (12486) ESP_ZB_COORDINATOR: status: 0
I (12896) ESP_ZB_COORDINATOR: status: 0
I (12946) ESP_ZB_COORDINATOR: New device commissioned or rejoined (short: 0x09c2)
I (13516) ESP_ZB_COORDINATOR: status: 0
I (26686) ESP_ZB_COORDINATOR: status: 0
## Light Control Functions

View File

@ -35,8 +35,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "esp_zb_coordinator.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_zb_coordinator.h"
static const char *TAG = "ESP_ZB_COORDINATOR";
@ -114,12 +115,14 @@ void zboss_signal_handler(zb_bufid_t bufid)
void app_main()
{
zb_ret_t zb_err_code;
zb_ieee_addr_t g_ieee_addr;
zb_esp_platform_config_t config = {
.radio_config = ZB_ESP_DEFAULT_RADIO_CONFIG(),
.host_config = ZB_ESP_DEFAULT_HOST_CONFIG(),
};
ESP_ERROR_CHECK(zb_esp_platform_config(&config));
/* initialize Zigbee stack */
ZB_INIT("light_coordinator");
esp_read_mac(g_ieee_addr, ESP_MAC_IEEE802154);
zb_set_long_address(g_ieee_addr);
zb_set_network_coordinator_role(IEEE_CHANNEL_MASK);
zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG);
zb_set_max_children(MAX_CHILDREN);

View File

@ -36,9 +36,17 @@
*/
#include "zboss_api.h"
#include "esp_err.h"
/* Zigbee Configuration */
#define IEEE_CHANNEL_MASK (1l << 13) /* ZigBee default setting is channel 13 for light example usage */
#define IEEE_CHANNEL_MASK (1l << 13) /* Zigbee default setting is channel 13 for light example usage */
#define ERASE_PERSISTENT_CONFIG ZB_TRUE /* erase network devices before running example */
#define MAX_CHILDREN 10 /* the max amount of connected devices */
#define ZB_ESP_DEFAULT_RADIO_CONFIG() \
{ \
.radio_mode = RADIO_MODE_NATIVE, \
}
#define ZB_ESP_DEFAULT_HOST_CONFIG() \
{ \
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
}

View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-zboss-lib: "~=0.0.4"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -16,9 +16,6 @@ This test code shows how to configure Zigbee end device and use it as a light sw
## Configure the project
[**Mandatory**] Download esp-zboss-lib packages from [Espressif's component serivce](https://components.espressif.com/).
You can add them to your project via `idf.py add-dependency espressif/esp-zboss-lib==0.0.2`
Before project configuration and build, make sure to set the correct chip target using `idf.py set-target esp32h2`.
## Build and Flash
@ -32,18 +29,18 @@ Build the project, flash it to the board, and start the monitor tool to view the
As you run the example, you will see the following log:
light switch:
I (9423) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
I (9523) ESP_ZB_SWITCH: status: -1
I (9523) ESP_ZB_SWITCH: Zigbee stack initialized
I (9523) ESP_ZB_SWITCH: Start network steering
I (11263) ESP_ZB_SWITCH: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
I (13433) ESP_ZB_SWITCH: Found bulb addr: 0x434a ep: 10
I (16433) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (17663) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (18693) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (19833) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (20753) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (21363) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (9423) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
I (9523) ESP_ZB_SWITCH: status: -1
I (9523) ESP_ZB_SWITCH: Zigbee stack initialized
I (9523) ESP_ZB_SWITCH: Start network steering
I (11263) ESP_ZB_SWITCH: Joined network successfully (Extended PAN ID: f9:54:2d:01:a0:03:f7:84, PAN ID: 0xf5b5)
I (13433) ESP_ZB_SWITCH: Found bulb addr: 0x434a ep: 10
I (16433) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (17663) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (18693) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (19833) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (20753) ESP_ZB_SWITCH: Send ON/OFF toggle command
I (21363) ESP_ZB_SWITCH: Send ON/OFF toggle command
## Light Control Functions

View File

@ -35,8 +35,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "esp_zb_switch.h"
#include "esp_log.h"
#include "esp_zb_switch.h"
/**
* @note Make sure set idf.py menuconfig in zigbee component as zigbee end device!
@ -284,12 +284,14 @@ void zboss_signal_handler(zb_uint8_t bufid)
void app_main()
{
zb_ret_t zb_err_code;
zb_ieee_addr_t g_ieee_addr;
zb_esp_platform_config_t config = {
.radio_config = ZB_ESP_DEFAULT_RADIO_CONFIG(),
.host_config = ZB_ESP_DEFAULT_HOST_CONFIG(),
};
/* initialize Zigbee stack */
ESP_ERROR_CHECK(zb_esp_platform_config(&config));
/* initialize Zigbee stack. */
ZB_INIT("light_switch");
esp_read_mac(g_ieee_addr, ESP_MAC_IEEE802154);
zb_set_long_address(g_ieee_addr);
zb_set_network_ed_role(IEEE_CHANNEL_MASK);
zb_set_nvram_erase_at_start(ERASE_PERSISTENT_CONFIG);
zb_set_ed_timeout(ED_AGING_TIMEOUT_64MIN);

View File

@ -34,9 +34,10 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "switch_driver.h"
#include "zboss_api.h"
#include "zboss_api_zcl.h"
#include "zb_ha.h"
#include "switch_driver.h"
/* Zigbee configuration */
#define IEEE_CHANNEL_MASK (1l << 13) /* ZigBee default setting is channel 13 for light example usage */
@ -60,3 +61,12 @@ typedef struct {
zb_zcl_on_off_attrs_t on_off_attr;
light_switch_bulb_params_t bulb_params;
} switch_device_ctx_t;
#define ZB_ESP_DEFAULT_RADIO_CONFIG() \
{ \
.radio_mode = RADIO_MODE_NATIVE, \
}
#define ZB_ESP_DEFAULT_HOST_CONFIG() \
{ \
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
}

View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-zboss-lib: "~=0.0.4"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -35,11 +35,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "switch_driver.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "freertos/queue.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "switch_driver.h"
/**
* @brief:

View File

@ -69,3 +69,4 @@ ignore:
- components/bt/host/bluedroid/
- '!components/bt/host/bluedroid/api/'
- '!components/bt/host/bluedroid/btc/'
- examples/zigbee/

View File

@ -2976,16 +2976,6 @@ examples/wifi/smart_config/main/smartconfig_main.c
examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c
examples/wifi/wifi_enterprise/main/wifi_enterprise_main.c
examples/wifi/wps/main/wps.c
examples/zigbee/light_sample/light_bulb/main/esp_zb_light.c
examples/zigbee/light_sample/light_bulb/main/esp_zb_light.h
examples/zigbee/light_sample/light_bulb/main/light_driver.c
examples/zigbee/light_sample/light_bulb/main/light_driver.h
examples/zigbee/light_sample/light_coordinator/main/esp_zb_coordinator.c
examples/zigbee/light_sample/light_coordinator/main/esp_zb_coordinator.h
examples/zigbee/light_sample/light_switch/main/esp_zb_switch.c
examples/zigbee/light_sample/light_switch/main/esp_zb_switch.h
examples/zigbee/light_sample/light_switch/main/switch_driver.c
examples/zigbee/light_sample/light_switch/main/switch_driver.h
tools/ble/lib_ble_client.py
tools/ble/lib_gap.py
tools/ble/lib_gatt.py