Skip to content

Commit 8a0f8df

Browse files
refactor(zigbee): changed class name to ZigbeeIlluminanceSensor
1 parent 6d7b544 commit 8a0f8df

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

libraries/Zigbee/examples/Zigbee_Light_Sensor/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Arduino-ESP32 Zigbee Light Sensor Sleepy Device Example
1+
# Arduino-ESP32 Zigbee Illuminance Sensor Example
22

3-
This example demonstrates how to use the Zigbee library to create an end device light sensor and use it as a Home Automation (HA) extended light sensor.
3+
This example demonstrates how to use the Zigbee library to create an end device illuminance sensor and use it as a Home Automation (HA) extended illuminance sensor.
44

55
# Supported Targets
66

@@ -9,9 +9,9 @@ Currently, this example supports the following targets.
99
| Supported Targets | ESP32-C6 | ESP32-H2 |
1010
| ----------------- | -------- | -------- |
1111

12-
## Light Sensor Functions
12+
## Illuminance Sensor Functions
1313

14-
1. Initialize a Zigbee light sensor.
14+
1. Initialize a Zigbee illuminance sensor.
1515
2. Measure illuminance value.
1616
3. Report the measured value to the Zigbee network.
1717

@@ -25,7 +25,7 @@ Currently, this example supports the following targets.
2525

2626
In this example the raw analog value of a light sensor is used to calculate illuminance.
2727
Alter the calculation according to your use case and calibrate it to receive correct lux values.
28-
Set the light sensor GPIO by changing the `light_sensor_pin` variable to the pin to the pin to which your sensor is connected.
28+
Set the illuminance sensor GPIO by changing the `illuminance_sensor_pin` variable to the pin to the pin to which your sensor is connected.
2929
Set the button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (BOOT button on ESP32-C6 and ESP32-H2).
3030

3131
#### Using Arduino IDE

libraries/Zigbee/examples/Zigbee_Light_Sensor/Zigbee_Light_Sensor.ino renamed to libraries/Zigbee/examples/Zigbee_Light_Sensor/Zigbee_Illuminance_Sensor.ino

+24-24
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
// limitations under the License.
1414

1515
/**
16-
* @brief This example demonstrates Zigbee light sensor.
16+
* @brief This example demonstrates Zigbee illuminance sensor.
1717
*
18-
* The example demonstrates how to use Zigbee library to create a end device light sensor.
19-
* The light sensor is a Zigbee end device, which is controlled by a Zigbee coordinator.
18+
* The example demonstrates how to use Zigbee library to create a end device illuminance sensor.
19+
* The illuminance sensor is a Zigbee end device, which is controlled by a Zigbee coordinator.
2020
*
2121
* Proper Zigbee mode must be selected in Tools->Zigbee mode
2222
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
@@ -32,31 +32,31 @@
3232

3333
#include "Zigbee.h"
3434

35-
#define ZIGBEE_LIGHT_SENSOR_ENDPOINT 9
35+
#define ZIGBEE_ILLUMINANCE_SENSOR_ENDPOINT 9
3636
uint8_t button = BOOT_PIN;
37-
uint8_t light_sensor_pin = 6; // Insert the analog pin to which the sensor (e.g. photoresistor) is connected
37+
uint8_t illuminance_sensor_pin = 6; // Insert the analog pin to which the sensor (e.g. photoresistor) is connected
3838

39-
ZigbeeLightSensor zbLightSensor = ZigbeeLightSensor(ZIGBEE_LIGHT_SENSOR_ENDPOINT);
39+
ZigbeeIlluminanceSensor zbIlluminanceSensor = ZigbeeIlluminanceSensor(ZIGBEE_ILLUMINANCE_SENSOR_ENDPOINT);
4040

41-
/********************* Light sensor **************************/
42-
static void light_sensor_value_update(void *arg) {
41+
/********************* Illuminance sensor **************************/
42+
static void illuminance_sensor_value_update(void *arg) {
4343
for (;;) {
4444
// read the raw analog value from the sensor
45-
int lsens_analog_raw = analogRead(light_sensor_pin);
46-
Serial.printf("[Light Sensor] raw analog value: %d\r\n", lsens_analog_raw);
45+
int lsens_analog_raw = analogRead(illuminance_sensor_pin);
46+
Serial.printf("[Illuminance Sensor] raw analog value: %d\r\n", lsens_analog_raw);
4747

4848
// conversion into zigbee raw illuminance value (typically between 0 in darkness and 50000 in direct sunlight)
4949
// depends on the value range of the raw analog sensor values and will need calibration for correct lux values
5050
int lsens_illuminance_raw = lsens_analog_raw * 10; // multiply by 10 for the sake of this example
51-
Serial.printf("[Light Sensor] raw illuminance value: %d\r\n", lsens_illuminance_raw);
51+
Serial.printf("[Illuminance Sensor] raw illuminance value: %d\r\n", lsens_illuminance_raw);
5252

5353
// according to zigbee documentation the formular 10^(lsens_illuminance_raw/10000)-1 can be used to calculate lux value from raw illuminance value
5454
// Note: Zigbee2MQTT seems to be using the formular 10^(lsens_illuminance_raw/10000) instead (without -1)
5555
int lsens_illuminance_lux = round(pow(10,(lsens_illuminance_raw / 10000.0))-1);
56-
Serial.printf("[Light Sensor] lux value: %d lux\r\n", lsens_illuminance_lux);
56+
Serial.printf("[Illuminance Sensor] lux value: %d lux\r\n", lsens_illuminance_lux);
5757

58-
// Update illuminance in light sensor EP
59-
zbLightSensor.setIlluminance(lsens_illuminance_raw); // use raw illuminance here!
58+
// Update illuminance in illuminance sensor EP
59+
zbIlluminanceSensor.setIlluminance(lsens_illuminance_raw); // use raw illuminance here!
6060

6161
delay(1000); // reduce delay (in ms), if you want your device to react more quickly to changes in illuminance
6262
}
@@ -74,20 +74,20 @@
7474
pinMode(button, INPUT_PULLUP);
7575

7676
// Optional: Set Zigbee device name and model
77-
zbLightSensor.setManufacturerAndModel("Espressif", "ZigbeeLightSensor");
77+
zbIlluminanceSensor.setManufacturerAndModel("Espressif", "ZigbeeIlluminanceSensor");
7878

7979
// Optional: Set power source (choose between ZB_POWER_SOURCE_MAINS and ZB_POWER_SOURCE_BATTERY), defaults to unknown
80-
zbLightSensor.setPowerSource(ZB_POWER_SOURCE_MAINS);
80+
zbIlluminanceSensor.setPowerSource(ZB_POWER_SOURCE_MAINS);
8181

8282
// Set minimum and maximum for raw illuminance value (0 min and 50000 max equals to 0 lux - 100,000 lux)
83-
zbLightSensor.setMinMaxValue(0, 50000);
83+
zbIlluminanceSensor.setMinMaxValue(0, 50000);
8484

8585
// Optional: Set tolerance for raw illuminance value
86-
zbLightSensor.setTolerance(1);
86+
zbIlluminanceSensor.setTolerance(1);
8787

8888
// Add endpoint to Zigbee Core
89-
Serial.println("Adding Zigbee light sensor endpoint to Zigbee Core");
90-
Zigbee.addEndpoint(&zbLightSensor);
89+
Serial.println("Adding Zigbee illuminance sensor endpoint to Zigbee Core");
90+
Zigbee.addEndpoint(&zbIlluminanceSensor);
9191

9292
Serial.println("Starting Zigbee...");
9393
// When all EPs are registered, start Zigbee in End Device mode
@@ -105,16 +105,16 @@
105105
}
106106
Serial.println();
107107

108-
// Start light sensor reading task
109-
xTaskCreate(light_sensor_value_update, "light_sensor_update", 2048, NULL, 10, NULL);
108+
// Start illuminance sensor reading task
109+
xTaskCreate(illuminance_sensor_value_update, "illuminance_sensor_update", 2048, NULL, 10, NULL);
110110

111111
// Set reporting schedule for illuminance value measurement in seconds, must be called after Zigbee.begin()
112112
// min_interval and max_interval in seconds, delta
113113
// if min = 1 and max = 0, delta = 1000, reporting is sent when raw illuminance value changes by 1000, but at most once per second
114114
// if min = 0 and max = 10, delta = 1000, reporting is sent every 10 seconds or if raw illuminance value changes by 1000
115115
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of illuminance change
116116
// Note: On pairing with Zigbee Home Automation or Zigbee2MQTT the reporting schedule will most likely be overwritten with their default settings
117-
zbLightSensor.setReporting(1, 0, 1000);
117+
zbIlluminanceSensor.setReporting(1, 0, 1000);
118118
}
119119

120120
/********************* Main loop **************************/
@@ -134,7 +134,7 @@
134134
}
135135
}
136136
// force report of illuminance when button is pressed
137-
zbLightSensor.reportIlluminance();
137+
zbIlluminanceSensor.reportIlluminance();
138138
}
139139
delay(100);
140140
}

libraries/Zigbee/keywords.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ZigbeeGateway KEYWORD1
2929
ZigbeeRangeExtender KEYWORD1
3030
ZigbeeVibrationSensor KEYWORD1
3131
ZigbeeWindowCovering KEYWORD1
32-
ZigbeeLightSensor KEYWORD1
32+
ZigbeeIlluminanceSensor KEYWORD1
3333

3434
# Other
3535
zigbee_role_t KEYWORD1
@@ -125,8 +125,8 @@ setHumidityReporting KEYWORD2
125125
reportHumidity KEYWORD2
126126

127127
# ZigbeeLightSensor
128-
setLightValue KEYWORD2
129-
reportLightValue KEYWORD2
128+
setIlluminance KEYWORD2
129+
reportIlluminance KEYWORD2
130130

131131
# ZigbeeFlowSensor
132132
setFlow KEYWORD2

libraries/Zigbee/src/Zigbee.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "ep/ZigbeeAnalog.h"
1919
#include "ep/ZigbeeFlowSensor.h"
2020
#include "ep/ZigbeeOccupancySensor.h"
21-
#include "ep/ZigbeeLightSensor.h"
21+
#include "ep/ZigbeeIlluminanceSensor.h"
2222
#include "ep/ZigbeeCarbonDioxideSensor.h"
2323
#include "ep/ZigbeeContactSwitch.h"
2424
#include "ep/ZigbeeDoorWindowHandle.h"

libraries/Zigbee/src/ep/ZigbeeLightSensor.cpp renamed to libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "ZigbeeLightSensor.h"
1+
#include "ZigbeeIlluminanceSensor.h"
22
#if CONFIG_ZB_ENABLED
33

4-
ZigbeeLightSensor::ZigbeeLightSensor(uint8_t endpoint) : ZigbeeEP(endpoint) {
4+
ZigbeeIlluminanceSensor::ZigbeeIlluminanceSensor(uint8_t endpoint) : ZigbeeEP(endpoint) {
55
_device_id = ESP_ZB_HA_LIGHT_SENSOR_DEVICE_ID;
66

77
esp_zb_light_sensor_cfg_t light_sensor_cfg = ESP_ZB_DEFAULT_LIGHT_SENSOR_CONFIG();
@@ -16,7 +16,7 @@ static int16_t zb_int_to_s16(int value) {
1616
return (int16_t) value;
1717
}
1818

19-
void ZigbeeLightSensor::setMinMaxValue(int min, int max) {
19+
void ZigbeeIlluminanceSensor::setMinMaxValue(int min, int max) {
2020
int16_t zb_min = zb_int_to_s16(min);
2121
int16_t zb_max = zb_int_to_s16(max);
2222
esp_zb_attribute_list_t *light_measure_cluster =
@@ -25,14 +25,14 @@ void ZigbeeLightSensor::setMinMaxValue(int min, int max) {
2525
esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&zb_max);
2626
}
2727

28-
void ZigbeeLightSensor::setTolerance(int tolerance) {
28+
void ZigbeeIlluminanceSensor::setTolerance(int tolerance) {
2929
uint16_t zb_tolerance = (uint16_t) tolerance;
3030
esp_zb_attribute_list_t *light_measure_cluster =
3131
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
3232
esp_zb_illuminance_meas_cluster_add_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_TOLERANCE_ID, (void *)&zb_tolerance);
3333
}
3434

35-
void ZigbeeLightSensor::setReporting(uint16_t min_interval, uint16_t max_interval, int delta) {
35+
void ZigbeeIlluminanceSensor::setReporting(uint16_t min_interval, uint16_t max_interval, int delta) {
3636
esp_zb_zcl_reporting_info_t reporting_info;
3737
memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t));
3838
reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV;
@@ -52,10 +52,10 @@ void ZigbeeLightSensor::setReporting(uint16_t min_interval, uint16_t max_interva
5252
esp_zb_lock_release();
5353
}
5454

55-
void ZigbeeLightSensor::setIlluminance(int illuminanceValue) {
55+
void ZigbeeIlluminanceSensor::setIlluminance(int illuminanceValue) {
5656
int16_t zb_illuminanceValue = zb_int_to_s16(illuminanceValue);
5757
log_v("Updating Illuminance...");
58-
/* Update light sensor measured illuminance */
58+
/* Update illuminance sensor measured illuminance */
5959
log_d("Setting Illuminance to %d", zb_illuminanceValue);
6060
esp_zb_lock_acquire(portMAX_DELAY);
6161
esp_zb_zcl_set_attribute_val(
@@ -64,7 +64,7 @@ void ZigbeeLightSensor::setIlluminance(int illuminanceValue) {
6464
esp_zb_lock_release();
6565
}
6666

67-
void ZigbeeLightSensor::reportIlluminance() {
67+
void ZigbeeIlluminanceSensor::reportIlluminance() {
6868
/* Send report attributes command */
6969
esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
7070
report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;

libraries/Zigbee/src/ep/ZigbeeLightSensor.h renamed to libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Class of Zigbee Light sensor endpoint inherited from common EP class */
1+
/* Class of Zigbee Illuminance sensor endpoint inherited from common EP class */
22

33
#pragma once
44

@@ -13,7 +13,7 @@
1313
the new macro works here, but should better be added to
1414
esp-zigbee-sdk/components/esp-zigbee-lib/include/ha/esp_zigbee_ha_standard.h
1515
*/
16-
#define ESP_ZB_DEFAULT_LIGHT_SENSOR_CONFIG() \
16+
#define ESP_ZB_DEFAULT_LIGHT_SENSOR_CONFIG() \
1717
{ \
1818
.basic_cfg = \
1919
{ \
@@ -36,24 +36,24 @@ esp-zigbee-sdk/components/esp-zigbee-lib/include/ha/esp_zigbee_ha_standard.h
3636
}, \
3737
}
3838

39-
class ZigbeeLightSensor : public ZigbeeEP {
39+
class ZigbeeIlluminanceSensor : public ZigbeeEP {
4040
public:
41-
ZigbeeLightSensor(uint8_t endpoint);
42-
~ZigbeeLightSensor() {}
41+
ZigbeeIlluminanceSensor(uint8_t endpoint);
42+
~ZigbeeIlluminanceSensor() {}
4343

44-
// Set the light value
44+
// Set the illuminance value
4545
void setIlluminance(int value);
4646

47-
// Set the min and max value for the light sensor
47+
// Set the min and max value for the illuminance sensor
4848
void setMinMaxValue(int min, int max);
4949

50-
// Set the tolerance value for the light sensor
50+
// Set the tolerance value for the illuminance sensor
5151
void setTolerance(int tolerance);
5252

53-
// Set the reporting interval for light measurement in seconds and delta
53+
// Set the reporting interval for illuminance measurement in seconds and delta
5454
void setReporting(uint16_t min_interval, uint16_t max_interval, int delta);
5555

56-
// Report the light value
56+
// Report the illuminance value
5757
void reportIlluminance();
5858
};
5959

0 commit comments

Comments
 (0)