Skip to content

Commit cb288b7

Browse files
authored
Merge branch 'espressif:master' into master
2 parents 1040ccd + b333bf2 commit cb288b7

File tree

10 files changed

+433
-37
lines changed

10 files changed

+433
-37
lines changed

Diff for: CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
300300
libraries/Zigbee/src/ep/ZigbeeGateway.cpp
301301
libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp
302302
libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp
303+
libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp
303304
)
304305

305306
set(ARDUINO_LIBRARY_BLE_SRCS

Diff for: cores/esp32/esp32-hal-rmt.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t freque
206206
log_w("GPIO %d - RMT Carrier must be a float percentage from 0 to 1. Setting to 50%.", pin);
207207
duty_percent = 0.5;
208208
}
209-
rmt_carrier_config_t carrier_cfg = {0};
209+
rmt_carrier_config_t carrier_cfg;
210+
memset((void *)&carrier_cfg, 0, sizeof(rmt_carrier_config_t));
210211
carrier_cfg.duty_cycle = duty_percent; // duty cycle
211212
carrier_cfg.frequency_hz = carrier_en ? frequency_Hz : 0; // carrier frequency in Hz
212213
carrier_cfg.flags.polarity_active_low = carrier_level; // carrier modulation polarity level
@@ -313,7 +314,8 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl
313314
return false;
314315
}
315316

316-
rmt_transmit_config_t transmit_cfg = {0}; // loop mode disabled
317+
rmt_transmit_config_t transmit_cfg; // loop mode disabled
318+
memset((void *)&transmit_cfg, 0, sizeof(rmt_transmit_config_t));
317319
bool retCode = true;
318320

319321
RMT_MUTEX_LOCK(bus);
@@ -380,6 +382,7 @@ static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool wa
380382

381383
// request reading RMT Channel Data
382384
rmt_receive_config_t receive_config;
385+
memset((void *)&receive_config, 0, sizeof(rmt_receive_config_t));
383386
receive_config.signal_range_min_ns = bus->signal_range_min_ns;
384387
receive_config.signal_range_max_ns = bus->signal_range_max_ns;
385388

@@ -530,6 +533,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
530533
if (channel_direction == RMT_TX_MODE) {
531534
// TX Channel
532535
rmt_tx_channel_config_t tx_cfg;
536+
memset((void *)&tx_cfg, 0, sizeof(rmt_tx_channel_config_t));
533537
tx_cfg.gpio_num = pin;
534538
// CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F80M for C6 -- CLK_XTAL for H2
535539
tx_cfg.clk_src = RMT_CLK_SRC_DEFAULT;
@@ -559,6 +563,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
559563
} else {
560564
// RX Channel
561565
rmt_rx_channel_config_t rx_cfg;
566+
memset((void *)&rx_cfg, 0, sizeof(rmt_rx_channel_config_t));
562567
rx_cfg.gpio_num = pin;
563568
// CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F80M for C6 -- CLK_XTAL for H2
564569
rx_cfg.clk_src = RMT_CLK_SRC_DEFAULT;
@@ -585,7 +590,8 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_
585590
}
586591

587592
// allocate memory for the RMT Copy encoder
588-
rmt_copy_encoder_config_t copy_encoder_config = {};
593+
rmt_copy_encoder_config_t copy_encoder_config;
594+
memset((void *)&copy_encoder_config, 0, sizeof(rmt_copy_encoder_config_t));
589595
if (rmt_new_copy_encoder(&copy_encoder_config, &bus->rmt_copy_encoder_h) != ESP_OK) {
590596
log_e("GPIO %d - RMT Encoder Memory Allocation error.", pin);
591597
goto Err;
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Arduino-ESP32 PM2.5 Sensor
2+
3+
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) simple sensor device type with particulate matter (PM2.5) measuring
4+
5+
# Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets | ESP32-C6 | ESP32-H2 |
10+
| ----------------- | -------- | -------- |
11+
12+
## Pressure + Flow Sensor Functions
13+
14+
* After this board first starts up, it would be configured locally to report the PM2.5 on every 30 seconds.
15+
* By clicking the button (BOOT) on this board, this board will immediately send a report of the current PM2.5 to the network.
16+
17+
## Hardware Required
18+
19+
* A USB cable for power supply and programming
20+
21+
### Configure the Project
22+
23+
In this example, the internal temperature sensor is used to demonstrate reading of the PM2.5 sensors.
24+
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).
25+
26+
#### Using Arduino IDE
27+
28+
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
29+
30+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
31+
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
32+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
33+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
34+
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`.
35+
36+
## Troubleshooting
37+
38+
If the End device flashed with this example 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.
39+
You can do the following:
40+
41+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
42+
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.
43+
44+
By default, the coordinator network is closed after rebooting or flashing new firmware.
45+
To open the network you have 2 options:
46+
47+
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
48+
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
49+
50+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
51+
52+
* **LED not blinking:** Check the wiring connection and the IO selection.
53+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
54+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
55+
56+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
57+
58+
## Contribute
59+
60+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
61+
62+
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!
63+
64+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
65+
66+
## Resources
67+
68+
* Official ESP32 Forum: [Link](https://esp32.com)
69+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
70+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
71+
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
72+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @brief This example demonstrates Zigbee PM2.5 sensor.
17+
*
18+
* The example demonstrates how to use Zigbee library to create a end device PM2.5 sensor.
19+
*
20+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
21+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
22+
*
23+
* Please check the README.md for instructions and more detailed description.
24+
*
25+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
26+
*/
27+
28+
#ifndef ZIGBEE_MODE_ED
29+
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
30+
#endif
31+
32+
#include "Zigbee.h"
33+
34+
/* Zigbee PM2.5 sensor configuration */
35+
#define PM2_5_SENSOR_ENDPOINT_NUMBER 1
36+
uint8_t button = BOOT_PIN;
37+
38+
ZigbeePM25Sensor zbPM25Sensor = ZigbeePM25Sensor(PM2_5_SENSOR_ENDPOINT_NUMBER);
39+
40+
void setup() {
41+
Serial.begin(115200);
42+
43+
// Init button switch
44+
pinMode(button, INPUT_PULLUP);
45+
46+
// Optional: set Zigbee device name and model
47+
zbPM25Sensor.setManufacturerAndModel("Espressif", "ZigbeePM25Sensor");
48+
49+
// Set minimum and maximum PM2.5 measurement value in µg/m³
50+
zbPM25Sensor.setMinMaxValue(0, 350);
51+
52+
// Set tolerance for PM2.5 measurement in µg/m³
53+
zbPM25Sensor.setTolerance(0.1);
54+
55+
// Add endpoints to Zigbee Core
56+
Zigbee.addEndpoint(&zbPM25Sensor);
57+
58+
Serial.println("Starting Zigbee...");
59+
// When all EPs are registered, start Zigbee in End Device mode
60+
if (!Zigbee.begin()) {
61+
Serial.println("Zigbee failed to start!");
62+
Serial.println("Rebooting...");
63+
ESP.restart();
64+
} else {
65+
Serial.println("Zigbee started successfully!");
66+
}
67+
Serial.println("Connecting to network");
68+
while (!Zigbee.connected()) {
69+
Serial.print(".");
70+
delay(100);
71+
}
72+
Serial.println();
73+
74+
// Set reporting interval for PM2.5 measurement to be done every 30 seconds, must be called after Zigbee.begin()
75+
// min_interval and max_interval in seconds, delta (PM2.5 change in µg/m³)
76+
// if min = 1 and max = 0, reporting is sent only when PM2.5 changes by delta
77+
// if min = 0 and max = 10, reporting is sent every 10 seconds or when PM2.5 changes by delta
78+
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of delta change
79+
zbPM25Sensor.setReporting(0, 30, 0);
80+
}
81+
82+
void loop() {
83+
static uint32_t timeCounter = 0;
84+
// Read PM2.5 sensor every 2s
85+
if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s
86+
// Read sensor value - here is chip temperature used + 50 as a dummy value for demonstration
87+
float pm25_value = 50.5 + temperatureRead();
88+
Serial.printf("Updating PM2.5 sensor value to %0.1f µg/m³\r\n", pm25_value);
89+
zbPM25Sensor.setPM25(pm25_value);
90+
}
91+
92+
// Checking button for factory reset and reporting
93+
if (digitalRead(button) == LOW) { // Push button pressed
94+
// Key debounce handling
95+
delay(100);
96+
int startTime = millis();
97+
while (digitalRead(button) == LOW) {
98+
delay(50);
99+
if ((millis() - startTime) > 3000) {
100+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
101+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
102+
delay(1000);
103+
Zigbee.factoryReset();
104+
}
105+
}
106+
zbPM25Sensor.report();
107+
}
108+
delay(100);
109+
}

Diff for: libraries/Zigbee/examples/Zigbee_PM25_Sensor/ci.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
3+
"requires": [
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
6+
]
7+
}

Diff for: libraries/Zigbee/src/Zigbee.h

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@
77
#include "ZigbeeEP.h"
88

99
// Endpoints
10-
#include "ep/ZigbeeLight.h"
10+
//// Switches
11+
#include "ep/ZigbeeColorDimmerSwitch.h"
1112
#include "ep/ZigbeeSwitch.h"
12-
#include "ep/ZigbeeDimmableLight.h"
13+
//// Lights
1314
#include "ep/ZigbeeColorDimmableLight.h"
14-
#include "ep/ZigbeeColorDimmerSwitch.h"
15-
#include "ep/ZigbeeTempSensor.h"
15+
#include "ep/ZigbeeDimmableLight.h"
16+
#include "ep/ZigbeeLight.h"
17+
//// Controllers
1618
#include "ep/ZigbeeThermostat.h"
17-
#include "ep/ZigbeePressureSensor.h"
19+
//// Sensors
1820
#include "ep/ZigbeeAnalog.h"
19-
#include "ep/ZigbeeFlowSensor.h"
20-
#include "ep/ZigbeeOccupancySensor.h"
21-
#include "ep/ZigbeeIlluminanceSensor.h"
2221
#include "ep/ZigbeeCarbonDioxideSensor.h"
2322
#include "ep/ZigbeeContactSwitch.h"
2423
#include "ep/ZigbeeDoorWindowHandle.h"
25-
#include "ep/ZigbeeWindowCovering.h"
24+
#include "ep/ZigbeeFlowSensor.h"
25+
#include "ep/ZigbeeIlluminanceSensor.h"
26+
#include "ep/ZigbeeOccupancySensor.h"
27+
#include "ep/ZigbeePM25Sensor.h"
28+
#include "ep/ZigbeePressureSensor.h"
29+
#include "ep/ZigbeeTempSensor.h"
2630
#include "ep/ZigbeeVibrationSensor.h"
27-
#include "ep/ZigbeeRangeExtender.h"
28-
#include "ep/ZigbeeGateway.h"
2931
#include "ep/ZigbeeWindSpeedSensor.h"
32+
#include "ep/ZigbeeWindowCovering.h"
33+
//// Other
34+
#include "ep/ZigbeeGateway.h"
35+
#include "ep/ZigbeeRangeExtender.h"

0 commit comments

Comments
 (0)