From 41a8516d10527f2839b618007cb2fe312dc98a60 Mon Sep 17 00:00:00 2001 From: hans-jurgen Date: Sun, 22 Dec 2024 01:17:47 +0100 Subject: [PATCH] 2024-12-2200 RCT --- platformio.ini | 1 + src/main.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/platformio.ini b/platformio.ini index ab4cd22..be11233 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,6 +17,7 @@ lib_deps = ;adafruit/Adafruit BME280 Library @ 2.2.4 adafruit/Adafruit BMP280 Library @ 2.6.8 adafruit/Adafruit Unified Sensor @ 1.1.14 + adafruit/RTClib @ 2.1.4 SD FS SPI diff --git a/src/main.cpp b/src/main.cpp index 4b4faf8..65800ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,6 +53,9 @@ SPIClass mySpi = SPIClass(VSPI); #include #include #include +#include "RTClib.h" + +RTC_DS3231 rtc; Preferences preferences; @@ -283,6 +286,24 @@ void setup() { ESP.restart(); } } + + 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); Serial.println(""); @@ -343,6 +364,8 @@ void setup() { 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);;