[Changed]: OTA update over http
This commit is contained in:
@@ -9,17 +9,19 @@
|
||||
#include <SPI.h>
|
||||
#include <DS3231.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>;
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h> //https://github.com/agnunez/ESP8266-I2C-LCD1602
|
||||
#include <NTPtimeESP.h> //https://github.com/SensorsIot/NTPtimeESP
|
||||
#include <EEPROM.h>
|
||||
|
||||
String Hardware = "0.10";
|
||||
String Software = "0.05";
|
||||
String Software = "0.06";
|
||||
String ntp_server = "ntp2.uni-augsburg.de";
|
||||
|
||||
// Set web server port number to 80
|
||||
ESP8266WebServer server(80);
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
|
||||
//LED Band Setup
|
||||
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
||||
@@ -36,7 +38,7 @@ CRGB leds[NUM_LEDS];
|
||||
RTClib RTC;
|
||||
DS3231 Clock;
|
||||
//NTP Setup
|
||||
NTPtime NTPch("ntp2.uni-augsburg.de"); // Choose server pool as required
|
||||
NTPtime NTPch(ntp_server); // Choose server pool as required
|
||||
|
||||
//Display
|
||||
LiquidCrystal_I2C lcd(0x3f, 16, 2);
|
||||
@@ -221,34 +223,6 @@ void setup() {
|
||||
|
||||
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();
|
||||
|
||||
setup_webserver();
|
||||
@@ -256,9 +230,6 @@ void setup() {
|
||||
|
||||
|
||||
void loop() {
|
||||
//OTA
|
||||
ArduinoOTA.handle();
|
||||
//OTA
|
||||
handle_webserver();
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long intervall = currentMillis - previousMillis;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
String logfile = "";
|
||||
|
||||
void setup_webserver(){
|
||||
httpUpdater.setup(&server, "Licht", "Wecker");
|
||||
|
||||
server.on("/log", []() { //Define the handling function for the path
|
||||
|
||||
server.send(200, "text/plain", logfile);
|
||||
@@ -16,8 +18,8 @@ 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;\">";
|
||||
String Footer = "</div><br><br><br><div id=\"footer\">Hardware: " + Hardware + ", Software:"+ Software +"</div></body></html> ";
|
||||
String Header = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Lichtwecker</title></head><body style=\"text-align:left;margin:0.5em\"><div id=\"header\"><h1 style=\"margin:0px;padding:0px\">Licht Wecker</h1><hr></div><div id=\"content\" style=\"font-size:1.2em;\">";
|
||||
String Footer = "</div><br><br><hr><div id=\"footer\">Not for Sale, Prototyp by <a href=\"http://christian.mittring-mering.de/\">CHM</a>, Hardware: " + Hardware + ", Software: "+ Software +"</div></body></html> ";
|
||||
|
||||
void handleRootPath() { //Handler for the rooth path
|
||||
handleArgs();
|
||||
@@ -74,6 +76,7 @@ void handleArgs(){
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
||||
print_reset();
|
||||
ESP.restart();
|
||||
break;
|
||||
}
|
||||
@@ -85,16 +88,21 @@ void handleArgs(){
|
||||
void print_website(){
|
||||
bool A1 = Clock.checkAlarmEnabled(1);
|
||||
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 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 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) + "<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) + "<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 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 Reboot = "<br><h3>System:</h3><a href=\"?reset=true\">Neustart</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><br><br><a href=\"update\">Software Update Modus</a>";
|
||||
String Body = Alarm + Zeit + NTP + Reboot;
|
||||
server.send(200, "text/html", Header + Body + Footer);
|
||||
}
|
||||
|
||||
void print_reset(){
|
||||
String Body = "Neustart... <a href=\"/\">Neu laden</a>";
|
||||
server.send(200, "text/html", Header + Body + Footer);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
//Helpers
|
||||
//####################################################################################
|
||||
|
||||
Reference in New Issue
Block a user