Poprawiony kod counter i nazw

This commit is contained in:
Sasza Stanczew 2026-09-07 14:04:29 +02:00
parent f88dbe3fb8
commit 80d1db9e1a

View file

@ -31,6 +31,7 @@
#endif #endif
#include "Zigbee.h" #include "Zigbee.h"
#include "nvs_flash.h"
#include <OneWireESP32.h> #include <OneWireESP32.h>
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
@ -41,6 +42,7 @@
/* Zigbee temperature sensor configuration */ /* Zigbee temperature sensor configuration */
#define ANALOG_DEVICE_ENDPOINT_NUMBER 1 #define ANALOG_DEVICE_ENDPOINT_NUMBER 1
#define ANALOG_DEVICE_ENDPOINT_NUMBER_2 2
#define TEMP_SENSOR_ENDPOINT_NUMBER 10 #define TEMP_SENSOR_ENDPOINT_NUMBER 10
uint8_t button = BOOT_PIN; uint8_t button = BOOT_PIN;
@ -53,7 +55,7 @@ int8_t counter = 0;
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER); ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
ZigbeeAnalog zbSetTemp = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER); ZigbeeAnalog zbSetTemp = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER);
ZigbeeAnalog zbSetTempDelta = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER); ZigbeeAnalog zbSetTempDelta = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER_2);
Adafruit_NeoPixel rgb(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel rgb(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t red = rgb.Color(255,0,0); uint32_t red = rgb.Color(255,0,0);
@ -122,13 +124,13 @@ static void temp_sensor_value_update(void *arg) {
temp_delta = zbSetTempDelta.getAnalogOutput(); temp_delta = zbSetTempDelta.getAnalogOutput();
if (tsens_value >= temp_set + temp_delta) { if (tsens_value >= temp_set + temp_delta) {
counter++; counter++;
if(counter > 3) counter = 3; if(counter > 5) counter = 5;
} else if (tsens_value <= temp_set - temp_delta) { } else if (tsens_value <= temp_set - temp_delta) {
counter--; counter--;
if(counter < 0) counter = 0; if(counter < 0) counter = 0;
} }
if(counter != 0) { if(counter > 1) {
Serial.printf("#%d PUMP ON %.2f°C\r\n", counter, tsens_value); Serial.printf("#%d PUMP ON %.2f°C\r\n", counter, tsens_value);
digitalWrite(PUMP_PIN, HIGH); digitalWrite(PUMP_PIN, HIGH);
} else { } else {
@ -155,7 +157,6 @@ void setup() {
rgb.setBrightness(30); rgb.setBrightness(30);
rgb.setPixelColor(0,red); rgb.show(); rgb.setPixelColor(0,red); rgb.show();
Serial.println("Starting temp task..."); Serial.println("Starting temp task...");
// Start Temperature sensor reading task // Start Temperature sensor reading task
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 3072, NULL, 10, NULL); xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 3072, NULL, 10, NULL);
@ -170,14 +171,14 @@ void setup() {
// temperature set as the threshold for pump activation/deactivation // temperature set as the threshold for pump activation/deactivation
zbSetTemp.addAnalogOutput(); zbSetTemp.addAnalogOutput();
zbSetTemp.setAnalogOutputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER); zbSetTemp.setAnalogOutputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER);
zbSetTemp.setAnalogOutputDescription("Water Temperature (°C)"); zbSetTemp.setAnalogOutputDescription("Set Temp");
zbSetTemp.setAnalogOutputResolution(1); zbSetTemp.setAnalogOutputResolution(1);
zbSetTemp.setAnalogOutputMinMax(10, 70); zbSetTemp.setAnalogOutputMinMax(10, 70);
// the delta value plus/minus the desired temperature // the delta value plus/minus the desired temperature
zbSetTempDelta.addAnalogOutput(); zbSetTempDelta.addAnalogOutput();
zbSetTempDelta.setAnalogOutputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER); zbSetTempDelta.setAnalogOutputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER);
zbSetTempDelta.setAnalogOutputDescription("Temperature delta (°C)"); zbSetTempDelta.setAnalogOutputDescription("Set Temp Delta");
zbSetTempDelta.setAnalogOutputResolution(0.5); zbSetTempDelta.setAnalogOutputResolution(0.5);
zbSetTempDelta.setAnalogOutputMinMax(1, 10); zbSetTempDelta.setAnalogOutputMinMax(1, 10);
@ -191,6 +192,15 @@ void setup() {
rgb.setPixelColor(0,orange); rgb.show(); rgb.setPixelColor(0,orange); rgb.show();
Serial.println("Starting Zigbee..."); Serial.println("Starting Zigbee...");
// Skip factoryReset() - it requires NVS partition which may not exist
// Instead, manually clear NVS if needed
// nvs_flash_erase(); // Uncomment if you need to clear NVS
// Open Zigbee network for 60 seconds (1 minute) to allow joining
Serial.println("Opening Zigbee network for joining (60s)...");
Zigbee.setRebootOpenNetwork(60);
// When all EPs are registered, start Zigbee in End Device mode // When all EPs are registered, start Zigbee in End Device mode
if (!Zigbee.begin()) { if (!Zigbee.begin()) {
Serial.println("Zigbee failed to start!"); Serial.println("Zigbee failed to start!");