diff --git a/de.pool.ntp.tiff b/de.pool.ntp.tiff new file mode 100644 index 0000000..629b211 Binary files /dev/null and b/de.pool.ntp.tiff differ diff --git a/src/main.cpp b/src/main.cpp index 65800ba..be6b6b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ void drawMenue(int32_t xs, int32_t sy); void Menue(); void zeige_IP(int x, int y); void NoTouchScreen(TouchPoint touch_1); +void ReadRTC(); void listDir(fs::FS &fs, const char * dirname, uint8_t levels) { @@ -287,22 +288,6 @@ void setup() { } } - if (!rtc.begin()) { - tft.fillScreen(TFT_RED); - Serial.println("Couldn't find RTC"); - tft.setTextColor(TFT_BLACK, TFT_WHITE); - tft.drawCentreString(" Couldn't find RTC ", 160, 110, 2); - //Serial.flush(); - while(1); - } - - //Serial.println("Setting the time..."); - // When time needs to be set on a new device, or after a power loss, the - // following line sets the RTC to the date & time this sketch was compiled - //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); - // This line sets the RTC with an explicit date & time, for example to set - // January 21, 2014 at 3am you would call: - // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); // Print local IP address and start web server tft.fillScreen(TFT_BLACK); @@ -350,7 +335,7 @@ void setup() { // See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region setenv("TZ", TZ_INFO, 1); - if (getNTPtime(10)) { // wait up to 10sec to sync + /* if (getNTPtime(10)) { // wait up to 10sec to sync } else { Serial.println("Time not set"); tft.fillScreen(TFT_RED); @@ -362,10 +347,8 @@ void setup() { } WiFi.disconnect(); ESP.restart(); - } + } */ lastNTPtime = time(&now); - getNTPtime(10); - //rtc.adjust(DateTime(timeinfo.tm_year, timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec)); preferences.begin("Interval", false); interval = preferences.getUInt("Interval", SAVE_INTERVAL);; @@ -382,6 +365,17 @@ void setup() { x = 320 /2; y += 32; tft.setTextColor(TFT_BLUE, TFT_BLACK); + if (!rtc.begin()) { + tft.fillScreen(TFT_RED); + Serial.println("Couldn't find RTC"); + tft.setTextColor(TFT_BLACK, TFT_WHITE); + tft.drawCentreString(" Couldn't find RTC ", 160, 110, 2); + //Serial.flush(); + while(1); + } + if (getNTPtime(10) == true){ + rtc.adjust(DateTime(1900 + timeinfo.tm_year, 1 + timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec)); + }; } void printTouchToDisplay(TouchPoint p) { @@ -447,7 +441,7 @@ void loop() { } } - getNTPtime(10); + ReadRTC(); tft.setTextColor(TFT_WHITE, TFT_BLACK); zeigeZeit(timeinfo, 215, 0); zeige_IP(0, 0); @@ -469,6 +463,22 @@ void loop() { Serial.print("SAVE ----> "); Serial.println(ausgabe); } } + + + /* Serial.print(now.year(), DEC); + Serial.print('/'); + Serial.print(now.month(), DEC); + Serial.print('/'); + Serial.print(now.day(), DEC); + Serial.print(" ("); + //Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); + Serial.print(") "); + Serial.print(now.hour(), DEC); + Serial.print(':'); + Serial.print(now.minute(), DEC); + Serial.print(':'); + Serial.print(now.second(), DEC); + Serial.println(); */ delay(300); } @@ -642,10 +652,20 @@ void Menue(){ tft.println(WiFi.localIP()); tft.setTextSize(1); } - void NoTouchScreen(TouchPoint touch_1){ - do{ - delay(50); - //Serial.printf(" Gefunden bei --------->: %i : %i : %i \n", touch_1.y, touch_1.x, touch_1.zRaw); - touch_1 = touchscreen.getTouch(); - } while(touch_1.zRaw > 0); - } \ No newline at end of file +void NoTouchScreen(TouchPoint touch_1){ + do{ + delay(50); + //Serial.printf(" Gefunden bei --------->: %i : %i : %i \n", touch_1.y, touch_1.x, touch_1.zRaw); + touch_1 = touchscreen.getTouch(); + } while(touch_1.zRaw > 0); +} + +void ReadRTC(){ + DateTime now = rtc.now(); + timeinfo.tm_sec = now.second(); + timeinfo.tm_min = now.minute(); + timeinfo.tm_hour = now.hour(); + timeinfo.tm_mday = now.day(); + timeinfo.tm_mon = now.month(); + timeinfo.tm_year = now.year(); +} \ No newline at end of file