correct time set and get

This commit is contained in:
lukas 2020-06-20 15:10:35 +02:00
parent 387910d37f
commit a0d42847c9
3 changed files with 20 additions and 19 deletions

View File

@ -45,14 +45,11 @@ void WifiManager::handleRoot() {
" <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"
" <div>Aktuelle Zeit: "+ String(value / 60) +" 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);
@ -75,22 +72,29 @@ void WifiManager::handleGet() {
Serial.println(server.arg("time"));
if (server.arg("time") != "") {
int time = atoi(server.arg("time").c_str()); //Gets the value of the query parameter
// should be hours
int time = (int) (server.arg("time").toFloat() * 3600.0 + 0.5);
//manager.setSSID(message);
if (time == 0) {
time = 7200;
}
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();
}
int WifiManager::getWaitTime() {
int value = 0;
EEPROM.begin(4096); // init the eeprom
EEPROM.get(0, value);
EEPROM.end(); // stop the eeprom communication
return value;
}

View File

@ -15,6 +15,8 @@ public:
void init();
void holdAlive();
int getWaitTime();
private:
ESP8266WebServer server;

View File

@ -15,7 +15,6 @@ static const uint8_t DruckSensorPin = 12;
static const uint8_t SchuetzPin = 13;
/** time config */
static int abschaltzeit = 7200; //sek
static const int maxpumpdauer = 600; //sek
// ticker fuer kein-wasser abschaltung
@ -77,7 +76,7 @@ ICACHE_RAM_ATTR void DruckschalterInt() {
}
}
int i = abschaltzeit; //todo better
int i = mang.getWaitTime(); //todo better
void WasserSensorCheck() {
if (digitalRead(WasserSensorPin) == LOW) {
Serial.println("Wasser Sensor AUS");
@ -91,7 +90,7 @@ void WasserSensorCheck() {
status.detach();
i = abschaltzeit;
i = mang.getWaitTime();
status.attach(5, []() {
i -= 5;
Serial.print("noch ");
@ -144,13 +143,9 @@ void setup() {
//allow = digitalRead(WasserSensorPin);
allow = true;
int value = 0;
EEPROM.begin(4096); // init the eeprom
EEPROM.get(0, value);
EEPROM.end(); // stop the eeprom communication
int value = mang.getWaitTime();
Serial.print("read value from eeprom: ");
Serial.println(value);
abschaltzeit = value;
WasserSensorCheck();
DruckschalterInt();