add min temperature threshold

This commit is contained in:
gilex-dev 2023-11-13 20:41:30 +01:00
parent 8c9de56fab
commit 0f29e89a50
3 changed files with 46 additions and 37 deletions

View File

@ -26,6 +26,7 @@ extern char home_html[];
extern bool override[]; extern bool override[];
extern const unsigned int pins[]; extern const unsigned int pins[];
extern int temperatureSet; extern int temperatureSet;
extern int minTemperatureSet;
extern int temperature; extern int temperature;
#endif #endif

View File

@ -100,6 +100,7 @@ void reload_settings() {
sprintf( sprintf(
settings_html, settings_html,
"<span> Ziel: </span><input type='number' min=0 max=50 name='temperature' value='%d' class='temperature'>°C <span>\ "<span> Ziel: </span><input type='number' min=0 max=50 name='temperature' value='%d' class='temperature'>°C <span>\
<br><span> Minimum: </span><input type='number' min=0 max=50 name='min_temperature' value='%d' class='temperature'>°C <span>\
<br>Aktuell: %d°C</span>\ <br>Aktuell: %d°C</span>\
<br>\ <br>\
<input type='submit'>\ <input type='submit'>\
@ -175,23 +176,23 @@ void reload_settings() {
</div>\ </div>\
</body>\ </body>\
</html>", </html>",
temperatureSet, temperature, time_all[0][0], time_all[1][0], temperatureSet, minTemperatureSet, temperature, time_all[0][0],
time_all[2][0], time_all[3][0], time_all[4][0], time_all[5][0], time_all[1][0], time_all[2][0], time_all[3][0], time_all[4][0],
time_all[6][0], time_all[7][0], time_all[0][1], time_all[1][1], time_all[5][0], time_all[6][0], time_all[7][0], time_all[0][1],
time_all[2][1], time_all[3][1], time_all[4][1], time_all[5][1], time_all[1][1], time_all[2][1], time_all[3][1], time_all[4][1],
time_all[6][1], time_all[7][1], time_all[0][2], time_all[1][2], time_all[5][1], time_all[6][1], time_all[7][1], time_all[0][2],
time_all[2][2], time_all[3][2], time_all[4][2], time_all[5][2], time_all[1][2], time_all[2][2], time_all[3][2], time_all[4][2],
time_all[6][2], time_all[7][2], time_all[0][3], time_all[1][3], time_all[5][2], time_all[6][2], time_all[7][2], time_all[0][3],
time_all[2][3], time_all[3][3], time_all[4][3], time_all[5][3], time_all[1][3], time_all[2][3], time_all[3][3], time_all[4][3],
time_all[6][3], time_all[7][3], time_all[0][4], time_all[1][4], time_all[5][3], time_all[6][3], time_all[7][3], time_all[0][4],
time_all[2][4], time_all[3][4], time_all[4][4], time_all[5][4], time_all[1][4], time_all[2][4], time_all[3][4], time_all[4][4],
time_all[6][4], time_all[7][4], time_all[0][5], time_all[1][5], time_all[5][4], time_all[6][4], time_all[7][4], time_all[0][5],
time_all[2][5], time_all[3][5], time_all[4][5], time_all[5][5], time_all[1][5], time_all[2][5], time_all[3][5], time_all[4][5],
time_all[6][5], time_all[7][5], time_all[0][6], time_all[1][6], time_all[5][5], time_all[6][5], time_all[7][5], time_all[0][6],
time_all[2][6], time_all[3][6], time_all[4][6], time_all[5][6], time_all[1][6], time_all[2][6], time_all[3][6], time_all[4][6],
time_all[6][6], time_all[7][6], time_all[0][7], time_all[1][7], time_all[5][6], time_all[6][6], time_all[7][6], time_all[0][7],
time_all[2][7], time_all[3][7], time_all[4][7], time_all[5][7], time_all[1][7], time_all[2][7], time_all[3][7], time_all[4][7],
time_all[6][7], time_all[7][7]); time_all[5][7], time_all[6][7], time_all[7][7]);
} }
void handleToggle() { void handleToggle() {

View File

@ -19,20 +19,19 @@ IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192, 168, 2, 1); IPAddress dns(192, 168, 2, 1);
Timezone myTime; Timezone myTime;
const u_int r = 0; const u_int r = 0; // D3 on Amica
const u_int oneWireBus = 0; const u_int oneWireBus = 0;
OneWire oneWire(oneWireBus); OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire); DallasTemperature sensors(&oneWire);
int temperature; int temperature, temperatureSet, minTemperatureSet;
int temperatureSet;
static unsigned long lastTempCycle = -5000; static unsigned long lastTempCycle = -5000;
char time_all[8][8][3] = { char time_all[8][8][3] = {
{}, {}, {}, {}, {}, {}, {}, {},
{}, {}, {}, {}}; // 3D array for load_EEPROM() and handleTime() {}, {}, {}, {}}; // 3D array for load_EEPROM() and handleTime()
const unsigned int pins[1] = {4}; const unsigned int pins[1] = {4}; // D2 on Amica
char stat[1][4] = {"AUS"}; // text on button char stat[1][4] = {"AUS"}; // text on button
char t_stat[1][4] = {""}; // for "status of timer changed" char t_stat[1][4] = {""}; // for "status of timer changed"
@ -167,6 +166,7 @@ void load_EEPROM() {
} }
} }
temperatureSet = EEPROM.read(256); temperatureSet = EEPROM.read(256);
minTemperatureSet = EEPROM.read(260);
} }
void handleHome() { void handleHome() {
@ -215,6 +215,12 @@ void handleTime() {
EEPROM.put(256, temperatureSet); EEPROM.put(256, temperatureSet);
EEPROM.commit(); 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(); reload_settings();
server.setContentLength(strlen(settings_html_pre) + strlen(settings_html)); server.setContentLength(strlen(settings_html_pre) + strlen(settings_html));
server.send(301, "text/html", settings_html_pre); server.send(301, "text/html", settings_html_pre);
@ -225,20 +231,21 @@ void timer() {
int ri = 0; int ri = 0;
bool isOn = false; bool isOn = false;
while (ri <= 7) { while (ri <= 7) {
if ((((myTime.hour() * 60 + myTime.minute() >= if (((((myTime.hour() * 60 + myTime.minute() >=
atoi(time_all[0][ri]) * 60 + atoi(time_all[1][ri])) and atoi(time_all[0][ri]) * 60 + atoi(time_all[1][ri])) and
(myTime.hour() * 60 + myTime.minute() < (myTime.hour() * 60 + myTime.minute() <
atoi(time_all[2][ri]) * 60 + atoi(time_all[2][ri]) * 60 +
atoi(time_all[3][ri]))) // first range atoi(time_all[3][ri]))) // first range
or ((myTime.hour() * 60 + myTime.minute() >= or ((myTime.hour() * 60 + myTime.minute() >=
atoi(time_all[4][ri]) * 60 + atoi(time_all[5][ri])) and atoi(time_all[4][ri]) * 60 + atoi(time_all[5][ri])) and
(myTime.hour() * 60 + myTime.minute() < (myTime.hour() * 60 + myTime.minute() <
atoi(time_all[6][ri]) * 60 + atoi(time_all[7][ri]))) or 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[0][ri]) == atoi(time_all[2][ri])) and
((atoi(time_all[1][ri]) == atoi(time_all[3][ri])) and ((atoi(time_all[1][ri]) == atoi(time_all[3][ri])) and
(atoi(time_all[0][ri]) + atoi(time_all[1][ri]) != (atoi(time_all[0][ri]) + atoi(time_all[1][ri]) !=
0)))) // second range 0)))) // second range
and temperature <= temperatureSet) { and temperature <= temperatureSet) or
temperature <= minTemperatureSet) {
isOn = true; isOn = true;
} }
ri++; ri++;
@ -294,7 +301,7 @@ void setup() {
p++; p++;
} }
Serial.begin(74880); 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(); sensors.begin();
debug(F("\nver.")); debug(F("\nver."));
debugln(version); debugln(version);