diff --git a/src/WifiManager.cpp b/src/WifiManager.cpp index d4c5ad4..12b57e7 100644 --- a/src/WifiManager.cpp +++ b/src/WifiManager.cpp @@ -2,17 +2,95 @@ // Created by lukas on 10.04.20. // +#include #include "WifiManager.h" void WifiManager::init() { Serial.print("Setting up Access Point"); + // start softap boolean result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2"); - if(result == true) - { + if (result == true) { Serial.println("Wifi Ready"); - } - else - { + Serial.println( WiFi.softAPIP()); + + + server.on("/", HTTP_GET, [this](){ + handleRoot(); + }); + + server.on("/get", [this](){ + handleGet(); + }); + server.onNotFound([this](){ + handleNotFound(); + }); + + server.begin(); + } else { Serial.println("Wifi Setup failed!"); } } + +WifiManager::WifiManager() : server(80) {} + +void WifiManager::handleRoot() { + Serial.println("HomePage called"); + + int value = 0; + EEPROM.begin(4096); // init the eeprom + EEPROM.get(0, value); + EEPROM.end(); // stop the eeprom communication + + const String index_html = "\n" + " Wastinfoboard-ConfigurationPage\n" + " \n" + " \n" + "
Aktuelle Zeit: "+ String(value) +" Minuten
\n" + "
\n" + " Zeit setzen: \n" + " \n" + "

\n" + " \n" + " " + " \n" + ""; + + server.send(200, "text/html", index_html); +} + +void WifiManager::handleNotFound() { + server.send(404, "text/plain", + "404: Not found"); // Send HTTP status 404 (Not Found) when there's no handler for the URI in the request +} + +void WifiManager::handleGet() { + Serial.println("get called"); + String s = "\n" + " Wastinfoboard-ConfigurationPage\n" + " \n" + " \n" + " \n" + ""; + + Serial.println(server.arg("time")); + + if (server.arg("time") != "") { + int time = atoi(server.arg("time").c_str()); //Gets the value of the query parameter + //manager.setSSID(message); + + EEPROM.begin(4096); // init the eeprom + EEPROM.put(0, time); + EEPROM.commit(); // write the changes to the eeprom + EEPROM.end(); // stop the eeprom communication + } else if (server.arg("reset") != "") { + Serial.println("Reset ..."); + ESP.reset(); + } +// manager.storeVars(); + Serial.println("send get back"); + server.send(200, "text/html", s); //Send web page +} + +void WifiManager::holdAlive() { + server.handleClient(); +} diff --git a/src/WifiManager.h b/src/WifiManager.h index 3d41930..00218b7 100644 --- a/src/WifiManager.h +++ b/src/WifiManager.h @@ -6,9 +6,21 @@ #include #include +#include class WifiManager { public: + WifiManager(); + void init(); + void holdAlive(); +private: + ESP8266WebServer server; + + void handleRoot(); + + void handleNotFound(); + + void handleGet(); }; diff --git a/src/main.cpp b/src/main.cpp index 08ef094..78a155a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "WifiManager.h" @@ -14,7 +15,7 @@ static const uint8_t DruckSensorPin = 12; static const uint8_t SchuetzPin = 13; /** time config */ -static const int abschaltzeit = 7200; //sek +static int abschaltzeit = 7200; //sek static const int maxpumpdauer = 600; //sek // ticker fuer kein-wasser abschaltung @@ -23,6 +24,8 @@ Ticker status; //pumpendauer maximum ticker Ticker pumpendauer; +WifiManager mang; + int turnontime = -1; void pumpeSchalten(bool on) { @@ -140,6 +143,15 @@ void setup() { delay(1000); //allow = digitalRead(WasserSensorPin); allow = true; + + int value = 0; + EEPROM.begin(4096); // init the eeprom + EEPROM.get(0, value); + EEPROM.end(); // stop the eeprom communication + Serial.print("read value from eeprom: "); + Serial.println(value); + abschaltzeit = value; + WasserSensorCheck(); DruckschalterInt(); @@ -152,11 +164,11 @@ void setup() { Serial.println("startup sequence complete!\n"); digitalWrite(LED_BUILTIN, HIGH); - WifiManager mang = WifiManager(); + mang.init(); } void loop() { - + mang.holdAlive(); } \ No newline at end of file