diff --git a/esp32h2_water_temp_pump/esp32h2_water_temp_pump.ino b/esp32h2_water_temp_pump/esp32h2_water_temp_pump.ino index ec40b8e..29c117b 100644 --- a/esp32h2_water_temp_pump/esp32h2_water_temp_pump.ino +++ b/esp32h2_water_temp_pump/esp32h2_water_temp_pump.ino @@ -31,6 +31,7 @@ #endif #include "Zigbee.h" +#include "nvs_flash.h" #include #include @@ -41,6 +42,7 @@ /* Zigbee temperature sensor configuration */ #define ANALOG_DEVICE_ENDPOINT_NUMBER 1 +#define ANALOG_DEVICE_ENDPOINT_NUMBER_2 2 #define TEMP_SENSOR_ENDPOINT_NUMBER 10 uint8_t button = BOOT_PIN; @@ -53,7 +55,7 @@ int8_t counter = 0; ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_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); uint32_t red = rgb.Color(255,0,0); @@ -122,13 +124,13 @@ static void temp_sensor_value_update(void *arg) { temp_delta = zbSetTempDelta.getAnalogOutput(); if (tsens_value >= temp_set + temp_delta) { counter++; - if(counter > 3) counter = 3; + if(counter > 5) counter = 5; } else if (tsens_value <= temp_set - temp_delta) { counter--; if(counter < 0) counter = 0; } - if(counter != 0) { + if(counter > 1) { Serial.printf("#%d PUMP ON %.2f°C\r\n", counter, tsens_value); digitalWrite(PUMP_PIN, HIGH); } else { @@ -155,7 +157,6 @@ void setup() { rgb.setBrightness(30); rgb.setPixelColor(0,red); rgb.show(); - Serial.println("Starting temp task..."); // Start Temperature sensor reading task 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 zbSetTemp.addAnalogOutput(); zbSetTemp.setAnalogOutputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER); - zbSetTemp.setAnalogOutputDescription("Water Temperature (°C)"); + zbSetTemp.setAnalogOutputDescription("Set Temp"); zbSetTemp.setAnalogOutputResolution(1); zbSetTemp.setAnalogOutputMinMax(10, 70); // the delta value plus/minus the desired temperature zbSetTempDelta.addAnalogOutput(); zbSetTempDelta.setAnalogOutputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER); - zbSetTempDelta.setAnalogOutputDescription("Temperature delta (°C)"); + zbSetTempDelta.setAnalogOutputDescription("Set Temp Delta"); zbSetTempDelta.setAnalogOutputResolution(0.5); zbSetTempDelta.setAnalogOutputMinMax(1, 10); @@ -191,6 +192,15 @@ void setup() { rgb.setPixelColor(0,orange); rgb.show(); 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 if (!Zigbee.begin()) { Serial.println("Zigbee failed to start!");