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
@@ -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
)
@@ -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
@@ -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);
@@ -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, \
}
@@ -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
@@ -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;
@@ -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
@@ -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);
@@ -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, \
}
@@ -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
@@ -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
@@ -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);
@@ -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, \
}
@@ -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
@@ -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: