diff --git a/WLAN_Thermometer.ino b/WLAN_Thermometer.ino index 03405e8..d8e0975 100644 --- a/WLAN_Thermometer.ino +++ b/WLAN_Thermometer.ino @@ -23,7 +23,8 @@ #define KRATE_TEMP 5000 #define KRATE_TIME 500 #define MEDIAN_SAMPLES 60 - +#define ONBOARD_LED 2 +#define NTP_TIMEOUT 15000 void check_mode(void); LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_COL, LCD_ROW); @@ -31,10 +32,12 @@ looper sched; RunningMedian samples = RunningMedian(MEDIAN_SAMPLES); float temp_min = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0; float temp_max = temp_min; +bool led_state; void setup() { pinMode(AP_DATA_RESET_PIN, INPUT_PULLUP); + pinMode(ONBOARD_LED, OUTPUT); Serial.begin(115200); Serial.println(F("WLANThermometer (c)2020 H. Wirtz ")); @@ -71,18 +74,18 @@ void setup() // then goes into a blocking loop awaiting configuration and will return success result lcd.clear(); - lcd.setCursor(0, 3); + lcd.setCursor(0, 0); lcd.print(F("Mode Config-AP")); - lcd.setCursor(0, 4); + lcd.setCursor(0, 1); lcd.print(F("192.168.4.1")); if (!wm.autoConnect(AP_SSID_CONFIG_NAME, AP_CONFIG_PASSWORD)) { DEBUG_MSG("Failed to connect\n"); - lcd.setCursor(0, 4); + lcd.setCursor(0, 2); lcd.print(F("Failed ")); delay(1000); - lcd.setCursor(8, 4); + lcd.setCursor(8, 2); lcd.print(F("- restart")); delay(1000); ESP.restart(); @@ -110,10 +113,14 @@ void setup() delay(500); } + lcd.setCursor(0, 3); + lcd.print("Getting time..."); DateTime.setTimeZone(2); - DateTime.begin(); - if (!DateTime.isTimeValid()) { + DateTime.begin(NTP_TIMEOUT); + while (!DateTime.isTimeValid()) + { Serial.println("Failed to get time from server."); + DateTime.forceUpdate(); } sched.addJob(show_temperature, KRATE_TEMP); @@ -140,6 +147,9 @@ void show_time(void) sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours(), p.getMinutes(), p.getSeconds()); lcd.setCursor(0, 0); lcd.print(dt); + + digitalWrite(ONBOARD_LED, led_state); + led_state = !led_state; } void show_temperature(void)