webserver where to set the pump timeout

This commit is contained in:
lukas 2020-06-20 12:12:27 +02:00
parent 1ba2aad7e7
commit 387910d37f
3 changed files with 110 additions and 8 deletions

View File

@ -2,17 +2,95 @@
// Created by lukas on 10.04.20. // Created by lukas on 10.04.20.
// //
#include <EEPROM.h>
#include "WifiManager.h" #include "WifiManager.h"
void WifiManager::init() { void WifiManager::init() {
Serial.print("Setting up Access Point"); Serial.print("Setting up Access Point");
// start softap
boolean result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2"); boolean result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
if(result == true) if (result == true) {
{
Serial.println("Wifi Ready"); Serial.println("Wifi Ready");
} Serial.println( WiFi.softAPIP());
else
{
server.on("/", HTTP_GET, [this](){
handleRoot();
});
server.on("/get", [this](){
handleGet();
});
server.onNotFound([this](){
handleNotFound();
});
server.begin();
} else {
Serial.println("Wifi Setup failed!"); 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 = "<!DOCTYPE HTML><html><head>\n"
" <title>Wastinfoboard-ConfigurationPage</title>\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
" </head><body>\n"
" <div>Aktuelle Zeit: "+ String(value) +" Minuten</div>\n"
" <form action=\"/get\">\n"
" Zeit setzen: <input placeholder=\"Abschaltzeit in h\" type=\"text\" name=\"time\">\n"
" <input type=\"submit\" value=\"Submit\">\n"
" </form><br>\n"
" <a href='/get?reset=reset' >\n"
" <button>Reset ESP ...</button>"
" </a>\n"
"</body></html>";
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 = "<!DOCTYPE HTML><html><head>\n"
" <title>Wastinfoboard-ConfigurationPage</title>\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
" <meta http-equiv=\"refresh\" content=\"0; URL=/\">\n"
" </head><body>\n"
"</body></html>";
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();
}

View File

@ -6,9 +6,21 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
class WifiManager { class WifiManager {
public: public:
WifiManager();
void init(); void init();
void holdAlive();
private:
ESP8266WebServer server;
void handleRoot();
void handleNotFound();
void handleGet();
}; };

View File

@ -1,5 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <Ticker.h> #include <Ticker.h>
#include <EEPROM.h>
#include "WifiManager.h" #include "WifiManager.h"
@ -14,7 +15,7 @@ static const uint8_t DruckSensorPin = 12;
static const uint8_t SchuetzPin = 13; static const uint8_t SchuetzPin = 13;
/** time config */ /** time config */
static const int abschaltzeit = 7200; //sek static int abschaltzeit = 7200; //sek
static const int maxpumpdauer = 600; //sek static const int maxpumpdauer = 600; //sek
// ticker fuer kein-wasser abschaltung // ticker fuer kein-wasser abschaltung
@ -23,6 +24,8 @@ Ticker status;
//pumpendauer maximum ticker //pumpendauer maximum ticker
Ticker pumpendauer; Ticker pumpendauer;
WifiManager mang;
int turnontime = -1; int turnontime = -1;
void pumpeSchalten(bool on) { void pumpeSchalten(bool on) {
@ -140,6 +143,15 @@ void setup() {
delay(1000); delay(1000);
//allow = digitalRead(WasserSensorPin); //allow = digitalRead(WasserSensorPin);
allow = true; 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(); WasserSensorCheck();
DruckschalterInt(); DruckschalterInt();
@ -152,11 +164,11 @@ void setup() {
Serial.println("startup sequence complete!\n"); Serial.println("startup sequence complete!\n");
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
WifiManager mang = WifiManager();
mang.init(); mang.init();
} }
void loop() { void loop() {
mang.holdAlive();
} }