Compare commits
7 Commits
main
...
temperatur
Author | SHA1 | Date |
---|---|---|
gilex-dev | f34259c63e | |
gilex-dev | 8f37203b79 | |
gilex-dev | 88baeee58e | |
gilex-dev | 64ef26117f | |
gilex-dev | 07b8a3aacf | |
gilex-dev | 926649004c | |
gilex-dev | 69611e8bfd |
|
@ -8,6 +8,12 @@
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[common_env_data]
|
||||||
|
build_flags = '-D BUILD_VERSION="0.8.3*"'
|
||||||
|
|
||||||
|
[platformio]
|
||||||
|
default_envs = esp12e
|
||||||
|
|
||||||
[env:esp12e]
|
[env:esp12e]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
|
@ -16,3 +22,21 @@ upload_speed = 921600
|
||||||
monitor_speed = 74880
|
monitor_speed = 74880
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ropg/ezTime@^0.8.3
|
ropg/ezTime@^0.8.3
|
||||||
|
paulstoffregen/OneWire@^2.3.7
|
||||||
|
milesburton/DallasTemperature@^3.11.0
|
||||||
|
build_flags = ${common_env_data.build_flags} -D BUILD_DEBUG=0
|
||||||
|
|
||||||
|
[env:esp12e_debug]
|
||||||
|
extends = env:esp12e
|
||||||
|
build_type = debug
|
||||||
|
build_flags = ${common_env_data.build_flags} -D BUILD_DEBUG=1
|
||||||
|
|
||||||
|
[env:esp12e_ota]
|
||||||
|
extends = env:esp12e
|
||||||
|
upload_protocol = espota
|
||||||
|
upload_port = 192.168.2.4
|
||||||
|
build_flags = ${common_env_data.build_flags} -D BUILD_DEBUG=0
|
||||||
|
|
||||||
|
[env:esp12e_ota_debug]
|
||||||
|
extends = env:esp12e_ota
|
||||||
|
build_flags = ${common_env_data.build_flags} -D BUILD_DEBUG=1
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <ezTime.h>
|
#include <ezTime.h>
|
||||||
|
|
||||||
#define DEBUG 1 // 1 for development, 0 for production
|
#if BUILD_DEBUG == 1
|
||||||
|
|
||||||
#if DEBUG == 1
|
|
||||||
#define debug(debugMSG...) Serial.print(debugMSG)
|
#define debug(debugMSG...) Serial.print(debugMSG)
|
||||||
#define debugln(debugMSG...) Serial.println(debugMSG)
|
#define debugln(debugMSG...) Serial.println(debugMSG)
|
||||||
#else
|
#else
|
||||||
|
@ -20,10 +18,13 @@
|
||||||
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 minTemperatureSet;
|
||||||
|
extern int temperature;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
101
src/html.cpp
101
src/html.cpp
|
@ -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
|
||||||
|
{
|
||||||
sprintf(home_html, "<!DOCTYPE html>\
|
sprintf(home_html, "<!DOCTYPE html>\
|
||||||
<html lang='de'>\
|
<html lang='de'>\
|
||||||
<head>\
|
<head>\
|
||||||
|
@ -68,47 +69,35 @@ void reload_home() {
|
||||||
<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>\
|
|
||||||
<span>Ventil 2:</span>\
|
|
||||||
<a href='/toggle?number=1'>%s</a>\
|
|
||||||
</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>\
|
<a class='animated_a' href='/settings'>Einstellungen</a>\
|
||||||
<br>\
|
<br>\
|
||||||
<a class='animated_a' href='#'>Kellerheizung</a>\
|
<a class='animated_a' href='http://192.168.2.5'>Garten Anlage</a>\
|
||||||
</div>\
|
</div>\
|
||||||
</div>\
|
</div>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>",
|
</html>",
|
||||||
myTime.hour(), myTime.minute(), myTime.second(), stat[0], stat[1],
|
myTime.hour(), myTime.minute(), myTime.second(), 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(
|
||||||
|
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'>\
|
||||||
|
</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>\
|
||||||
|
<tr>\
|
||||||
<td>1</td>\
|
<td>1</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
|
@ -157,7 +146,7 @@ void reload_settings() {
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
</tr>\
|
</tr>\
|
||||||
<tr style='display: none'>\
|
<tr>\
|
||||||
<td>8</td>\
|
<td>8</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
|
@ -170,42 +159,44 @@ void reload_settings() {
|
||||||
</div>\
|
</div>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>",
|
</html>",
|
||||||
time_all[0][0], time_all[1][0], time_all[2][0], time_all[3][0],
|
temperatureSet, minTemperatureSet, temperature, time_all[0][0],
|
||||||
time_all[4][0], time_all[5][0], time_all[6][0], time_all[7][0],
|
time_all[1][0], time_all[2][0], time_all[3][0], time_all[4][0],
|
||||||
time_all[0][1], time_all[1][1], time_all[2][1], time_all[3][1],
|
time_all[5][0], time_all[6][0], time_all[7][0], time_all[0][1],
|
||||||
time_all[4][1], time_all[5][1], time_all[6][1], time_all[7][1],
|
time_all[1][1], time_all[2][1], time_all[3][1], time_all[4][1],
|
||||||
time_all[0][2], time_all[1][2], time_all[2][2], time_all[3][2],
|
time_all[5][1], time_all[6][1], time_all[7][1], time_all[0][2],
|
||||||
time_all[4][2], time_all[5][2], time_all[6][2], time_all[7][2],
|
time_all[1][2], time_all[2][2], time_all[3][2], time_all[4][2],
|
||||||
time_all[0][3], time_all[1][3], time_all[2][3], time_all[3][3],
|
time_all[5][2], time_all[6][2], time_all[7][2], time_all[0][3],
|
||||||
time_all[4][3], time_all[5][3], time_all[6][3], time_all[7][3],
|
time_all[1][3], time_all[2][3], time_all[3][3], time_all[4][3],
|
||||||
time_all[0][4], time_all[1][4], time_all[2][4], time_all[3][4],
|
time_all[5][3], time_all[6][3], time_all[7][3], time_all[0][4],
|
||||||
time_all[4][4], time_all[5][4], time_all[6][4], time_all[7][4],
|
time_all[1][4], time_all[2][4], time_all[3][4], time_all[4][4],
|
||||||
time_all[0][5], time_all[1][5], time_all[2][5], time_all[3][5],
|
time_all[5][4], time_all[6][4], time_all[7][4], time_all[0][5],
|
||||||
time_all[4][5], time_all[5][5], time_all[6][5], time_all[7][5],
|
time_all[1][5], time_all[2][5], time_all[3][5], time_all[4][5],
|
||||||
time_all[0][6], time_all[1][6], time_all[2][6], time_all[3][6],
|
time_all[5][5], time_all[6][5], time_all[7][5], time_all[0][6],
|
||||||
time_all[4][6], time_all[5][6], time_all[6][6], time_all[7][6],
|
time_all[1][6], time_all[2][6], time_all[3][6], time_all[4][6],
|
||||||
time_all[0][7], time_all[1][7], time_all[2][7], time_all[3][7],
|
time_all[5][6], time_all[6][6], time_all[7][6], time_all[0][7],
|
||||||
time_all[4][7], time_all[5][7], time_all[6][7], time_all[7][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() {
|
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");
|
||||||
}
|
}
|
||||||
debug(F("Status: "));
|
debug(F("Status: "));
|
||||||
debugln(stat[i]);
|
debugln(stat[i]);
|
||||||
reload_home();
|
|
||||||
server.sendHeader(F("Location"), F("/"), true);
|
server.sendHeader(F("Location"), F("/"), true);
|
||||||
server.send(302, F("text/html"), home_html);
|
server.send(302);
|
||||||
debugln(override[i]);
|
debugln(override[i]);
|
||||||
debugln(F("---------------------------"));
|
debugln(F("---------------------------"));
|
||||||
}
|
}
|
||||||
|
|
292
src/main.cpp
292
src/main.cpp
|
@ -1,39 +1,44 @@
|
||||||
const char SSID[] = "";
|
const char SSID[] = "";
|
||||||
const char PASSWORD[] = "";
|
const char PASSWORD[] = "";
|
||||||
|
|
||||||
const char version[] = " 0.8";
|
|
||||||
#include "globalvars.h"
|
#include "globalvars.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoOTA.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; // D3 on Amica
|
||||||
|
|
||||||
|
const u_int oneWireBus = 0;
|
||||||
|
OneWire oneWire(oneWireBus);
|
||||||
|
DallasTemperature sensors(&oneWire);
|
||||||
|
|
||||||
|
int temperature, temperatureSet, minTemperatureSet;
|
||||||
|
static unsigned long lastTempCycle = -5000;
|
||||||
|
static unsigned long lastTimeCycle = -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[] = {4}; // D2 on Amica
|
||||||
13, 10, 9}; // TODO: only 7 of 8 pins defined
|
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
char stat[8][4] = {"AUS", "AUS", "AUS", "AUS",
|
char stat[][4] = {"AUS"}; // text on button
|
||||||
"AUS", "AUS", "AUS", "AUS"}; // text on button
|
char t_stat[][4] = {""}; // for "status of timer changed"
|
||||||
char t_stat[8][4] = {"", "", "", "",
|
bool override[] = {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>\
|
||||||
|
@ -60,7 +65,7 @@ const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\
|
||||||
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;\
|
||||||
|
@ -70,6 +75,9 @@ const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\
|
||||||
width: -moz-fit-content;\
|
width: -moz-fit-content;\
|
||||||
border-radius: 4px;\
|
border-radius: 4px;\
|
||||||
}\
|
}\
|
||||||
|
.temperature {\
|
||||||
|
width: 2.5em;\
|
||||||
|
}\
|
||||||
.animated_a, [type='submit']{\
|
.animated_a, [type='submit']{\
|
||||||
background-color: rgb(135, 252, 119);\
|
background-color: rgb(135, 252, 119);\
|
||||||
border: none;\
|
border: none;\
|
||||||
|
@ -117,13 +125,14 @@ const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\
|
||||||
*:focus {\
|
*:focus {\
|
||||||
outline: none;\
|
outline: none;\
|
||||||
}\
|
}\
|
||||||
|
span:empty {content: 'nicht verbunden';}\
|
||||||
</style>\
|
</style>\
|
||||||
</head>\
|
</head>\
|
||||||
<body>\
|
<body>\
|
||||||
<div class='wrapper_main'>\
|
<div class='wrapper_main'>\
|
||||||
<form action='settings' method='POST'>\
|
<form action='settings' method='POST'>\
|
||||||
<select name='rule' id='rule' required>\
|
<select name='rule' id='rule'>\
|
||||||
<option value='' selected disabled>Ventiel Nr.</option>\
|
<option value='' selected disabled>Spalte Nr.</option>\
|
||||||
<option value='0'>1</option>\
|
<option value='0'>1</option>\
|
||||||
<option value='1'>2</option>\
|
<option value='1'>2</option>\
|
||||||
<option value='2'>3</option>\
|
<option value='2'>3</option>\
|
||||||
|
@ -131,7 +140,7 @@ const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\
|
||||||
<option value='4'>5</option>\
|
<option value='4'>5</option>\
|
||||||
<option value='5'>6</option>\
|
<option value='5'>6</option>\
|
||||||
<option value='6'>7</option>\
|
<option value='6'>7</option>\
|
||||||
<option value='7' disabled>8</option>\
|
<option value='7'>8</option>\
|
||||||
</select>\
|
</select>\
|
||||||
<br>\
|
<br>\
|
||||||
<input type='time' name='time_o'>\
|
<input type='time' name='time_o'>\
|
||||||
|
@ -139,21 +148,12 @@ const char settings_html_pre[] PROGMEM = {"<!DOCTYPE html>\
|
||||||
<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();
|
||||||
|
void handleReset();
|
||||||
|
void handleRestart();
|
||||||
|
|
||||||
void load_EEPROM() {
|
void load_EEPROM() {
|
||||||
unsigned int EEPROM_Addr = 0;
|
unsigned int EEPROM_Addr = 0;
|
||||||
|
@ -164,6 +164,8 @@ void load_EEPROM() {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
temperatureSet = EEPROM.read(256);
|
||||||
|
minTemperatureSet = EEPROM.read(260);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHome() {
|
void handleHome() {
|
||||||
|
@ -180,7 +182,31 @@ void handleSettings() {
|
||||||
debugln(ESP.getFreeHeap(), DEC);
|
debugln(ESP.getFreeHeap(), DEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleReset() {
|
||||||
|
for (int i = 0; i < 264; i++) {
|
||||||
|
EEPROM.put(i, 0);
|
||||||
|
EEPROM.commit();
|
||||||
|
}
|
||||||
|
server.send(200, "text/html",
|
||||||
|
"<html><head><meta http-equiv=\"refresh\" "
|
||||||
|
"content=\"2;url=/restart\"/></head><body><p>EEPROM has been "
|
||||||
|
"reset.</p></body></html>");
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleRestart() {
|
||||||
|
server.send(200, "text/html",
|
||||||
|
"<html><head><meta http-equiv=\"refresh\" "
|
||||||
|
"content=\"10;url=/\"/></head><body><p>Restarting...</p></"
|
||||||
|
"body></html>");
|
||||||
|
server.close();
|
||||||
|
delay(1000);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
void handleTime() {
|
void handleTime() {
|
||||||
|
bool changed = false;
|
||||||
|
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++) {
|
||||||
|
@ -191,39 +217,78 @@ void handleTime() {
|
||||||
server.arg(args[arg])[4]};
|
server.arg(args[arg])[4]};
|
||||||
sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s%s",
|
sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s%s",
|
||||||
buff_h[0], buff_h[1]);
|
buff_h[0], buff_h[1]);
|
||||||
sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()], "%s%s",
|
sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()],
|
||||||
buff_m[0], buff_m[1]);
|
"%s%s", buff_m[0], buff_m[1]);
|
||||||
|
|
||||||
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()]));
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
EEPROM.put(server.arg("rule").toInt() * 4 + arg * 64 + 32,
|
EEPROM.put(
|
||||||
|
server.arg("rule").toInt() * 4 + arg * 64 + 32,
|
||||||
atoi(time_all[arg * 2 + 1][server.arg("rule").toInt()]));
|
atoi(time_all[arg * 2 + 1][server.arg("rule").toInt()]));
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (server.arg("temperature").toInt() != temperatureSet) {
|
||||||
|
debugln("write temperature");
|
||||||
|
temperatureSet = server.arg("temperature").toInt();
|
||||||
|
EEPROM.put(256, temperatureSet);
|
||||||
|
EEPROM.commit();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (server.arg("min_temperature").toInt() != minTemperatureSet) {
|
||||||
|
debugln("write minTemperature");
|
||||||
|
minTemperatureSet = server.arg("min_temperature").toInt();
|
||||||
|
EEPROM.put(260, minTemperatureSet);
|
||||||
|
EEPROM.commit();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
lastTimeCycle = -5000; // trigger timer()
|
||||||
reload_settings();
|
reload_settings();
|
||||||
server.setContentLength(strlen(settings_html_pre) + strlen(settings_html));
|
server.sendHeader(F("Location"), F("/settings"), true);
|
||||||
server.send(301, "text/html", settings_html_pre);
|
server.send(302);
|
||||||
server.sendContent(settings_html);
|
} else {
|
||||||
|
server.send(204); // nothing changed (except maybe current temperature),
|
||||||
|
// so no page update needed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer() {
|
void timer() {
|
||||||
if (((myTime.hour() * 60 + myTime.minute() >=
|
if (millis() - lastTimeCycle > 5000) {
|
||||||
atoi(time_all[0][r]) * 60 + atoi(time_all[1][r])) and
|
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() <
|
(myTime.hour() * 60 + myTime.minute() <
|
||||||
atoi(time_all[2][r]) * 60 + atoi(time_all[3][r]))) or
|
atoi(time_all[2][ri]) * 60 +
|
||||||
((myTime.hour() * 60 + myTime.minute() >=
|
atoi(time_all[3][ri]))) // first range
|
||||||
atoi(time_all[4][r]) * 60 + atoi(time_all[5][r])) and
|
or ((myTime.hour() * 60 + myTime.minute() >=
|
||||||
|
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) or
|
||||||
|
temperature <= minTemperatureSet) {
|
||||||
|
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);
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 100); // 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 +301,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);
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 0); // 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"));
|
||||||
|
@ -244,62 +310,146 @@ void timer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastTimeCycle = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint ledBrightness = 0;
|
||||||
|
int ledBrightnessStep = 20;
|
||||||
|
uint lastLedCycle;
|
||||||
|
void pulseLed() {
|
||||||
|
if (millis() - lastLedCycle > 100) {
|
||||||
|
analogWrite(LED_BUILTIN_AUX, ledBrightness);
|
||||||
|
ledBrightness += ledBrightnessStep;
|
||||||
|
if (ledBrightness <= 0 || ledBrightness >= 255) {
|
||||||
|
ledBrightnessStep = -ledBrightnessStep;
|
||||||
|
}
|
||||||
|
lastLedCycle = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void emergencyStop() {
|
||||||
|
for (uint pin = 0; pin < sizeof(pins) / sizeof(pins[0]); pin++) {
|
||||||
|
debug("Emergency stop, pulling down pin: ");
|
||||||
|
debugln(pin);
|
||||||
|
digitalWrite(pins[pin], LOW);
|
||||||
|
}
|
||||||
|
server.close();
|
||||||
|
char apSSID[32];
|
||||||
|
sprintf(apSSID, "ESP-%06X has an issue", ESP.getChipId());
|
||||||
|
WiFi.softAP(apSSID, "", 1, false, 0);
|
||||||
|
unsigned long lastTry = millis();
|
||||||
|
while (millis() - lastTry < (1000 * 60)) {
|
||||||
|
analogWrite(LED_BUILTIN, 255);
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 0);
|
||||||
|
delay(125);
|
||||||
|
analogWrite(LED_BUILTIN, 0);
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 255);
|
||||||
|
delay(125);
|
||||||
|
analogWrite(LED_BUILTIN, 255);
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 255);
|
||||||
|
delay(250);
|
||||||
|
}
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void getCurrentTemperature() {
|
||||||
|
if (millis() - lastTempCycle > 5000) {
|
||||||
|
sensors.requestTemperatures();
|
||||||
|
temperature = int(sensors.getTempCByIndex(0));
|
||||||
|
lastTempCycle = millis();
|
||||||
|
if (temperature == -127) {
|
||||||
|
emergencyStop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
int p = 0;
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
while (p <= 7) {
|
pinMode(LED_BUILTIN_AUX, OUTPUT);
|
||||||
|
analogWrite(LED_BUILTIN, 255);
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 255);
|
||||||
|
uint p = 0;
|
||||||
|
while (p <= sizeof(pins) / sizeof(pins[0])) {
|
||||||
pinMode(pins[p], OUTPUT);
|
pinMode(pins[p], OUTPUT);
|
||||||
digitalWrite(pins[p], HIGH);
|
digitalWrite(pins[p], LOW);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
Serial.begin(74880);
|
Serial.begin(74880);
|
||||||
EEPROM.begin(256); // 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. "));
|
debug(F("\nver. "));
|
||||||
debugln(version);
|
debug(BUILD_VERSION);
|
||||||
|
debugln(BUILD_DEBUG ? "-debug" : "");
|
||||||
debugln(F("check for updates at "
|
debugln(F("check for updates at "
|
||||||
"https://somepi.ddns.net/gitea/gilex-dev/ESP8266-IOT-timer/\n"));
|
"https://somepi.ddns.net/gitea/gilex-dev/ESP8266-IOT-timer/\n"));
|
||||||
load_EEPROM();
|
load_EEPROM();
|
||||||
// WLAN-config
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// WiFI-config
|
||||||
WiFi.mode(WIFI_STA);
|
// WiFi.mode(WIFI_STA); // comment to force use of staticIP
|
||||||
WiFi.config(staticIP, gateway, subnet, dns);
|
// WiFi.config(staticIP, gateway, subnet, dns);
|
||||||
WiFi.hostname("ESP8266 IOT development");
|
WiFi.hostname("esp8266-iot-dev");
|
||||||
WiFi.begin(SSID, PASSWORD);
|
WiFi.begin(SSID, PASSWORD);
|
||||||
|
|
||||||
Serial.println(F("Connecting ..."));
|
uint32_t notConnectedCounter = 0;
|
||||||
|
debug(F("Connecting to "));
|
||||||
|
debugln(WiFi.SSID());
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(250);
|
delay(250);
|
||||||
Serial.print('.');
|
debug(F("."));
|
||||||
|
analogWrite(LED_BUILTIN_AUX, 255 * (notConnectedCounter % 2)); // LED
|
||||||
|
notConnectedCounter++;
|
||||||
|
if (notConnectedCounter >
|
||||||
|
(1000 / 250) * 15) { // Reset board if not connected after 15s
|
||||||
|
debugln("\nResetting due to Wifi not connecting");
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
Serial.print(F("\nConnected to "));
|
}
|
||||||
Serial.println(WiFi.SSID());
|
analogWrite(LED_BUILTIN_AUX, 0);
|
||||||
Serial.print(F("IP address:\t"));
|
debug(F("\nConnected to "));
|
||||||
Serial.println(WiFi.localIP());
|
debugln(WiFi.SSID());
|
||||||
//----------------------------------------------------------------------------------------------------------------------------------
|
debug(F("IP address: "));
|
||||||
myTime.setLocation("de");
|
debugln(WiFi.localIP());
|
||||||
waitForSync();
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
|
// Time-config
|
||||||
|
myTime.setLocation("de");
|
||||||
|
// setServer("192.168.2.1"); // uncomment to set custom NTP server
|
||||||
|
if (!waitForSync(TIMEZONED_TIMEOUT / 1000)) {
|
||||||
|
// Reset instead of using fallback timezone
|
||||||
|
debugln("\nResetting due to NTP not syncing");
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
debug(F("Local time: "));
|
debug(F("Local time: "));
|
||||||
debugln(myTime.dateTime("H:i:s"));
|
debugln(myTime.dateTime("H:i:s"));
|
||||||
setInterval();
|
setInterval(60 * 60 * 11); // + NTP_STALE_AFTER=3602 = sync every ~ 12 h
|
||||||
|
|
||||||
|
// Server-config
|
||||||
server.on("/", HTTP_GET, handleHome);
|
server.on("/", HTTP_GET, handleHome);
|
||||||
server.on("/settings", HTTP_GET, handleSettings);
|
server.on("/settings", HTTP_GET, handleSettings);
|
||||||
server.on("/settings", HTTP_POST, handleTime);
|
server.on("/settings", HTTP_POST, handleTime);
|
||||||
server.on("/toggle", HTTP_GET, handleToggle);
|
server.on("/toggle", HTTP_GET, handleToggle);
|
||||||
server.on("/version", HTTP_GET,
|
server.on("/reset", HTTP_GET, handleReset);
|
||||||
[] { server.send(200, "text/html", version); });
|
server.on("/restart", HTTP_GET, handleRestart);
|
||||||
|
server.on("/version", HTTP_GET, [] {
|
||||||
|
char softwareVersion[32];
|
||||||
|
sprintf(softwareVersion, "%s%s", BUILD_VERSION,
|
||||||
|
BUILD_DEBUG ? "-debug" : "");
|
||||||
|
server.send(200, "text/html", softwareVersion);
|
||||||
|
});
|
||||||
|
|
||||||
|
getCurrentTemperature();
|
||||||
server.begin();
|
server.begin();
|
||||||
debugln(F("Webserver started"));
|
debugln(F("Webserver started"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
|
getCurrentTemperature();
|
||||||
timer();
|
timer();
|
||||||
r++;
|
|
||||||
if (r == 7) {
|
|
||||||
r = 0;
|
|
||||||
}
|
|
||||||
yield();
|
yield();
|
||||||
delay(50);
|
delay(50);
|
||||||
|
events();
|
||||||
|
ArduinoOTA.handle();
|
||||||
|
pulseLed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue