code refactor
This commit is contained in:
80
FW/NCM107-ESP32C3/src/clock.cpp
Normal file
80
FW/NCM107-ESP32C3/src/clock.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "clock.h"
|
||||
|
||||
int RTC_hours, RTC_minutes, RTC_seconds, RTC_day, RTC_month, RTC_year, RTC_day_of_week;
|
||||
bool RTC_present;
|
||||
|
||||
const char *ssid = "iot";
|
||||
const char *password = "Rijnstraat214";
|
||||
|
||||
|
||||
|
||||
void getRTCTime()
|
||||
{
|
||||
// RTC_seconds = timeClient.getSeconds();
|
||||
// RTC_minutes = timeClient.getMinutes();
|
||||
// RTC_hours = timeClient.getHours();
|
||||
// RTC_day_of_week = 1
|
||||
// RTC_day = timeClient.getDay();
|
||||
// RTC_month = timeClient.
|
||||
// RTC_year =
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
WiFi.begin(ssid, password);
|
||||
while ( WiFi.status() != WL_CONNECTED ) {
|
||||
delay ( 500 );
|
||||
Serial.print ( "." );
|
||||
}
|
||||
//setup NTP
|
||||
timeClient.begin();
|
||||
|
||||
|
||||
getRTCTime();
|
||||
byte prevSeconds=RTC_seconds;
|
||||
unsigned long RTC_ReadingStartTime=millis();
|
||||
RTC_present=true;
|
||||
while(prevSeconds==RTC_seconds)
|
||||
{
|
||||
getRTCTime();
|
||||
//Serial.println(RTC_seconds);
|
||||
if ((millis()-RTC_ReadingStartTime)>3000)
|
||||
{
|
||||
Serial.println(F("Warning! RTC DON'T RESPOND!"));
|
||||
RTC_present=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setTime(RTC_hours, RTC_minutes, RTC_seconds, RTC_day, RTC_month, RTC_year);
|
||||
}
|
||||
|
||||
void loopClock()
|
||||
{
|
||||
timeClient.update();
|
||||
|
||||
// if (((millis()%60000)==0)&&(RTC_present)) //synchronize with RTC every 10 seconds
|
||||
// {
|
||||
// getRTCTime();
|
||||
// setTime(RTC_hours, RTC_minutes, RTC_seconds, RTC_day, RTC_month, RTC_year);
|
||||
// Serial.println("sync:");
|
||||
// Serial.println(RTC_seconds);
|
||||
// }
|
||||
}
|
||||
|
||||
String getTimeNow()
|
||||
{
|
||||
if (value[hModeValueIndex]==24) return PreZero(tijd.getHour())+PreZero(tijd.getMinute())+PreZero(tijd.getSecond());
|
||||
else return PreZero(tijd.getHour())+PreZero(tijd.getMinute())+PreZero(tijd.getSecond());
|
||||
}
|
||||
|
||||
String updateDateString()
|
||||
{
|
||||
static unsigned long lastTimeDateUpdate=millis();
|
||||
static String DateString=PreZero(tijd.getDay())+PreZero(tijd.getMonth())+PreZero(tijd.getYear()%1000);
|
||||
if ((millis()-lastTimeDateUpdate)>1000)
|
||||
{
|
||||
lastTimeDateUpdate=millis();
|
||||
DateString=PreZero(tijd.getDay())+PreZero(tijd.getMonth())+PreZero(tijd.getYear()%1000);
|
||||
}
|
||||
return DateString;
|
||||
}
|
||||
Reference in New Issue
Block a user