adapt for single switch & add temperature support

This commit is contained in:
gilex-dev 2023-08-19 19:19:25 +02:00
parent 6ec6cc0175
commit b00d6a7bb5
3 changed files with 373 additions and 344 deletions

View File

@ -20,10 +20,12 @@
extern ESP8266WebServer server; extern ESP8266WebServer server;
extern Timezone myTime; extern Timezone myTime;
extern char time_all[8][8][3]; extern char time_all[8][8][3];
extern char stat[8][4]; extern char stat[1][4];
extern char settings_html[]; extern char settings_html[];
extern char home_html[]; 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 temperature;
#endif #endif

View File

@ -1,7 +1,8 @@
#include "globalvars.h" #include "globalvars.h"
#include <Arduino.h> #include <Arduino.h>
void reload_home() { void reload_home() // generates current time and changes variables in home_html
{
char time_current[3][3] = {"", "", ""}; char time_current[3][3] = {"", "", ""};
if (myTime.hour() < 10) { if (myTime.hour() < 10) {
sprintf(time_current[0], "0%d", myTime.hour()); sprintf(time_current[0], "0%d", myTime.hour());
@ -22,198 +23,188 @@ void reload_home() {
sprintf(home_html, "<!DOCTYPE html>\ sprintf(home_html, "<!DOCTYPE html>\
<html lang='de'>\ <html lang='de'>\
<head>\ <head>\
<meta charset='UTF-8'>\ <meta charset='UTF-8'>\
<meta http-equiv='X-UA-Compatible' content='IE=edge'>\ <meta http-equiv='X-UA-Compatible' content='IE=edge'>\
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\ <meta name='viewport' content='width=device-width, initial-scale=1.0'>\
<title>Home</title>\ <title>Home</title>\
<style>\ <style>\
* {\ * {\
font-family: Arial, Helvetica, sans-serif;\ font-family: Arial, Helvetica, sans-serif;\
font-size: 40px;\ font-size: 40px;\
user-select: none;\ user-select: none;\
text-decoration: none;\ text-decoration: none;\
}\ }\
h2 {\ h2 {\
font-size: 28px;\ font-size: 28px;\
}\ }\
h2 span{\ h2 span{\
font-size: inherit;\ font-size: inherit;\
font-family: monospace;\ font-family: monospace;\
}\ }\
.wrapper_main {\ .wrapper_main {\
margin: 0 auto;\ margin: 0 auto;\
width: fit-content;\ width: fit-content;\
width: -moz-fit-content;\ width: -moz-fit-content;\
text-align: center;\ text-align: center;\
background-color: rgb(202, 202, 202);\ background-color: rgb(202, 202, 202);\
padding: 1px 8px 8px 8px;\ padding: 1px 8px 8px 8px;\
border-radius: 4px;\ border-radius: 4px;\
}\ }\
.wrapper_form div a {\ .wrapper_form div a {\
width: 100px;\ width: 100px;\
}\ }\
.wrapper_form div a, .animated_a {\ .wrapper_form div a, .animated_a {\
background-color: rgb(252, 255, 104);\ background-color: rgb(252, 255, 104);\
border: none;\ border: none;\
border-radius: 4px;\ border-radius: 4px;\
box-shadow: rgb(180, 172, 59) 0 4px;\ box-shadow: rgb(180, 172, 59) 0 4px;\
position: relative;\ position: relative;\
margin: 8px 0;\ margin: 8px 0;\
padding: 2px;\ padding: 2px;\
}\ }\
.wrapper_form div a, .animated_a {\ .wrapper_form div a, .animated_a {\
display: inline-block;\ display: inline-block;\
}\ }\
a {\ a {\
color: black;\ color: black;\
}\ }\
.wrapper_form div a, .animated_a {\ .wrapper_form div a, .animated_a {\
cursor: pointer;\ cursor: pointer;\
}\ }\
.animated_a:active, .wrapper_form div a:active {\ .animated_a:active, .wrapper_form div a:active {\
box-shadow: rgb(180, 172, 59) 0 2px;\ box-shadow: rgb(180, 172, 59) 0 2px;\
top: 2px;\ top: 2px;\
}\ }\
</style>\ </style>\
</head>\ </head>\
<body>\ <body>\
<div class='wrapper_main'>\ <div class='wrapper_main'>\
<h1>Übersicht</h1>\ <h1>Übersicht</h1>\
<h2>Uhrzeit: <span>%s:%s:%s</span></h2>\ <h2>Uhrzeit: <span>%s:%s:%s</span></h2>\
<div class='wrapper_form'>\ <div class='wrapper_form'>\
<div>\ <div>\
<span>Ventil 1: </span>\ <span>Ventil 1: </span>\
<a href='/toggle?number=0'>%s</a>\ <a href='/toggle?number=0'>%s</a>\
</div>\ </div>\
<div>\ <a class='animated_a' href='/settings'>Einstellungen</a>\
<span>Ventil 2:</span>\ <br>\
<a href='/toggle?number=1'>%s</a>\ <a class='animated_a' href='http://192.168.2.5'>Garten Anlage</a>\
</div>\ </div>\
<div>\ </div>\
<span>Ventil 3:</span>\
<a href='/toggle?number=2'>%s</a>\
</div>\
<div>\
<span>Ventil 4:</span>\
<a href='/toggle?number=3'>%s</a>\
</div>\
<div>\
<span>Ventil 5:</span>\
<a href='/toggle?number=4'>%s</a>\
</div>\
<div>\
<span>Ventil 6:</span>\
<a href='/toggle?number=5'>%s</a>\
</div>\
<div>\
<span>Ventil 7:</span>\
<a href='/toggle?number=6'>%s</a>\
</div>\
<div style='display: none;'>\
<span>Ventil 8:</span>\
<a href='/toggle?number=7'>%s</a>\
</div>\
<a class='animated_a' href='/settings'>Einstellungen</a>\
<br>\
<a class='animated_a' href='#'>Kellerheizung</a>\
</div>\
</div>\
</body>\ </body>\
</html>", </html>",
time_current[0], time_current[1], time_current[2], stat[0], stat[1], time_current[0], time_current[1], time_current[2], stat[0]);
stat[2], stat[3], stat[4], stat[5], stat[6], stat[7]);
} }
void reload_settings() { void reload_settings() {
sprintf(settings_html, "<tr>\ sprintf(
<td>1</td>\ settings_html,
<td>%s:%s</td>\ "<span> Ziel: </span><input type='number' min=0 max=50 name='temperature' value='%d' class='temperature'>°C <span>\
<td>%s:%s</td>\ <br>Aktuell: %d°C</span>\
<td>%s:%s</td>\ <br>\
<td>%s:%s</td>\ <input type='submit'>\
</tr>\ </form>\
<tr>\ <div class='wrapper_table'>\
<td>2</td>\ <table>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <th style='background-color: gray;'></th>\
<td>%s:%s</td>\ <th>von:</th>\
<td>%s:%s</td>\ <th>bis:</th>\
</tr>\ <th>von:</th>\
<tr>\ <th>bis:</th>\
<td>3</td>\ </tr>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <td>1</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
</tr>\ <td>%s:%s</td>\
<tr>\ <td>%s:%s</td>\
<td>4</td>\ </tr>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <td>2</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
</tr>\ <td>%s:%s</td>\
<tr>\ <td>%s:%s</td>\
<td>5</td>\ </tr>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <td>3</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
</tr>\ <td>%s:%s</td>\
<tr>\ <td>%s:%s</td>\
<td>6</td>\ </tr>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <td>4</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
</tr>\ <td>%s:%s</td>\
<tr>\ <td>%s:%s</td>\
<td>7</td>\ </tr>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <td>5</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
</tr>\ <td>%s:%s</td>\
<tr style='display: none'>\ <td>%s:%s</td>\
<td>8</td>\ </tr>\
<td>%s:%s</td>\ <tr>\
<td>%s:%s</td>\ <td>6</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
<td>%s:%s</td>\ <td>%s:%s</td>\
</tr>\ <td>%s:%s</td>\
</table>\ <td>%s:%s</td>\
</div>\ </tr>\
<a class='animated_a' href='/'>Übersicht</a>\ <tr>\
</div>\ <td>7</td>\
</body>\ <td>%s:%s</td>\
<td>%s:%s</td>\
<td>%s:%s</td>\
<td>%s:%s</td>\
</tr>\
<tr>\
<td>8</td>\
<td>%s:%s</td>\
<td>%s:%s</td>\
<td>%s:%s</td>\
<td>%s:%s</td>\
</tr>\
</table>\
</div>\
<a class='animated_a' href='/'>Übersicht</a>\
</div>\
</body>\
</html>", </html>",
time_all[0][0], time_all[1][0], time_all[2][0], time_all[3][0], temperatureSet, temperature, time_all[0][0], time_all[1][0],
time_all[4][0], time_all[5][0], time_all[6][0], time_all[7][0], time_all[2][0], time_all[3][0], time_all[4][0], time_all[5][0],
time_all[0][1], time_all[1][1], time_all[2][1], time_all[3][1], time_all[6][0], time_all[7][0], time_all[0][1], time_all[1][1],
time_all[4][1], time_all[5][1], time_all[6][1], time_all[7][1], time_all[2][1], time_all[3][1], time_all[4][1], time_all[5][1],
time_all[0][2], time_all[1][2], time_all[2][2], time_all[3][2], time_all[6][1], time_all[7][1], time_all[0][2], time_all[1][2],
time_all[4][2], time_all[5][2], time_all[6][2], time_all[7][2], time_all[2][2], time_all[3][2], time_all[4][2], time_all[5][2],
time_all[0][3], time_all[1][3], time_all[2][3], time_all[3][3], time_all[6][2], time_all[7][2], time_all[0][3], time_all[1][3],
time_all[4][3], time_all[5][3], time_all[6][3], time_all[7][3], time_all[2][3], time_all[3][3], time_all[4][3], time_all[5][3],
time_all[0][4], time_all[1][4], time_all[2][4], time_all[3][4], time_all[6][3], time_all[7][3], time_all[0][4], time_all[1][4],
time_all[4][4], time_all[5][4], time_all[6][4], time_all[7][4], time_all[2][4], time_all[3][4], time_all[4][4], time_all[5][4],
time_all[0][5], time_all[1][5], time_all[2][5], time_all[3][5], time_all[6][4], time_all[7][4], time_all[0][5], time_all[1][5],
time_all[4][5], time_all[5][5], time_all[6][5], time_all[7][5], time_all[2][5], time_all[3][5], time_all[4][5], time_all[5][5],
time_all[0][6], time_all[1][6], time_all[2][6], time_all[3][6], time_all[6][5], time_all[7][5], time_all[0][6], time_all[1][6],
time_all[4][6], time_all[5][6], time_all[6][6], time_all[7][6], time_all[2][6], time_all[3][6], time_all[4][6], time_all[5][6],
time_all[0][7], time_all[1][7], time_all[2][7], time_all[3][7], time_all[6][6], time_all[7][6], time_all[0][7], time_all[1][7],
time_all[4][7], time_all[5][7], time_all[6][7], time_all[7][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() { void handleToggle() {
int i = server.arg("number") int i =
.toInt(); // converts GET argument to int and does stuff xD server.arg("number")
.toInt(); // handles manual toggle and converts GET argument to int
override[i] = !override[i]; override[i] = !override[i];
debugln(F("---------------------------")); debugln(F("---------------------------"));
debug(F("[RECIVED] for: ")); debug(F("[RECIVED] for: "));
debugln(i); debugln(i);
digitalWrite(pins[i], !digitalRead(pins[i])); digitalWrite(pins[i], !digitalRead(pins[i]));
if (digitalRead(pins[i]) == LOW) { digitalWrite(2, !digitalRead(2));
if (digitalRead(pins[i]) == HIGH) {
sprintf(stat[i], "AN"); sprintf(stat[i], "AN");
} else { } else {
sprintf(stat[i], "AUS"); sprintf(stat[i], "AUS");

View File

@ -1,156 +1,154 @@
const char SSID[] = ""; const char SSID[] = "";
const char PASSWORD[] = ""; const char PASSWORD[] = "";
const char version[] = " 0.8"; const char version[] = " 0.8.1";
#include "globalvars.h" #include "globalvars.h"
#include <Arduino.h> #include <Arduino.h>
#include <DallasTemperature.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <OneWire.h>
#include <ezTime.h> #include <ezTime.h>
#include <stdint.h> #include <stdint.h>
ESP8266WebServer server; ESP8266WebServer server;
IPAddress staticIP(192, 168, 2, 5); // static IP address IPAddress staticIP(192, 168, 2, 4); // static IP address
IPAddress gateway(192, 168, 2, 1); // Router's IP address IPAddress gateway(192, 168, 2, 1); // Router's IP address
IPAddress subnet(255, 255, 255, 0); 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 oneWireBus = 0;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
int temperature;
int temperatureSet;
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[8] = {5, 4, 14, 12, const unsigned int pins[1] = {4};
13, 10, 9}; // TODO: only 7 of 8 pins defined
int r = 0;
char stat[8][4] = {"AUS", "AUS", "AUS", "AUS", char stat[1][4] = {"AUS"}; // text on button
"AUS", "AUS", "AUS", "AUS"}; // text on button char t_stat[1][4] = {""}; // for "status of timer changed"
char t_stat[8][4] = {"", "", "", "", bool override[1] = {false}; // for manual override
"", "", "", ""}; // for "status of timer changed" char home_html[1346];
bool override[8] = {false, false, false, false, char settings_html[987];
false, false, false, false}; // for manual override
char home_html[3000]; // be careful when changing these values (might cause
// overflow)!
char settings_html[2014];
const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\ const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\
<html lang='de'>\ <html lang='de'>\
<head>\ <head>\
<meta charset='UTF-8'>\ <meta charset='UTF-8'>\
<meta http-equiv='X-UA-Compatible' content='IE=edge'>\ <meta http-equiv='X-UA-Compatible' content='IE=edge'>\
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\ <meta name='viewport' content='width=device-width, initial-scale=1.0'>\
<title>Einstellungen</title>\ <title>Einstellungen</title>\
<style>\ <style>\
* {\ * {\
font-family: Arial, Helvetica, sans-serif;\ font-family: Arial, Helvetica, sans-serif;\
font-size: 26px;\ font-size: 26px;\
user-select: none;\ user-select: none;\
text-decoration: none;\ text-decoration: none;\
}\ }\
a {\ a {\
color: black;\ color: black;\
}\ }\
.wrapper_main {\ .wrapper_main {\
margin: 0 auto;\ margin: 0 auto;\
max-width: fit-content;\ max-width: fit-content;\
max-width: -moz-fit-content;\ max-width: -moz-fit-content;\
text-align: center;\ text-align: center;\
background-color: rgb(214, 214, 214);\ background-color: rgb(214, 214, 214);\
padding: 1px 8px 8px 8px;\ padding: 1px 8px 8px 8px;\
border-radius: 4px;\ border-radius: 4px;\
}\ }\
#rule, [type='time'] {\ #rule, [type='time'], .temperature {\
height: 36px;\ height: 36px;\
border: none;\ border: none;\
padding: 0 4px;\ padding: 0 4px;\
margin: 4px 0;\ margin: 4px 0;\
background-color: white;\ background-color: white;\
width: fit-content;\ width: fit-content;\
width: -moz-fit-content;\ width: -moz-fit-content;\
border-radius: 4px;\ border-radius: 4px;\
}\ }\
.animated_a, [type='submit']{\ .temperature {\
background-color: rgb(135, 252, 119);\ width: 2.5em;\
border: none;\ }\
border-radius: 4px;\ .animated_a, [type='submit']{\
box-shadow: rgb(25, 167, 49) 0 4px;\ background-color: rgb(135, 252, 119);\
position: relative;\ border: none;\
margin: 8px 0;\ border-radius: 4px;\
padding: 2px 8px;\ box-shadow: rgb(25, 167, 49) 0 4px;\
}\ position: relative;\
[type='submit'] {\ margin: 8px 0;\
position: relative;\ padding: 2px 8px;\
top: -2px;\ }\
display: inline-block;\ [type='submit'] {\
}\ position: relative;\
.animated_a {\ top: -2px;\
text-decoration: none;\ display: inline-block;\
display: inline-block;\ }\
margin: 8px 0;\ .animated_a {\
padding-top: 4px;\ text-decoration: none;\
height: 28px;\ display: inline-block;\
}\ margin: 8px 0;\
.wrapper_table {\ padding-top: 4px;\
overflow: auto;\ height: 28px;\
}\ }\
table {\ .wrapper_table {\
margin: 8px auto;\ overflow: auto;\
}\ }\
table, th, td {\ table {\
border: 1px solid black;\ margin: 8px auto;\
border-collapse: collapse;\ }\
user-select: text;\ table, th, td {\
padding: 0 8px;\ border: 1px solid black;\
}\ border-collapse: collapse;\
.animated_a, [type='submit']{\ user-select: text;\
cursor: pointer;\ padding: 0 8px;\
}\ }\
.animated_a:active {\ .animated_a, [type='submit']{\
box-shadow: rgb(25, 167, 49) 0 2px;\ cursor: pointer;\
top: 2px;\ }\
}\ .animated_a:active {\
[type='submit']:active {\ box-shadow: rgb(25, 167, 49) 0 2px;\
box-shadow: rgb(25, 167, 49) 0 2px;\ top: 2px;\
top: 0px;\ }\
}\ [type='submit']:active {\
*:focus {\ box-shadow: rgb(25, 167, 49) 0 2px;\
outline: none;\ top: 0px;\
}\ }\
</style>\ *:focus {\
</head>\ outline: none;\
<body>\ }\
<div class='wrapper_main'>\ span:empty {content: 'nicht verbunden';}\
<form action='settings' method='POST'>\ </style>\
<select name='rule' id='rule' required>\ </head>\
<option value='' selected disabled>Ventiel Nr.</option>\ <body>\
<option value='0'>1</option>\ <div class='wrapper_main'>\
<option value='1'>2</option>\ <form action='settings' method='POST'>\
<option value='2'>3</option>\ <select name='rule' id='rule'>\
<option value='3'>4</option>\ <option value='' selected disabled>Spalte Nr.</option>\
<option value='4'>5</option>\ <option value='0'>1</option>\
<option value='5'>6</option>\ <option value='1'>2</option>\
<option value='6'>7</option>\ <option value='2'>3</option>\
<option value='7' disabled>8</option>\ <option value='3'>4</option>\
</select>\ <option value='4'>5</option>\
<br>\ <option value='5'>6</option>\
<input type='time' name='time_o'>\ <option value='6'>7</option>\
<option value='7'>8</option>\
</select>\
<br>\
<input type='time' name='time_o'>\
- <input type='time' name='time_f'>\ - <input type='time' name='time_f'>\
<br>\ <br>\
<input type='time' name='time_o_1'>\ <input type='time' name='time_o_1'>\
- <input type='time' name='time_f_1'>\ - <input type='time' name='time_f_1'>\
<br>\ <br>"};
<input type='submit'>\
</form>\
<div class='wrapper_table'>\
<table>\
<tr>\
<th style='background-color: gray;'></th>\
<th>von:</th>\
<th>bis:</th>\
<th>von:</th>\
<th>bis:</th>\
</tr>"};
void reload_home(); void reload_home();
void reload_settings(); void reload_settings();
void handleToggle(); void handleToggle();
@ -168,6 +166,7 @@ void load_EEPROM() {
yield(); yield();
} }
} }
temperatureSet = EEPROM.read(256);
} }
void handleHome() { void handleHome() {
@ -185,14 +184,19 @@ void handleSettings() {
} }
void handleTime() { void handleTime() {
if (server.arg("rule") != "") {
debugln("write main");
const char args[4][9] = {"time_o", "time_f", "time_o_1", "time_f_1"}; const char args[4][9] = {"time_o", "time_f", "time_o_1", "time_f_1"};
for (unsigned int arg = 0; arg < 4; arg++) { for (unsigned int arg = 0; arg < 4; arg++) {
if (server.arg(args[arg]) != "") { if (server.arg(args[arg]) != "") {
char buff_h[2][2] = {server.arg(args[arg])[0], server.arg(args[arg])[1]}; char buff_h[2][2] = {server.arg(args[arg])[0],
char buff_m[2][2] = {server.arg(args[arg])[3], server.arg(args[arg])[4]}; 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][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 + 1][server.arg("rule").toInt()], "%s",
buff_m);
EEPROM.put(server.arg("rule").toInt() * 4 + arg * 64, EEPROM.put(server.arg("rule").toInt() * 4 + arg * 64,
atoi(time_all[arg * 2][server.arg("rule").toInt()])); atoi(time_all[arg * 2][server.arg("rule").toInt()]));
@ -202,6 +206,13 @@ void handleTime() {
EEPROM.commit(); EEPROM.commit();
} }
} }
}
if (server.arg("temperature").toInt() != temperatureSet) {
debugln("write temperature");
temperatureSet = server.arg("temperature").toInt();
EEPROM.put(256, temperatureSet);
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);
@ -209,21 +220,35 @@ void handleTime() {
} }
void timer() { void timer() {
if (((myTime.hour() * 60 + myTime.minute() >= int ri = 0;
atoi(time_all[0][r]) * 60 + atoi(time_all[1][r])) and 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() < (myTime.hour() * 60 + myTime.minute() <
atoi(time_all[2][r]) * 60 + atoi(time_all[3][r]))) or atoi(time_all[2][ri]) * 60 + atoi(time_all[3][ri]))) // first range
((myTime.hour() * 60 + myTime.minute() >= or ((myTime.hour() * 60 + myTime.minute() >=
atoi(time_all[4][r]) * 60 + atoi(time_all[5][r])) 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][r]) * 60 + atoi(time_all[7][r])))) { 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) {
isOn = true;
}
ri++;
}
if (isOn) {
if ((override[r]) and (strcmp(t_stat[r], "off") == 0)) { if ((override[r]) and (strcmp(t_stat[r], "off") == 0)) {
override[r] = false; override[r] = false;
debugln(F("debug#1")); debugln(F("debug#1"));
} }
sprintf(t_stat[r], "on"); sprintf(t_stat[r], "on");
if (!override[r]) { if (!override[r]) {
digitalWrite(pins[r], LOW); digitalWrite(pins[r], HIGH);
digitalWrite(2, HIGH); // LED
if (strcmp(stat[r], "AUS") == 0) { if (strcmp(stat[r], "AUS") == 0) {
debug(r); debug(r);
debugln(F(" is on")); debugln(F(" is on"));
@ -236,7 +261,8 @@ void timer() {
} }
sprintf(t_stat[r], "off"); sprintf(t_stat[r], "off");
if (!override[r]) { if (!override[r]) {
digitalWrite(pins[r], HIGH); digitalWrite(pins[r], LOW);
digitalWrite(2, LOW); // LED
if (strcmp(stat[r], "AN") == 0) { if (strcmp(stat[r], "AN") == 0) {
debug(r); debug(r);
debugln(F(" is off")); debugln(F(" is off"));
@ -245,16 +271,28 @@ void timer() {
} }
} }
} }
void getCurrentTemperatur() {
if (millis() - lastTempCycle > 5000) {
sensors.requestTemperatures();
temperature = int(sensors.getTempCByIndex(0)) != -127
? int(sensors.getTempCByIndex(0))
: 255; // TODO: mark as invalid
lastTempCycle = millis();
debugln(temperature);
}
}
void setup() { void setup() {
int p = 0; int p = 0;
while (p <= 7) { while (p <= 7) {
pinMode(pins[p], OUTPUT); pinMode(pins[p], OUTPUT);
digitalWrite(pins[p], HIGH); pinMode(2, OUTPUT);
digitalWrite(pins[p], LOW);
digitalWrite(2, LOW); // LED
p++; p++;
} }
Serial.begin(74880); Serial.begin(74880);
EEPROM.begin(256); // 4 bits for EEPROM, address 0-255, value 0-255 EEPROM.begin(260); // 4 bits for EEPROM, address 0-255, value 0-255
sensors.begin();
debug(F("\nver.")); debug(F("\nver."));
debugln(version); debugln(version);
debugln(F("check for updates at " debugln(F("check for updates at "
@ -267,15 +305,15 @@ void setup() {
WiFi.hostname("ESP8266 IOT development"); WiFi.hostname("ESP8266 IOT development");
WiFi.begin(SSID, PASSWORD); WiFi.begin(SSID, PASSWORD);
Serial.println(F("Connecting ...")); debugln(F("Connecting ..."));
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(250); delay(250);
Serial.print('.'); debug('.');
} }
Serial.print(F("\nConnected to ")); debug(F("\nConnected to "));
Serial.println(WiFi.SSID()); debugln(WiFi.SSID());
Serial.print(F("IP address:\t")); debug(F("IP address: "));
Serial.println(WiFi.localIP()); debugln(WiFi.localIP());
//---------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------
myTime.setLocation("de"); myTime.setLocation("de");
waitForSync(); waitForSync();
@ -289,17 +327,15 @@ void setup() {
server.on("/toggle", HTTP_GET, handleToggle); server.on("/toggle", HTTP_GET, handleToggle);
server.on("/version", HTTP_GET, server.on("/version", HTTP_GET,
[] { server.send(200, "text/html", version); }); [] { server.send(200, "text/html", version); });
getCurrentTemperatur();
server.begin(); server.begin();
debugln(F("Webserver started")); debugln(F("Webserver started"));
} }
void loop() { void loop() {
server.handleClient(); server.handleClient();
getCurrentTemperatur();
timer(); timer();
r++;
if (r == 7) {
r = 0;
}
yield(); yield();
delay(50); delay(50);
} }