Compare commits
2
Commits
0.05
...
05cdb44ab5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05cdb44ab5 | ||
|
|
60755333bf |
@@ -9,17 +9,19 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <DS3231.h>
|
#include <DS3231.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ESP8266HTTPUpdateServer.h>;
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h> //https://github.com/agnunez/ESP8266-I2C-LCD1602
|
#include <LiquidCrystal_I2C.h> //https://github.com/agnunez/ESP8266-I2C-LCD1602
|
||||||
#include <NTPtimeESP.h> //https://github.com/SensorsIot/NTPtimeESP
|
#include <NTPtimeESP.h> //https://github.com/SensorsIot/NTPtimeESP
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
String Hardware = "0.10";
|
String Hardware = "0.10";
|
||||||
String Software = "0.05";
|
String Software = "0.07";
|
||||||
|
String ntp_server = "ntp2.uni-augsburg.de";
|
||||||
|
|
||||||
// Set web server port number to 80
|
// Set web server port number to 80
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
//LED Band Setup
|
//LED Band Setup
|
||||||
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
||||||
@@ -36,7 +38,7 @@ CRGB leds[NUM_LEDS];
|
|||||||
RTClib RTC;
|
RTClib RTC;
|
||||||
DS3231 Clock;
|
DS3231 Clock;
|
||||||
//NTP Setup
|
//NTP Setup
|
||||||
NTPtime NTPch("ntp2.uni-augsburg.de"); // Choose server pool as required
|
NTPtime NTPch(ntp_server); // Choose server pool as required
|
||||||
|
|
||||||
//Display
|
//Display
|
||||||
LiquidCrystal_I2C lcd(0x3f, 16, 2);
|
LiquidCrystal_I2C lcd(0x3f, 16, 2);
|
||||||
@@ -221,44 +223,13 @@ void setup() {
|
|||||||
|
|
||||||
previousMillis = millis();
|
previousMillis = millis();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------
|
|
||||||
//OTA
|
|
||||||
// No authentication by default
|
|
||||||
|
|
||||||
ArduinoOTA.setPassword(NodeName.c_str());
|
|
||||||
ArduinoOTA.setHostname(NodeName.c_str());
|
|
||||||
|
|
||||||
ArduinoOTA.onStart([]() {
|
|
||||||
write_log("Start");
|
|
||||||
});
|
|
||||||
ArduinoOTA.onEnd([]() {
|
|
||||||
write_log("\nEnd");
|
|
||||||
});
|
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
||||||
write_log("Progress: " + String(progress / (total / 100)));
|
|
||||||
});
|
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
|
||||||
write_log("Error: " + String(error));
|
|
||||||
if (error == OTA_AUTH_ERROR) write_log("Auth Failed");
|
|
||||||
else if (error == OTA_BEGIN_ERROR) write_log("Begin Failed");
|
|
||||||
else if (error == OTA_CONNECT_ERROR) write_log("Connect Failed");
|
|
||||||
else if (error == OTA_RECEIVE_ERROR) write_log("Receive Failed");
|
|
||||||
else if (error == OTA_END_ERROR) write_log("End Failed");
|
|
||||||
});
|
|
||||||
ArduinoOTA.begin();
|
|
||||||
//-------------------------------------------------
|
|
||||||
update_time_from_web();
|
update_time_from_web();
|
||||||
|
|
||||||
setup_webserver();
|
setup_webserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//OTA
|
|
||||||
ArduinoOTA.handle();
|
|
||||||
//OTA
|
|
||||||
handle_webserver();
|
handle_webserver();
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
unsigned long intervall = currentMillis - previousMillis;
|
unsigned long intervall = currentMillis - previousMillis;
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
String logfile = "";
|
String logfile = "";
|
||||||
|
//Webserver
|
||||||
|
//###################################################################################
|
||||||
|
|
||||||
void setup_webserver(){
|
void setup_webserver(){
|
||||||
|
httpUpdater.setup(&server, "Licht", "Wecker");
|
||||||
|
|
||||||
server.on("/log", []() { //Define the handling function for the path
|
server.on("/log", []() { //Define the handling function for the path
|
||||||
|
|
||||||
server.send(200, "text/plain", logfile);
|
server.send(200, "text/plain", logfile);
|
||||||
@@ -16,8 +20,15 @@ void handle_webserver(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String Header = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Lichtwecker</title></head><body><div id=\"header\"><h1>Licht Wecker</h1></div><div id=\"content\" style=\"font-size:1.2em;\">";
|
//Layout
|
||||||
String Footer = "</div><br><br><br><div id=\"footer\">Hardware: " + Hardware + ", Software:"+ Software +"</div></body></html> ";
|
//###################################################################################
|
||||||
|
|
||||||
|
String Meta = "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\"><meta charset=\"UTF-8\">";
|
||||||
|
String CSS = "<style>.card {box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);background-color: white;transition: 0.3s;margin: 0.2rem;padding: 0.4rem;padding-top: 0.5rem;display: inline-block;display: -webkit-inline-block;text-align:center;flex: 1;-webkit-flex: 1 1 250px;}.cardcontainer {box-sizing: border-box;display:flex;flex-wrap: wrap;display: -webkit-flex;-webkit-flex-wrap: wrap;overflow:auto;}#footer {border-top: 3px solid darkblue;-webkit-justify-content: space-around;display: absolute;justify-content: space-around;}</style>";
|
||||||
|
String Header = "<!DOCTYPE html><html><head>" + Meta + CSS + "<title>Lichtwecker</title></head><body style=\"text-align:left;margin: 0px;padding: 0px;\"><div id=\"header\" style=\"background-color: blue;margin: 0px;padding: 0px;color: white;border: 0.2em solid blue;text-align: center;\"><h1 style=\"margin:0px;padding:0px\">Licht Wecker</h1></div><div id=\"content\" style=\"font-size:1.2em;margin:0.5em;\" class=\"cardcontainer\">";
|
||||||
|
String Footer = "</div><br><br><div id=\"footer\">Not for Sale, Prototyp by <a href=\"http://christian.mittring-mering.de/\">CHM</a>, Hardware: " + Hardware + ", Software: "+ Software +"</div></body></html> ";
|
||||||
|
String card_start = "<div class=\"card\">";
|
||||||
|
String card_end = "</div>";
|
||||||
|
|
||||||
void handleRootPath() { //Handler for the rooth path
|
void handleRootPath() { //Handler for the rooth path
|
||||||
handleArgs();
|
handleArgs();
|
||||||
@@ -74,6 +85,7 @@ void handleArgs(){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
||||||
|
print_reset();
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -82,19 +94,27 @@ void handleArgs(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Webpage
|
||||||
|
//###################################################################################
|
||||||
|
|
||||||
void print_website(){
|
void print_website(){
|
||||||
bool A1 = Clock.checkAlarmEnabled(1);
|
bool A1 = Clock.checkAlarmEnabled(1);
|
||||||
bool A2 = Clock.checkAlarmEnabled(2);
|
bool A2 = Clock.checkAlarmEnabled(2);
|
||||||
String Alarm1 = "Alarm 1: <form action=\"/\" methode=\"get\"><input type=\"text\" name=\"al1h\" value=\"" + String(al1h) + "\">:<input type=\"text\" name=\"al1m\" value=\"" + String(al1m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + " Aktiv: " + getBoolString(A1) + "<br><a href=\"?a1=true\">Aktivieren</a> " + " <a href=\"?a1=false\">Deaktivieren</a>";
|
String Alarm1 = "<b>Alarm 1:</b> <form action=\"/\" methode=\"get\"><input type=\"number\" name=\"al1h\" value=\"" + String(al1h) + "\">:<input type=\"number\" name=\"al1m\" value=\"" + String(al1m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + "<br>Aktiv: " + getBoolString(A1) + "<br><a href=\"?a1=true\">Aktivieren</a> " + " <a href=\"?a1=false\">Deaktivieren</a>";
|
||||||
String Alarm2 = "Alarm 2: <form action=\"/\" methode=\"get\"><input type=\"text\" name=\"al2h\" value=\"" + String(al2h) + "\">:<input type=\"text\" name=\"al2m\" value=\"" + String(al2m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + " Aktiv: " + getBoolString(A2) + "<br><a href=\"?a2=true\">Aktivieren</a> " + " <a href=\"?a2=false\">Deaktivieren</a>";
|
String Alarm2 = "<b>Alarm 2:</b> <form action=\"/\" methode=\"get\"><input type=\"number\" name=\"al2h\" value=\"" + String(al2h) + "\">:<input type=\"number\" name=\"al2m\" value=\"" + String(al2m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + "<br>Aktiv: " + getBoolString(A2) + "<br><a href=\"?a2=true\">Aktivieren</a> " + " <a href=\"?a2=false\">Deaktivieren</a>";
|
||||||
String Alarm = "<h3>Alarm</h3>" + Alarm1 + "<br><br>" + Alarm2;
|
String Alarm = "<h3>Alarm</h3>" + Alarm1 + "<br><br>" + Alarm2;
|
||||||
String Zeit = "<br><h3>Zeit</h3>" + String(h) + ":" + String(m) + ":" + String(s) + " - " + String(d) + "." + String(M) + "." + String(y) + " | DST: " + String(summertime_EU(y,M,d,h,1));
|
String Zeit = "<br><h3>Zeit</h3>" + String(h) + ":" + String(m) + ":" + String(s) + " - " + String(d) + "." + String(M) + "." + String(y) + " | DST: " + String(summertime_EU(y,M,d,h,1));
|
||||||
String NTP = "<br><h3>NTP</h3>" + String("stündliches Zeit Update über Netzwerk: ") + getBoolString(ntp_update) + "<br><a href=\"?ntp=true\">Aktivieren</a> " + " <a href=\"?ntp=false\">Deaktivieren</a>";
|
String NTP = "<br><h3>NTP</h3>" + String("stündliches Zeit Update über " + ntp_server + ": ") + getBoolString(ntp_update) + "<br><a href=\"?ntp=true\">Aktivieren</a> " + " <a href=\"?ntp=false\">Deaktivieren</a>";
|
||||||
String Reboot = "<br><h3>System:</h3><a href=\"?reset=true\">Neustart</a>";
|
String Reboot = "<br><h3>System:</h3><a href=\"?reset=true\">Neustart</a><br><br><a href=\"update\">Software Update Modus</a>";
|
||||||
String Body = Alarm + Zeit + NTP + Reboot;
|
String Body = card_start + Alarm + card_end + card_start + Zeit + card_end + card_start + NTP + card_end + card_start + Reboot + card_end;
|
||||||
server.send(200, "text/html", Header + Body + Footer);
|
server.send(200, "text/html", Header + Body + Footer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_reset(){
|
||||||
|
String Body = "<div class=\"card\">Neustart... <a href=\"/\">Neu laden</a></div>";
|
||||||
|
server.send(200, "text/html", Header + Body + Footer);
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
//Helpers
|
//Helpers
|
||||||
//####################################################################################
|
//####################################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user