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" " <title>Wastinfoboard-ConfigurationPage</title>\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
" </head><body>\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" " <form action=\"/get\">\n"
" Zeit setzen: <input placeholder=\"Abschaltzeit in h\" type=\"text\" name=\"time\">\n" " Zeit setzen: <input placeholder=\"Abschaltzeit in h\" type=\"text\" name=\"time\">\n"
" <input type=\"submit\" value=\"Submit\">\n" " <input type=\"submit\" value=\"Submit\">\n"
" </form><br>\n" " </form><br>\n"
" <a href='/get?reset=reset' >\n"
" <button>Reset ESP ...</button>"
" </a>\n"
"</body></html>"; "</body></html>";
server.send(200, "text/html", index_html); server.send(200, "text/html", index_html);
@ -75,22 +72,29 @@ void WifiManager::handleGet() {
Serial.println(server.arg("time")); Serial.println(server.arg("time"));
if (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); //manager.setSSID(message);
if (time == 0) {
time = 7200;
}
EEPROM.begin(4096); // init the eeprom EEPROM.begin(4096); // init the eeprom
EEPROM.put(0, time); EEPROM.put(0, time);
EEPROM.commit(); // write the changes to the eeprom EEPROM.commit(); // write the changes to the eeprom
EEPROM.end(); // stop the eeprom communication 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 server.send(200, "text/html", s); //Send web page
} }
void WifiManager::holdAlive() { void WifiManager::holdAlive() {
server.handleClient(); 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 init();
void holdAlive(); void holdAlive();
int getWaitTime();
private: private:
ESP8266WebServer server; ESP8266WebServer server;

View File

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