From 0f29e89a50cc6d96f88e7c6409ff26448f8f4ce6 Mon Sep 17 00:00:00 2001 From: gilex-dev Date: Mon, 13 Nov 2023 20:41:30 +0100 Subject: [PATCH] add min temperature threshold --- src/globalvars.h | 1 + src/html.cpp | 35 ++++++++++++++++++----------------- src/main.cpp | 47 +++++++++++++++++++++++++++-------------------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/globalvars.h b/src/globalvars.h index 0a740d9..97b49bd 100644 --- a/src/globalvars.h +++ b/src/globalvars.h @@ -26,6 +26,7 @@ extern char home_html[]; extern bool override[]; extern const unsigned int pins[]; extern int temperatureSet; +extern int minTemperatureSet; extern int temperature; #endif diff --git a/src/html.cpp b/src/html.cpp index 13e456a..6a1cb95 100644 --- a/src/html.cpp +++ b/src/html.cpp @@ -100,6 +100,7 @@ void reload_settings() { sprintf( settings_html, " Ziel: °C \ +
Minimum: °C \
Aktuell: %d°C
\
\ \ @@ -175,23 +176,23 @@ void reload_settings() { \ \ ", - temperatureSet, temperature, time_all[0][0], time_all[1][0], - time_all[2][0], time_all[3][0], time_all[4][0], time_all[5][0], - time_all[6][0], time_all[7][0], time_all[0][1], time_all[1][1], - time_all[2][1], time_all[3][1], time_all[4][1], time_all[5][1], - time_all[6][1], time_all[7][1], time_all[0][2], time_all[1][2], - time_all[2][2], time_all[3][2], time_all[4][2], time_all[5][2], - time_all[6][2], time_all[7][2], time_all[0][3], time_all[1][3], - time_all[2][3], time_all[3][3], time_all[4][3], time_all[5][3], - time_all[6][3], time_all[7][3], time_all[0][4], time_all[1][4], - time_all[2][4], time_all[3][4], time_all[4][4], time_all[5][4], - time_all[6][4], time_all[7][4], time_all[0][5], time_all[1][5], - time_all[2][5], time_all[3][5], time_all[4][5], time_all[5][5], - time_all[6][5], time_all[7][5], time_all[0][6], time_all[1][6], - time_all[2][6], time_all[3][6], time_all[4][6], time_all[5][6], - time_all[6][6], time_all[7][6], time_all[0][7], time_all[1][7], - time_all[2][7], time_all[3][7], time_all[4][7], time_all[5][7], - time_all[6][7], time_all[7][7]); + temperatureSet, minTemperatureSet, temperature, time_all[0][0], + time_all[1][0], time_all[2][0], time_all[3][0], time_all[4][0], + time_all[5][0], time_all[6][0], time_all[7][0], time_all[0][1], + time_all[1][1], time_all[2][1], time_all[3][1], time_all[4][1], + time_all[5][1], time_all[6][1], time_all[7][1], time_all[0][2], + time_all[1][2], time_all[2][2], time_all[3][2], time_all[4][2], + time_all[5][2], time_all[6][2], time_all[7][2], time_all[0][3], + time_all[1][3], time_all[2][3], time_all[3][3], time_all[4][3], + time_all[5][3], time_all[6][3], time_all[7][3], time_all[0][4], + time_all[1][4], time_all[2][4], time_all[3][4], time_all[4][4], + time_all[5][4], time_all[6][4], time_all[7][4], time_all[0][5], + time_all[1][5], time_all[2][5], time_all[3][5], time_all[4][5], + time_all[5][5], time_all[6][5], time_all[7][5], time_all[0][6], + time_all[1][6], time_all[2][6], time_all[3][6], time_all[4][6], + time_all[5][6], time_all[6][6], time_all[7][6], time_all[0][7], + time_all[1][7], time_all[2][7], time_all[3][7], time_all[4][7], + time_all[5][7], time_all[6][7], time_all[7][7]); } void handleToggle() { diff --git a/src/main.cpp b/src/main.cpp index 354af81..1d92848 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,20 +19,19 @@ IPAddress subnet(255, 255, 255, 0); IPAddress dns(192, 168, 2, 1); Timezone myTime; -const u_int r = 0; +const u_int r = 0; // D3 on Amica const u_int oneWireBus = 0; OneWire oneWire(oneWireBus); DallasTemperature sensors(&oneWire); -int temperature; -int temperatureSet; +int temperature, temperatureSet, minTemperatureSet; static unsigned long lastTempCycle = -5000; char time_all[8][8][3] = { {}, {}, {}, {}, - {}, {}, {}, {}}; // 3D array for load_EEPROM() and handleTime() -const unsigned int pins[1] = {4}; + {}, {}, {}, {}}; // 3D array for load_EEPROM() and handleTime() +const unsigned int pins[1] = {4}; // D2 on Amica char stat[1][4] = {"AUS"}; // text on button char t_stat[1][4] = {""}; // for "status of timer changed" @@ -167,6 +166,7 @@ void load_EEPROM() { } } temperatureSet = EEPROM.read(256); + minTemperatureSet = EEPROM.read(260); } void handleHome() { @@ -215,6 +215,12 @@ void handleTime() { EEPROM.put(256, temperatureSet); EEPROM.commit(); } + if (server.arg("min_temperature").toInt() != minTemperatureSet) { + debugln("write minTemperature"); + minTemperatureSet = server.arg("min_temperature").toInt(); + EEPROM.put(260, minTemperatureSet); + EEPROM.commit(); + } reload_settings(); server.setContentLength(strlen(settings_html_pre) + strlen(settings_html)); server.send(301, "text/html", settings_html_pre); @@ -225,20 +231,21 @@ void timer() { int ri = 0; bool isOn = false; while (ri <= 7) { - if ((((myTime.hour() * 60 + myTime.minute() >= - atoi(time_all[0][ri]) * 60 + atoi(time_all[1][ri])) and - (myTime.hour() * 60 + myTime.minute() < - atoi(time_all[2][ri]) * 60 + - atoi(time_all[3][ri]))) // first range - or ((myTime.hour() * 60 + myTime.minute() >= - atoi(time_all[4][ri]) * 60 + atoi(time_all[5][ri])) and - (myTime.hour() * 60 + myTime.minute() < - atoi(time_all[6][ri]) * 60 + atoi(time_all[7][ri]))) or - ((atoi(time_all[0][ri]) == atoi(time_all[2][ri])) and - ((atoi(time_all[1][ri]) == atoi(time_all[3][ri])) and - (atoi(time_all[0][ri]) + atoi(time_all[1][ri]) != - 0)))) // second range - and temperature <= temperatureSet) { + if (((((myTime.hour() * 60 + myTime.minute() >= + atoi(time_all[0][ri]) * 60 + atoi(time_all[1][ri])) and + (myTime.hour() * 60 + myTime.minute() < + atoi(time_all[2][ri]) * 60 + + atoi(time_all[3][ri]))) // first range + or ((myTime.hour() * 60 + myTime.minute() >= + atoi(time_all[4][ri]) * 60 + atoi(time_all[5][ri])) and + (myTime.hour() * 60 + myTime.minute() < + atoi(time_all[6][ri]) * 60 + atoi(time_all[7][ri]))) or + ((atoi(time_all[0][ri]) == atoi(time_all[2][ri])) and + ((atoi(time_all[1][ri]) == atoi(time_all[3][ri])) and + (atoi(time_all[0][ri]) + atoi(time_all[1][ri]) != + 0)))) // second range + and temperature <= temperatureSet) or + temperature <= minTemperatureSet) { isOn = true; } ri++; @@ -294,7 +301,7 @@ void setup() { p++; } Serial.begin(74880); - EEPROM.begin(260); // 4 bits for EEPROM, address 0-255, value 0-255 + EEPROM.begin(264); // 4 bits for EEPROM, address 0-263, value 0-255 sensors.begin(); debug(F("\nver.")); debugln(version);