From d18255dd69d9b2fd31fda6c3b4fd801f160549e7 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 22 Oct 2020 08:18:46 +0200 Subject: [PATCH] Fixing data reset. Some eyecandy. --- WLAN_Thermometer.ino | 51 +++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/WLAN_Thermometer.ino b/WLAN_Thermometer.ino index 57007e9..265d9c5 100644 --- a/WLAN_Thermometer.ino +++ b/WLAN_Thermometer.ino @@ -1,6 +1,6 @@ // Use from 0 to 4. Higher number, more debugging messages and memory usage. //#define _WIFIMGR_LOGLEVEL_ 4 -//#define DEBUG 1 +#define DEBUG 1 #include #include @@ -58,11 +58,15 @@ void ConfigAPStarted(WiFiManager* wm); void setup() { + bool ap_reset_last_state; + pinMode(AP_DATA_RESET_PIN, INPUT_PULLDOWN); pinMode(ONBOARD_LED, OUTPUT); Serial.begin(115200); Serial.println(F("WLANThermometer (c)2020 H. Wirtz ")); + delay(200); + ap_reset_last_state = digitalRead(AP_DATA_RESET_PIN); lcd.init(); lcd.backlight(); @@ -73,6 +77,11 @@ void setup() lcd.setCursor(2, 1); lcd.print(F("(c)parasiTstudio")); + if (digitalRead(AP_DATA_RESET_PIN) == HIGH && ap_reset_last_state == HIGH) + { + ap_data_reset(); + } + WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP WiFiManager wm; @@ -113,10 +122,9 @@ void setup() DEBUG_MSG("mDNS started.\n"); } - lcd.clear(); - lcd.setCursor(0, 0); + lcd.setCursor(0,2); lcd.print(F("Mode WiFi client")); - lcd.setCursor(0, 1); + lcd.setCursor(0, 3); lcd.print(WiFi.localIP()); delay(500); @@ -324,19 +332,7 @@ void check_reset_ap_data(void) { if (digitalRead(AP_DATA_RESET_PIN) == HIGH && last_reset_ap_check == true) { - DEBUG_MSG("Reset AP data\n"); - - WiFiManager wm; - - lcd.clear(); - lcd.setCursor(0, 0); - lcd.print("Resetting AP Data"); - delay(2000); - wm.resetSettings(); - lcd.setCursor(0, 1); - lcd.print("Done."); - delay(1000); - ESP.restart(); + ap_data_reset(); } else if (digitalRead(AP_DATA_RESET_PIN) == HIGH) { @@ -545,16 +541,14 @@ void get_sensor_data(void) void ConfigAPWeb(void) { - lcd.clear(); lcd.setCursor(0, 2); - lcd.print(F("Mode Config-AP")); + lcd.print(F("Mode Config-AP ")); lcd.setCursor(0, 3); lcd.print(F("192.168.4.1")); } void ConfigAPStarted(WiFiManager * wm) { - lcd.clear(); DEBUG_MSG("Config-AP started\n"); } @@ -562,3 +556,20 @@ float round_float(float num, uint8_t dec_place) { return ((round(num * powf(10, dec_place))) / powf(10, dec_place)); } + +void ap_data_reset(void) +{ + DEBUG_MSG("Reset AP data\n"); + + WiFiManager wm; + + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Resetting AP Data"); + delay(2000); + wm.resetSettings(); + lcd.setCursor(0, 1); + lcd.print("Done."); + delay(1000); + ESP.restart(); +}