Skip to content

Commit fa6267a

Browse files
committed
Dev Update: Version setting, Thermostat fix, ...
Simplified bounded device print as the structure is common for any EP type Allowed setting custom app version for EP, default is 0 Small fixes and code updates
1 parent 4d18a8c commit fa6267a

20 files changed

+149
-236
lines changed

boards.txt

+42-42
Large diffs are not rendered by default.

libraries/Zigbee/examples/Zigbee_Color_Dimmer_Switch/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Set the Button Switch GPIO by changing the `GPIO_SWITCH` definition. By default,
2424
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
2525

2626
* Before Compile/Verify, select the correct board: `Tools -> Board`.
27-
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator)`.
27+
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`.
2828
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`.
2929
* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port.
3030
* Optional: Set debug level to info to see logs from Zigbee stack: `Tools -> Core Debug Level: Info`.

libraries/Zigbee/examples/Zigbee_On_Off_Switch/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Currently, this example supports the following targets.
1717

1818
### Configure the Project
1919

20-
Set the Button Switch GPIO by changing the `GPIO_INPUT_IO_TOGGLE_SWITCH` definition. By default, the LED_PIN is `GPIO_NUM_9`.
20+
Set the Button Switch GPIO by changing the `GPIO_INPUT_IO_TOGGLE_SWITCH` definition. By default, it's the pin `9` (BOOT button on ESP32-C6 and ESP32-H2).
2121

2222
#### Using Arduino IDE
2323

2424
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
2525

2626
* Before Compile/Verify, select the correct board: `Tools -> Board`.
27-
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator)`.
27+
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`.
2828
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`.
2929
* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port.
3030
* Optional: Set debug level to info to see logs from Zigbee stack: `Tools -> Core Debug Level: Info`.

libraries/Zigbee/examples/Zigbee_Thermostat/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Set the Button GPIO by changing the `BUTTON_PIN` definition. By default, it's th
3535
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
3636

3737
* Before Compile/Verify, select the correct board: `Tools -> Board`.
38-
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator)`.
38+
* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`.
3939
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`.
4040
* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port.
4141
* Optional: Set debug level to info to see logs from Zigbee stack: `Tools -> Core Debug Level: Info`.

libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void setup() {
9393
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode
9494
Zigbee.begin(ZIGBEE_COORDINATOR);
9595

96-
Serial.println("Waiting for Light to bound to the switch");
96+
Serial.println("Waiting for Temperature sensor to bound to the switch");
9797
//Wait for switch to bound to a light:
9898
while(!zbThermostat.is_bound())
9999
{

libraries/Zigbee/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ author=P-R-O-C-H-Y
44
maintainer=Jan Procházka <[email protected]>
55
sentence=Enables zigbee connection with the ESP32
66
paragraph=With this library you can create zigbee end devices, routers, coordinators and connect them to the zigbee network.
7+
category=Communication
78
url=
89
architectures=esp32

libraries/Zigbee/src/Zigbee_core.cpp

+3-26
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
244244
esp_zb_zdo_match_desc_req_param_t cmd_req;
245245
cmd_req.dst_nwk_addr = dev_annce_params->device_short_addr;
246246
cmd_req.addr_of_interest = dev_annce_params->device_short_addr;
247-
log_i("Device capabilities: 0x%02x", dev_annce_params->capability);
247+
log_v("Device capabilities: 0x%02x", dev_annce_params->capability);
248248
/*
249249
capability:
250250
Bit 0 – Alternate PAN Coordinator
@@ -257,8 +257,6 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
257257
Bit 7 – Reserved
258258
*/
259259

260-
//TODO: Save the device short address and endpoint to the list ????????
261-
262260
// for each endpoint in the list call the find_endpoint function if not bounded or allowed to bind multiple devices
263261
for (std::list<Zigbee_EP*>::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) {
264262
if (!(*it)->_is_bound || (*it)->_allow_multiple_binding) {
@@ -278,7 +276,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
278276
}
279277
}
280278
break;
281-
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;
279+
default: log_v("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); break;
282280
}
283281
}
284282

@@ -338,28 +336,6 @@ void Zigbee_Core::scanDelete() {
338336
_scan_status = ZB_SCAN_FAILED;
339337
}
340338

341-
// NOTE: Binding functions to not forget
342-
// void esp_zb_zdo_device_bind_req(esp_zb_zdo_bind_req_param_t *cmd_req, esp_zb_zdo_bind_callback_t user_cb, void *user_ctx)
343-
// {
344-
// uint8_t output = 0;
345-
// uint16_t outlen = sizeof(uint8_t);
346-
347-
// typedef struct {
348-
// esp_zb_zdo_bind_req_param_t bind_req;
349-
// esp_zb_user_cb_t bind_usr;
350-
// } esp_zb_zdo_bind_req_t;
351-
352-
// esp_zb_zdo_bind_req_t zdo_data = {
353-
// .bind_usr = {
354-
// .user_ctx = (uint32_t)user_ctx,
355-
// .user_cb = (uint32_t)user_cb,
356-
// },
357-
// };
358-
359-
// memcpy(&zdo_data.bind_req, cmd_req, sizeof(esp_zb_zdo_bind_req_param_t));
360-
// esp_host_zb_output(ESP_ZNSP_ZDO_BIND_SET, &zdo_data, sizeof(esp_zb_zdo_bind_req_t), &output, &outlen);
361-
// }
362-
363339
// Function to convert enum value to string
364340
const char* Zigbee_Core::getDeviceTypeString(esp_zb_ha_standard_devices_t deviceId) {
365341
switch (deviceId) {
@@ -386,6 +362,7 @@ const char* Zigbee_Core::getDeviceTypeString(esp_zb_ha_standard_devices_t device
386362
case ESP_ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID: return "Color Dimmable Light Device";
387363
case ESP_ZB_HA_DIMMER_SWITCH_DEVICE_ID: return "Dimmer Switch Device";
388364
case ESP_ZB_HA_COLOR_DIMMER_SWITCH_DEVICE_ID: return "Color Dimmer Switch Device";
365+
case ESP_ZB_HA_LIGHT_SENSOR_DEVICE_ID: return "Light Sensor";
389366
case ESP_ZB_HA_SHADE_DEVICE_ID: return "Shade";
390367
case ESP_ZB_HA_SHADE_CONTROLLER_DEVICE_ID: return "Shade controller";
391368
case ESP_ZB_HA_WINDOW_COVERING_DEVICE_ID: return "Window Covering client";

libraries/Zigbee/src/Zigbee_ep.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Zigbee_EP::~Zigbee_EP() {
1818

1919
}
2020

21+
void Zigbee_EP::setVersion(uint8_t version) {
22+
_ep_config.app_device_version = version;
23+
}
24+
2125
void Zigbee_EP::setManufacturerAndModel(const char *name, const char *model) {
2226
// Convert manufacturer to ZCL string
2327
size_t length = strlen(name);
@@ -74,6 +78,14 @@ void Zigbee_EP::readManufacturerAndModel(uint8_t endpoint, uint16_t short_addr)
7478
esp_zb_zcl_read_attr_cmd_req(&read_req);
7579
}
7680

81+
void Zigbee_EP::printBoundDevices() {
82+
log_i("Bound devices:");
83+
for(const auto& device : _bound_devices) {
84+
log_i("Device on endpoint %d, short address: 0x%x", device->endpoint, device->short_addr);
85+
print_ieee_addr(device->ieee_addr);
86+
}
87+
}
88+
7789
void Zigbee_EP::readBasicCluster(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) {
7890
/* Basic cluster attributes */
7991
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) {

libraries/Zigbee/src/Zigbee_ep.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ typedef struct zbstring_s {
3131
} ESP_ZB_PACKED_STRUCT
3232
zbstring_t;
3333

34+
typedef struct zb_device_params_s {
35+
esp_zb_ieee_addr_t ieee_addr;
36+
uint8_t endpoint;
37+
uint16_t short_addr;
38+
} zb_device_params_t;
39+
3440
/* Zigbee End Device Class */
3541
class Zigbee_EP {
3642
public:
@@ -42,19 +48,23 @@ class Zigbee_EP {
4248

4349
static uint8_t _endpoint;
4450
esp_zb_ha_standard_devices_t _device_id; //type of device
45-
uint8_t _version;
4651

4752
esp_zb_endpoint_config_t _ep_config;
4853
esp_zb_cluster_list_t *_cluster_list;
54+
std::list<zb_device_params_t*> _bound_devices;
55+
56+
static bool _is_bound;
4957

5058
// Set ep config and cluster list
5159
void set_ep_config(esp_zb_endpoint_config_t ep_config, esp_zb_cluster_list_t *cluster_list) {
5260
_ep_config = ep_config;
5361
_cluster_list = cluster_list;
5462
}
5563

56-
static bool _is_bound;
64+
void setVersion(uint8_t version);
65+
5766
static bool is_bound() { return _is_bound; }
67+
void printBoundDevices();
5868

5969
static bool _allow_multiple_binding;
6070
static void allowMultipleBinding(bool bind) { _allow_multiple_binding = bind; }
@@ -72,7 +82,4 @@ class Zigbee_EP {
7282
virtual void readBasicCluster(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute); //already implemented
7383

7484
friend class ZigbeeCore;
75-
76-
// List of Zigbee EP classes
77-
friend class ZigbeeLight;
7885
};

libraries/Zigbee/src/ep/ep_color_dimmable_light.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
ZigbeeColorDimmableLight::ZigbeeColorDimmableLight(uint8_t endpoint) : Zigbee_EP(endpoint) {
44
_device_id = ESP_ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID;
5-
_version = 0;
65

76
esp_zb_color_dimmable_light_cfg_t light_cfg = ESP_ZB_DEFAULT_COLOR_DIMMABLE_LIGHT_CONFIG();
87
_cluster_list = esp_zb_color_dimmable_light_clusters_create(&light_cfg);
98
_ep_config = {
109
.endpoint = _endpoint,
1110
.app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
1211
.app_device_id = ESP_ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID,
13-
.app_device_version = _version
12+
.app_device_version = 0
1413
};
1514
}
1615

libraries/Zigbee/src/ep/ep_color_dimmer_switch.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ ZigbeeColorDimmerSwitch* ZigbeeColorDimmerSwitch::_instance = nullptr;
55

66
ZigbeeColorDimmerSwitch::ZigbeeColorDimmerSwitch(uint8_t endpoint) : Zigbee_EP(endpoint) {
77
_device_id = ESP_ZB_HA_COLOR_DIMMER_SWITCH_DEVICE_ID;
8-
_version = 0;
9-
108
_instance = this; // Set the static pointer to this instance
119

1210
esp_zb_color_dimmable_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_COLOR_DIMMABLE_SWITCH_CONFIG();
@@ -16,7 +14,7 @@ ZigbeeColorDimmerSwitch::ZigbeeColorDimmerSwitch(uint8_t endpoint) : Zigbee_EP(e
1614
.endpoint = _endpoint,
1715
.app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
1816
.app_device_id = ESP_ZB_HA_COLOR_DIMMER_SWITCH_DEVICE_ID,
19-
.app_device_version = _version
17+
.app_device_version = 0
2018
};
2119
}
2220

@@ -42,27 +40,29 @@ void ZigbeeColorDimmerSwitch::bind_cb(esp_zb_zdp_status_t zdo_status, void *user
4240
if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
4341
log_i("Bound successfully!");
4442
if (user_ctx) {
45-
light_bulb_device_params_t *light = (light_bulb_device_params_t *)user_ctx;
43+
zb_device_params_t *light = (zb_device_params_t *)user_ctx;
4644
//Read manufacturer and model automatically after successful bind
4745
_instance->readManufacturerAndModel(light->endpoint, light->short_addr);
4846
log_i("The light originating from address(0x%x) on endpoint(%d)", light->short_addr, light->endpoint);
4947
//TODO: call user method to notify about the light and pass all the info ????
50-
_instance->_bound_lights.push_back(light);
48+
_instance->_bound_devices.push_back(light);
5149
}
5250
_is_bound = true;
51+
} else {
52+
log_e("Binding failed!");
5353
}
5454
}
5555

5656
void ZigbeeColorDimmerSwitch::find_cb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) {
5757
if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
5858
log_d("Found light endpoint");
5959
esp_zb_zdo_bind_req_param_t bind_req;
60-
light_bulb_device_params_t *light = (light_bulb_device_params_t *)malloc(sizeof(light_bulb_device_params_t));
60+
zb_device_params_t *light = (zb_device_params_t *)malloc(sizeof(zb_device_params_t));
6161
light->endpoint = endpoint;
6262
light->short_addr = addr;
6363
esp_zb_ieee_address_by_short(light->short_addr, light->ieee_addr);
6464
esp_zb_get_long_address(bind_req.src_address);
65-
bind_req.src_endp = _endpoint; //_dev_endpoint;
65+
bind_req.src_endp = _endpoint;
6666
bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF;
6767
bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED;
6868
memcpy(bind_req.dst_address_u.addr_long, light->ieee_addr, sizeof(esp_zb_ieee_addr_t));
@@ -93,18 +93,9 @@ void ZigbeeColorDimmerSwitch::find_endpoint(esp_zb_zdo_match_desc_req_param_t *c
9393
.num_out_clusters = 3,
9494
.cluster_list = cluster_list,
9595
};
96-
//esp_zb_zdo_find_color_dimmable_light(&cmd_req, user_find_cb, NULL);
9796
esp_zb_zdo_match_cluster(&color_dimmable_light_req, find_cb, NULL);
9897
}
9998

100-
void ZigbeeColorDimmerSwitch::printBoundLights() {
101-
log_i("Bound lights:");
102-
for(const auto& light : _bound_lights) {
103-
log_i("Light on endpoint %d, short address: 0x%x", light->endpoint, light->short_addr);
104-
print_ieee_addr(light->ieee_addr);
105-
}
106-
}
107-
10899
// Methods to control the light
109100
void ZigbeeColorDimmerSwitch::lightToggle() {
110101
if (_is_bound) {

libraries/Zigbee/src/ep/ep_color_dimmer_switch.h

-21
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
#include "Zigbee_ep.h"
66
#include "ha/esp_zigbee_ha_standard.h"
77

8-
typedef struct light_bulb_device_params_s {
9-
esp_zb_ieee_addr_t ieee_addr;
10-
uint8_t endpoint;
11-
uint16_t short_addr;
12-
} light_bulb_device_params_t;
13-
148
class ZigbeeColorDimmerSwitch : public Zigbee_EP {
159
public:
1610
ZigbeeColorDimmerSwitch(uint8_t endpoint);
@@ -19,10 +13,6 @@ class ZigbeeColorDimmerSwitch : public Zigbee_EP {
1913
// save instance of the class in order to use it in static functions
2014
static ZigbeeColorDimmerSwitch* _instance;
2115

22-
// list of bounded lights
23-
std::list<light_bulb_device_params_t*> _bound_lights;
24-
void printBoundLights();
25-
2616
void calculateXY(uint8_t red, uint8_t green, uint8_t blue, uint16_t &x, uint16_t &y);
2717

2818
// methods to control the color dimmable light
@@ -64,14 +54,3 @@ class ZigbeeColorDimmerSwitch : public Zigbee_EP {
6454
static void find_cb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx);
6555

6656
};
67-
68-
//NOTE:
69-
/* ON/OFF switch commands for light control */
70-
// typedef enum {
71-
// ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID = 0x00, /*!< "Turn off" command. */
72-
// ESP_ZB_ZCL_CMD_ON_OFF_ON_ID = 0x01, /*!< "Turn on" command. */
73-
// ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID = 0x02, /*!< "Toggle state" command. */
74-
// ESP_ZB_ZCL_CMD_ON_OFF_OFF_WITH_EFFECT_ID = 0x40, /*!< "Off with effect" command. */
75-
// ESP_ZB_ZCL_CMD_ON_OFF_ON_WITH_RECALL_GLOBAL_SCENE_ID = 0x41, /*!< "On with recall global scene" command. */
76-
// ESP_ZB_ZCL_CMD_ON_OFF_ON_WITH_TIMED_OFF_ID = 0x42, /*!< "On with timed off" command. */
77-
// } esp_zb_zcl_on_off_cmd_id_t;

libraries/Zigbee/src/ep/ep_on_off_light.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
ZigbeeLight::ZigbeeLight(uint8_t endpoint) : Zigbee_EP(endpoint) {
44
_device_id = ESP_ZB_HA_ON_OFF_LIGHT_DEVICE_ID;
5-
_version = 0;
65

76
esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG();
87
_cluster_list = esp_zb_on_off_light_clusters_create(&light_cfg); // use esp_zb_zcl_cluster_list_create() instead of esp_zb_on_off_light_clusters_create()
98
_ep_config = {
109
.endpoint = _endpoint,
1110
.app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
1211
.app_device_id = ESP_ZB_HA_ON_OFF_LIGHT_DEVICE_ID,
13-
.app_device_version = _version
12+
.app_device_version = 0
1413
};
1514
}
1615

0 commit comments

Comments
 (0)