copied code from examples
This commit is contained in:
parent
94c6328747
commit
ef272dbe4e
3 changed files with 222 additions and 0 deletions
79
esp32h2_water_temp_pump/README.md
Normal file
79
esp32h2_water_temp_pump/README.md
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
# Arduino-ESP32 Zigbee Temperature Sensor Example
|
||||||
|
|
||||||
|
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) temperature sensor.
|
||||||
|
|
||||||
|
# Supported Targets
|
||||||
|
|
||||||
|
Currently, this example supports the following targets.
|
||||||
|
|
||||||
|
| Supported Targets | ESP32-C6 | ESP32-H2 |
|
||||||
|
| ----------------- | -------- | -------- |
|
||||||
|
|
||||||
|
## Temperature Sensor Functions
|
||||||
|
|
||||||
|
Note:
|
||||||
|
* This board means the board (e.g. ESP32-H2 / C6) loaded with `Zigbee_Temperature_Sensor` example.
|
||||||
|
* The remote board means the board (e.g. ESP32-H2 / C6) loaded with `Zigbee_Thermostat` example.
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
* After this board first starts up, it would be configured locally to report the temperature on 1 degree change and no periodic reporting to the remote board.
|
||||||
|
* By clicking the button (BOOT) on this board, this board will immediately send a report of the current measured temperature to the remote board.
|
||||||
|
|
||||||
|
## Hardware Required
|
||||||
|
|
||||||
|
* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee coordinator (loaded with `Zigbee_Thermostat` example)
|
||||||
|
* A USB cable for power supply and programming
|
||||||
|
* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee end device and upload the `Zigbee_Temperature_Sensor` example
|
||||||
|
|
||||||
|
### Configure the Project
|
||||||
|
|
||||||
|
In this example, the internal temperature sensor task is reading the chip temperature.
|
||||||
|
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).
|
||||||
|
|
||||||
|
#### Using Arduino IDE
|
||||||
|
|
||||||
|
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
|
||||||
|
|
||||||
|
* Before Compile/Verify, select the correct board: `Tools -> Board`.
|
||||||
|
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)`
|
||||||
|
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`
|
||||||
|
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
|
||||||
|
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
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.
|
||||||
|
You can do the following:
|
||||||
|
|
||||||
|
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
|
||||||
|
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.
|
||||||
|
|
||||||
|
By default, the coordinator network is closed after rebooting or flashing new firmware.
|
||||||
|
To open the network you have 2 options:
|
||||||
|
|
||||||
|
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
|
||||||
|
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
|
||||||
|
|
||||||
|
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
|
||||||
|
|
||||||
|
* **LED not blinking:** Check the wiring connection and the IO selection.
|
||||||
|
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
|
||||||
|
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
|
||||||
|
|
||||||
|
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
|
||||||
|
|
||||||
|
## Contribute
|
||||||
|
|
||||||
|
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
* Official ESP32 Forum: [Link](https://esp32.com)
|
||||||
|
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||||
|
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
|
||||||
|
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
|
||||||
|
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
|
||||||
5
esp32h2_water_temp_pump/ci.yml
Normal file
5
esp32h2_water_temp_pump/ci.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
fqbn_append: PartitionScheme=zigbee,ZigbeeMode=ed
|
||||||
|
|
||||||
|
requires:
|
||||||
|
- CONFIG_SOC_IEEE802154_SUPPORTED=y
|
||||||
|
- CONFIG_ZB_ENABLED=y
|
||||||
138
esp32h2_water_temp_pump/esp32h2_water_temp_pump.ino
Normal file
138
esp32h2_water_temp_pump/esp32h2_water_temp_pump.ino
Normal file
|
|
@ -0,0 +1,138 @@
|
||||||
|
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This example demonstrates Zigbee temperature sensor.
|
||||||
|
*
|
||||||
|
* The example demonstrates how to use Zigbee library to create a end device temperature sensor.
|
||||||
|
* The temperature sensor is a Zigbee end device, which is controlled by a Zigbee coordinator.
|
||||||
|
*
|
||||||
|
* Proper Zigbee mode must be selected in Tools->Zigbee mode
|
||||||
|
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
|
||||||
|
*
|
||||||
|
* Please check the README.md for instructions and more detailed description.
|
||||||
|
*
|
||||||
|
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZIGBEE_MODE_ED
|
||||||
|
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Zigbee.h"
|
||||||
|
|
||||||
|
/* Zigbee temperature sensor configuration */
|
||||||
|
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
|
||||||
|
uint8_t button = BOOT_PIN;
|
||||||
|
|
||||||
|
// Optional Time cluster variables
|
||||||
|
struct tm timeinfo;
|
||||||
|
struct tm *localTime;
|
||||||
|
int32_t timezone;
|
||||||
|
|
||||||
|
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
|
||||||
|
|
||||||
|
/************************ Temp sensor *****************************/
|
||||||
|
static void temp_sensor_value_update(void *arg) {
|
||||||
|
for (;;) {
|
||||||
|
// Read temperature sensor value
|
||||||
|
float tsens_value = temperatureRead();
|
||||||
|
Serial.printf("Updated temperature sensor value to %.2f°C\r\n", tsens_value);
|
||||||
|
// Update temperature value in Temperature sensor EP
|
||||||
|
zbTempSensor.setTemperature(tsens_value);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************* Arduino functions **************************/
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Init button switch
|
||||||
|
pinMode(button, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// Optional: set Zigbee device name and model
|
||||||
|
zbTempSensor.setManufacturerAndModel("Espressif", "ZigbeeTempSensor");
|
||||||
|
|
||||||
|
// Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
|
||||||
|
zbTempSensor.setMinMaxValue(10, 50);
|
||||||
|
|
||||||
|
// Optional: Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
|
||||||
|
zbTempSensor.setTolerance(1);
|
||||||
|
|
||||||
|
// Optional: Time cluster configuration (default params, as this device will revieve time from coordinator)
|
||||||
|
zbTempSensor.addTimeCluster();
|
||||||
|
|
||||||
|
// Add endpoint to Zigbee Core
|
||||||
|
Zigbee.addEndpoint(&zbTempSensor);
|
||||||
|
|
||||||
|
Serial.println("Starting Zigbee...");
|
||||||
|
// When all EPs are registered, start Zigbee in End Device mode
|
||||||
|
if (!Zigbee.begin()) {
|
||||||
|
Serial.println("Zigbee failed to start!");
|
||||||
|
Serial.println("Rebooting...");
|
||||||
|
ESP.restart();
|
||||||
|
} else {
|
||||||
|
Serial.println("Zigbee started successfully!");
|
||||||
|
}
|
||||||
|
Serial.println("Connecting to network");
|
||||||
|
while (!Zigbee.connected()) {
|
||||||
|
Serial.print(".");
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
// Optional: If time cluster is added, time can be read from the coordinator
|
||||||
|
timeinfo = zbTempSensor.getTime();
|
||||||
|
timezone = zbTempSensor.getTimezone();
|
||||||
|
|
||||||
|
Serial.println("UTC time:");
|
||||||
|
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||||
|
|
||||||
|
time_t local = mktime(&timeinfo) + timezone;
|
||||||
|
localTime = localtime(&local);
|
||||||
|
|
||||||
|
Serial.println("Local time with timezone:");
|
||||||
|
Serial.println(localTime, "%A, %B %d %Y %H:%M:%S");
|
||||||
|
|
||||||
|
// Start Temperature sensor reading task
|
||||||
|
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 2048, NULL, 10, NULL);
|
||||||
|
|
||||||
|
// Set reporting interval for temperature measurement in seconds, must be called after Zigbee.begin()
|
||||||
|
// min_interval and max_interval in seconds, delta (temp change in 0,1 °C)
|
||||||
|
// if min = 1 and max = 0, reporting is sent only when temperature changes by delta
|
||||||
|
// if min = 0 and max = 10, reporting is sent every 10 seconds or temperature changes by delta
|
||||||
|
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of temperature change
|
||||||
|
zbTempSensor.setReporting(1, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Checking button for factory reset
|
||||||
|
if (digitalRead(button) == LOW) { // Push button pressed
|
||||||
|
// Key debounce handling
|
||||||
|
delay(100);
|
||||||
|
int startTime = millis();
|
||||||
|
while (digitalRead(button) == LOW) {
|
||||||
|
delay(50);
|
||||||
|
if ((millis() - startTime) > 3000) {
|
||||||
|
// If key pressed for more than 3secs, factory reset Zigbee and reboot
|
||||||
|
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
|
||||||
|
delay(1000);
|
||||||
|
Zigbee.factoryReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zbTempSensor.reportTemperature();
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue