mirror of https://github.com/sqfmi/Watchy.git
moved NTP sync to main Watchy lib
parent
a454e65ba2
commit
eb89c09a31
|
@ -92,7 +92,7 @@ void Watchy::handleButtonPress(){
|
|||
showUpdateFW();
|
||||
break;
|
||||
case 6:
|
||||
syncNTP();
|
||||
showSyncNTP();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -174,7 +174,7 @@ void Watchy::handleButtonPress(){
|
|||
showUpdateFW();
|
||||
break;
|
||||
case 6:
|
||||
syncNTP();
|
||||
showSyncNTP();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -881,7 +881,7 @@ void Watchy::updateFWBegin(){
|
|||
showMenu(menuIndex, false);
|
||||
}
|
||||
|
||||
void Watchy::syncNTP(){
|
||||
void Watchy::showSyncNTP(){
|
||||
display.setFullWindow();
|
||||
display.fillScreen(GxEPD_BLACK);
|
||||
display.setFont(&FreeMonoBold9pt7b);
|
||||
|
@ -890,7 +890,7 @@ void Watchy::syncNTP(){
|
|||
display.println("Syncing NTP... ");
|
||||
display.display(false); //full refresh
|
||||
if(connectWiFi()){
|
||||
if(RTC.syncNtpTime()){
|
||||
if(syncNTP()){
|
||||
display.println("NTP Sync Success");
|
||||
}else{
|
||||
display.println("NTP Sync Failed");
|
||||
|
@ -903,6 +903,37 @@ void Watchy::syncNTP(){
|
|||
showMenu(menuIndex, false);
|
||||
}
|
||||
|
||||
bool Watchy::syncNTP(){ //NTP sync - call after connecting to WiFi and remember to turn it back off
|
||||
configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER);
|
||||
struct tm timeinfo;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
return false; //NTP sync failed
|
||||
}
|
||||
/****************************************************
|
||||
struct tm
|
||||
{
|
||||
int tm_sec; // Seconds [0,60].
|
||||
int tm_min; // Minutes [0,59].
|
||||
int tm_hour; // Hour [0,23].
|
||||
int tm_mday; // Day of month [1,31].
|
||||
int tm_mon; // Month of year [0,11].
|
||||
int tm_year; // Years since 1900.
|
||||
int tm_wday; // Day of week [0,6] (Sunday =0).
|
||||
int tm_yday; // Day of year [0,365].
|
||||
int tm_isdst; // Daylight Savings flag.
|
||||
}
|
||||
****************************************************/
|
||||
tmElements_t tm;
|
||||
tm.Year = CalendarYrToTm(timeinfo.tm_year + 1900);
|
||||
tm.Month = timeinfo.tm_mon + 1; //tm.Month 1 - 12
|
||||
tm.Day = timeinfo.tm_mday;
|
||||
tm.Hour = timeinfo.tm_hour;
|
||||
tm.Minute = timeinfo.tm_min;
|
||||
tm.Second = timeinfo.tm_sec;
|
||||
RTC.set(tm);
|
||||
return true;
|
||||
}
|
||||
|
||||
// time_t compileTime()
|
||||
// {
|
||||
// const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
||||
|
|
|
@ -39,8 +39,9 @@ class Watchy {
|
|||
void showBuzz();
|
||||
void showAccelerometer();
|
||||
void showUpdateFW();
|
||||
void showSyncNTP();
|
||||
bool syncNTP();
|
||||
void setTime();
|
||||
void syncNTP();
|
||||
void setupWifi();
|
||||
bool connectWiFi();
|
||||
weatherData getWeatherData();
|
||||
|
|
|
@ -115,37 +115,6 @@ void WatchyRTC::_PCFConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:
|
|||
clearAlarm();
|
||||
}
|
||||
|
||||
bool WatchyRTC::syncNtpTime(){ //NTP sync - call after connecting to WiFi and remember to turn it back off
|
||||
configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER);
|
||||
struct tm timeinfo;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
return false; //NTP sync failed
|
||||
}
|
||||
/****************************************************
|
||||
struct tm
|
||||
{
|
||||
int tm_sec; // Seconds [0,60].
|
||||
int tm_min; // Minutes [0,59].
|
||||
int tm_hour; // Hour [0,23].
|
||||
int tm_mday; // Day of month [1,31].
|
||||
int tm_mon; // Month of year [0,11].
|
||||
int tm_year; // Years since 1900.
|
||||
int tm_wday; // Day of week [0,6] (Sunday =0).
|
||||
int tm_yday; // Day of year [0,365].
|
||||
int tm_isdst; // Daylight Savings flag.
|
||||
}
|
||||
****************************************************/
|
||||
tmElements_t tm;
|
||||
tm.Year = CalendarYrToTm(timeinfo.tm_year + 1900);
|
||||
tm.Month = timeinfo.tm_mon + 1; //tm.Month 1 - 12
|
||||
tm.Day = timeinfo.tm_mday;
|
||||
tm.Hour = timeinfo.tm_hour;
|
||||
tm.Minute = timeinfo.tm_min;
|
||||
tm.Second = timeinfo.tm_sec;
|
||||
set(tm);
|
||||
return true;
|
||||
}
|
||||
|
||||
String WatchyRTC::_getValue(String data, char separator, int index)
|
||||
{
|
||||
int found = 0;
|
||||
|
|
|
@ -25,7 +25,6 @@ class WatchyRTC {
|
|||
void clearAlarm();
|
||||
void read(tmElements_t &tm);
|
||||
void set(tmElements_t tm);
|
||||
bool syncNtpTime();
|
||||
uint8_t temperature();
|
||||
private:
|
||||
void _DSConfig(String datetime);
|
||||
|
|
Loading…
Reference in New Issue