Compare commits

...

2 Commits

Author SHA1 Message Date
gilex-dev 782fe8cf04 fix theoretical overflow with sprintf 2023-11-13 22:33:19 +01:00
gilex-dev 900a1d9af2 add min temperature threshold 2023-11-13 22:22:30 +01:00
3 changed files with 54 additions and 66 deletions

View File

@ -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

View File

@ -3,23 +3,6 @@
void reload_home() // generates current time and changes variables in home_html
{
char time_current[3][3] = {"", "", ""};
if (myTime.hour() < 10) {
sprintf(time_current[0], "0%d", myTime.hour());
} else {
sprintf(time_current[0], "%d", myTime.hour());
}
if (myTime.minute() < 10) {
sprintf(time_current[1], "0%d", myTime.minute());
} else {
sprintf(time_current[1], "%d", myTime.minute());
}
if (myTime.second() < 10) {
sprintf(time_current[2], "0%d", myTime.second());
} else {
sprintf(time_current[2], "%d", myTime.second());
}
sprintf(home_html, "<!DOCTYPE html>\
<html lang='de'>\
<head>\
@ -80,7 +63,7 @@ top: 2px;\
<body>\
<div class='wrapper_main'>\
<h1>Übersicht</h1>\
<h2>Uhrzeit: <span>%s:%s:%s</span></h2>\
<h2>Uhrzeit: <span>%02d:%02d:%02d</span></h2>\
<div class='wrapper_form'>\
<div>\
<span>Ventil 1: </span>\
@ -93,13 +76,14 @@ top: 2px;\
</div>\
</body>\
</html>",
time_current[0], time_current[1], time_current[2], stat[0]);
myTime.hour(), myTime.minute(), myTime.second(), stat[0]);
}
void reload_settings() {
sprintf(
settings_html,
"<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>\
<input type='submit'>\
@ -175,23 +159,23 @@ void reload_settings() {
</div>\
</body>\
</html>",
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() {

View File

@ -1,7 +1,7 @@
const char SSID[] = "";
const char PASSWORD[] = "";
const char version[] = " 0.8.1";
const char version[] = " 0.8.3";
#include "globalvars.h"
#include <Arduino.h>
#include <DallasTemperature.h>
@ -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};
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"
@ -157,16 +156,13 @@ void load_EEPROM() {
unsigned int EEPROM_Addr = 0;
for (unsigned int i0 = 0; i0 < 8; i0++) {
for (unsigned int i = 0; i < 8; i++) {
if (EEPROM.read(EEPROM_Addr) < 10) {
sprintf(time_all[i0][i], "0%d", EEPROM.read(EEPROM_Addr));
} else {
sprintf(time_all[i0][i], "%d", EEPROM.read(EEPROM_Addr));
}
sprintf(time_all[i0][i], "%02d", EEPROM.read(EEPROM_Addr));
EEPROM_Addr += 4;
yield();
}
}
temperatureSet = EEPROM.read(256);
minTemperatureSet = EEPROM.read(260);
}
void handleHome() {
@ -194,10 +190,10 @@ void handleTime() {
server.arg(args[arg])[1]};
char buff_m[2][2] = {server.arg(args[arg])[3],
server.arg(args[arg])[4]};
sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s",
buff_h);
sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()], "%s",
buff_m);
sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s%s",
buff_h[0], buff_h[1]);
sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()],
"%s%s", buff_m[0], buff_m[1]);
EEPROM.put(server.arg("rule").toInt() * 4 + arg * 64,
atoi(time_all[arg * 2][server.arg("rule").toInt()]));
@ -215,6 +211,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,7 +227,7 @@ void timer() {
int ri = 0;
bool isOn = false;
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
(myTime.hour() * 60 + myTime.minute() <
atoi(time_all[2][ri]) * 60 +
@ -238,7 +240,8 @@ void timer() {
((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) {
and temperature <= temperatureSet) or
temperature <= minTemperatureSet) {
isOn = true;
}
ri++;
@ -294,7 +297,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);