apply formatting guidelines to existing files & remove unused dep
This commit is contained in:
parent
61aaca8510
commit
dd55af6d9c
|
@ -16,5 +16,3 @@ 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
|
|
||||||
|
|
110
src/html.cpp
110
src/html.cpp
|
@ -2,24 +2,24 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
void reload_home() {
|
void reload_home() {
|
||||||
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());
|
||||||
} else {
|
} else {
|
||||||
sprintf(time_current[0], "%d", myTime.hour());
|
sprintf(time_current[0], "%d", myTime.hour());
|
||||||
}
|
}
|
||||||
if (myTime.minute() < 10) {
|
if (myTime.minute() < 10) {
|
||||||
sprintf(time_current[1], "0%d", myTime.minute());
|
sprintf(time_current[1], "0%d", myTime.minute());
|
||||||
} else {
|
} else {
|
||||||
sprintf(time_current[1], "%d", myTime.minute());
|
sprintf(time_current[1], "%d", myTime.minute());
|
||||||
}
|
}
|
||||||
if (myTime.second() < 10) {
|
if (myTime.second() < 10) {
|
||||||
sprintf(time_current[2], "0%d", myTime.second());
|
sprintf(time_current[2], "0%d", myTime.second());
|
||||||
} else {
|
} else {
|
||||||
sprintf(time_current[2], "%d", myTime.second());
|
sprintf(time_current[2], "%d", myTime.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
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'>\
|
||||||
|
@ -120,12 +120,12 @@ void reload_home() {
|
||||||
</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[1],
|
||||||
stat[2], stat[3], stat[4], stat[5], stat[6], stat[7]);
|
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, "<tr>\
|
||||||
<td>1</td>\
|
<td>1</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
<td>%s:%s</td>\
|
<td>%s:%s</td>\
|
||||||
|
@ -187,42 +187,42 @@ 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],
|
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[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[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[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[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[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[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[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[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[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[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[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[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[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[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]);
|
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 = server.arg("number")
|
||||||
.toInt(); // converts GET argument to int and does stuff xD
|
.toInt(); // converts GET argument to int and does stuff xD
|
||||||
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) {
|
if (digitalRead(pins[i]) == LOW) {
|
||||||
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();
|
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, F("text/html"), home_html);
|
||||||
debugln(override[i]);
|
debugln(override[i]);
|
||||||
debugln(F("---------------------------"));
|
debugln(F("---------------------------"));
|
||||||
}
|
}
|
||||||
|
|
268
src/main.cpp
268
src/main.cpp
|
@ -12,27 +12,27 @@ const char version[] = " 0.8";
|
||||||
|
|
||||||
ESP8266WebServer server;
|
ESP8266WebServer server;
|
||||||
IPAddress staticIP(192, 168, 2, 5); // static IP address
|
IPAddress staticIP(192, 168, 2, 5); // 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;
|
||||||
|
|
||||||
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[8] = {5, 4, 14, 12,
|
||||||
13, 10, 9}; // TODO: only 7 of 8 pins defined
|
13, 10, 9}; // TODO: only 7 of 8 pins defined
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
char stat[8][4] = {"AUS", "AUS", "AUS", "AUS",
|
char stat[8][4] = {"AUS", "AUS", "AUS", "AUS",
|
||||||
"AUS", "AUS", "AUS", "AUS"}; // text on button
|
"AUS", "AUS", "AUS", "AUS"}; // text on button
|
||||||
char t_stat[8][4] = {"", "", "", "",
|
char t_stat[8][4] = {"", "", "", "",
|
||||||
"", "", "", ""}; // for "status of timer changed"
|
"", "", "", ""}; // for "status of timer changed"
|
||||||
bool override[8] = {false, false, false, false,
|
bool override[8] = {false, false, false, false,
|
||||||
false, false, false, false}; // for manual override
|
false, false, false, false}; // for manual override
|
||||||
|
|
||||||
char home_html[3000]; // be careful when changing these values (might cause
|
char home_html[3000]; // be careful when changing these values (might cause
|
||||||
// overflow)!
|
// overflow)!
|
||||||
char settings_html[2014];
|
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'>\
|
||||||
|
@ -156,150 +156,154 @@ void reload_settings();
|
||||||
void handleToggle();
|
void handleToggle();
|
||||||
|
|
||||||
void load_EEPROM() {
|
void load_EEPROM() {
|
||||||
unsigned int EEPROM_Addr = 0;
|
unsigned int EEPROM_Addr = 0;
|
||||||
for (unsigned int i0 = 0; i0 < 8; i0++) {
|
for (unsigned int i0 = 0; i0 < 8; i0++) {
|
||||||
for (unsigned int i = 0; i < 8; i++) {
|
for (unsigned int i = 0; i < 8; i++) {
|
||||||
if (EEPROM.read(EEPROM_Addr) < 10) {
|
if (EEPROM.read(EEPROM_Addr) < 10) {
|
||||||
sprintf(time_all[i0][i], "0%d", EEPROM.read(EEPROM_Addr));
|
sprintf(time_all[i0][i], "0%d", EEPROM.read(EEPROM_Addr));
|
||||||
} else {
|
} else {
|
||||||
sprintf(time_all[i0][i], "%d", EEPROM.read(EEPROM_Addr));
|
sprintf(time_all[i0][i], "%d", EEPROM.read(EEPROM_Addr));
|
||||||
}
|
}
|
||||||
EEPROM_Addr += 4;
|
EEPROM_Addr += 4;
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHome() {
|
void handleHome() {
|
||||||
reload_home();
|
reload_home();
|
||||||
server.send(200, "text/html", home_html);
|
server.send(200, "text/html", home_html);
|
||||||
debugln(ESP.getFreeHeap(), DEC);
|
debugln(ESP.getFreeHeap(), DEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSettings() {
|
void handleSettings() {
|
||||||
reload_settings();
|
reload_settings();
|
||||||
server.setContentLength(strlen(settings_html_pre) + strlen(settings_html));
|
server.setContentLength(strlen(settings_html_pre) + strlen(settings_html));
|
||||||
server.send(200, "text/html", settings_html_pre);
|
server.send(200, "text/html", settings_html_pre);
|
||||||
server.sendContent(settings_html);
|
server.sendContent(settings_html);
|
||||||
debugln(ESP.getFreeHeap(), DEC);
|
debugln(ESP.getFreeHeap(), DEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleTime() {
|
void handleTime() {
|
||||||
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]};
|
||||||
sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s", buff_h);
|
char buff_m[2][2] = {server.arg(args[arg])[3],
|
||||||
sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()], "%s", buff_m);
|
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);
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
||||||
server.sendContent(settings_html);
|
server.sendContent(settings_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer() {
|
void timer() {
|
||||||
if (((myTime.hour() * 60 + myTime.minute() >=
|
if (((myTime.hour() * 60 + myTime.minute() >=
|
||||||
atoi(time_all[0][r]) * 60 + atoi(time_all[1][r])) and
|
atoi(time_all[0][r]) * 60 + atoi(time_all[1][r])) 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][r]) * 60 + atoi(time_all[3][r]))) or
|
||||||
((myTime.hour() * 60 + myTime.minute() >=
|
((myTime.hour() * 60 + myTime.minute() >=
|
||||||
atoi(time_all[4][r]) * 60 + atoi(time_all[5][r])) and
|
atoi(time_all[4][r]) * 60 + atoi(time_all[5][r])) 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][r]) * 60 + atoi(time_all[7][r])))) {
|
||||||
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], LOW);
|
||||||
if (strcmp(stat[r], "AUS") == 0) {
|
if (strcmp(stat[r], "AUS") == 0) {
|
||||||
debug(r);
|
debug(r);
|
||||||
debugln(F(" is on"));
|
debugln(F(" is on"));
|
||||||
sprintf(stat[r], "AN");
|
sprintf(stat[r], "AN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((override[r]) and (strcmp(t_stat[r], "on") == 0)) {
|
if ((override[r]) and (strcmp(t_stat[r], "on") == 0)) {
|
||||||
override[r] = false;
|
override[r] = false;
|
||||||
}
|
}
|
||||||
sprintf(t_stat[r], "off");
|
sprintf(t_stat[r], "off");
|
||||||
if (!override[r]) {
|
if (!override[r]) {
|
||||||
digitalWrite(pins[r], HIGH);
|
digitalWrite(pins[r], HIGH);
|
||||||
if (strcmp(stat[r], "AN") == 0) {
|
if (strcmp(stat[r], "AN") == 0) {
|
||||||
debug(r);
|
debug(r);
|
||||||
debugln(F(" is off"));
|
debugln(F(" is off"));
|
||||||
sprintf(stat[r], "AUS");
|
sprintf(stat[r], "AUS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
digitalWrite(pins[p], HIGH);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
Serial.begin(74880);
|
Serial.begin(74880);
|
||||||
EEPROM.begin(256); // 4 bits for EEPROM, address 0-255, value 0-255
|
EEPROM.begin(256); // 4 bits for EEPROM, address 0-255, value 0-255
|
||||||
debug(F("\nver."));
|
debug(F("\nver."));
|
||||||
debugln(version);
|
debugln(version);
|
||||||
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
|
// WLAN-config
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.config(staticIP, gateway, subnet, dns);
|
WiFi.config(staticIP, gateway, subnet, dns);
|
||||||
WiFi.hostname("ESP8266 IOT development");
|
WiFi.hostname("ESP8266 IOT development");
|
||||||
WiFi.begin(SSID, PASSWORD);
|
WiFi.begin(SSID, PASSWORD);
|
||||||
|
|
||||||
Serial.println(F("Connecting ..."));
|
Serial.println(F("Connecting ..."));
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(250);
|
delay(250);
|
||||||
Serial.print('.');
|
Serial.print('.');
|
||||||
}
|
}
|
||||||
Serial.print(F("\nConnected to "));
|
Serial.print(F("\nConnected to "));
|
||||||
Serial.println(WiFi.SSID());
|
Serial.println(WiFi.SSID());
|
||||||
Serial.print(F("IP address:\t"));
|
Serial.print(F("IP address:\t"));
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
//----------------------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------------------
|
||||||
myTime.setLocation("de");
|
myTime.setLocation("de");
|
||||||
waitForSync();
|
waitForSync();
|
||||||
|
|
||||||
debug(F("Local time: "));
|
debug(F("Local time: "));
|
||||||
debugln(myTime.dateTime("H:i:s"));
|
debugln(myTime.dateTime("H:i:s"));
|
||||||
setInterval();
|
setInterval();
|
||||||
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("/version", HTTP_GET,
|
||||||
[] { server.send(200, "text/html", version); });
|
[] { server.send(200, "text/html", version); });
|
||||||
server.begin();
|
server.begin();
|
||||||
debugln(F("Webserver started"));
|
debugln(F("Webserver started"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
timer();
|
timer();
|
||||||
r++;
|
r++;
|
||||||
if (r == 7) {
|
if (r == 7) {
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
yield();
|
yield();
|
||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue