2024-12-2201 NPT auf RTC

This commit is contained in:
hans-jurgen 2024-12-22 03:21:09 +01:00
parent 41a8516d10
commit f73cdab130
2 changed files with 48 additions and 28 deletions

BIN
de.pool.ntp.tiff Normal file

Binary file not shown.

View File

@ -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);
@ -470,6 +464,22 @@ void loop() {
}
}
/* 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){
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();
}