synced time when on wifi
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
*.bmp
|
*.bmp
|
||||||
|
watchfaces/libraries
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ void WatchyTetris::drawWatchFace()
|
|||||||
// Background
|
// Background
|
||||||
display.drawBitmap(0, 0, tetrisbg, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_BLACK);
|
display.drawBitmap(0, 0, tetrisbg, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_BLACK);
|
||||||
|
|
||||||
|
readWorldTime();
|
||||||
|
|
||||||
//Hour
|
//Hour
|
||||||
display.drawBitmap(25, 20, tetris_nums_0[currentTime.Hour / 10], 40, 60, GxEPD_BLACK); //first digit
|
display.drawBitmap(25, 20, tetris_nums_0[currentTime.Hour / 10], 40, 60, GxEPD_BLACK); //first digit
|
||||||
display.drawBitmap(75, 20, tetris_nums_1[currentTime.Hour % 10], 40, 60, GxEPD_BLACK); //second digit
|
display.drawBitmap(75, 20, tetris_nums_1[currentTime.Hour % 10], 40, 60, GxEPD_BLACK); //second digit
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
#include <Watchy.h>
|
#include <Watchy.h>
|
||||||
#include "tetris.h"
|
#include "tetris.h"
|
||||||
|
#include "wta.h"
|
||||||
|
|
||||||
class WatchyTetris : public Watchy
|
#undef WTA_TIMEZONE
|
||||||
|
#define WTA_TIMEZONE "Europe/Paris"
|
||||||
|
|
||||||
|
class WatchyTetris : public WatchySynced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WatchyTetris();
|
WatchyTetris();
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#include "wta.h"
|
||||||
|
|
||||||
|
RTC_DATA_ATTR int worldTimeIntervalCounter = WTA_UPDATE_INTERVAL;
|
||||||
|
|
||||||
|
void WatchySynced::readWorldTime()
|
||||||
|
{
|
||||||
|
if (worldTimeIntervalCounter >= WTA_UPDATE_INTERVAL)
|
||||||
|
{
|
||||||
|
if (connectWiFi())
|
||||||
|
{
|
||||||
|
HTTPClient http;
|
||||||
|
http.setConnectTimeout(10000);
|
||||||
|
String queryURL = String(WTA_URL) + String(WTA_TIMEZONE);
|
||||||
|
http.begin(queryURL.c_str());
|
||||||
|
int httpResponseCode = http.GET();
|
||||||
|
if (httpResponseCode == 200)
|
||||||
|
{
|
||||||
|
String payload = http.getString();
|
||||||
|
JSONVar responseObject = JSON.parse(payload);
|
||||||
|
tmElements_t tm;
|
||||||
|
String datetime = String((const char *)responseObject["datetime"]);
|
||||||
|
tm.Year = datetime.substring(0, 4).toInt() - YEAR_OFFSET;
|
||||||
|
tm.Month = datetime.substring(5, 7).toInt();
|
||||||
|
tm.Day = datetime.substring(8, 10).toInt();
|
||||||
|
tm.Hour = datetime.substring(11, 13).toInt();
|
||||||
|
tm.Minute = datetime.substring(14, 16).toInt();
|
||||||
|
tm.Second = 0;
|
||||||
|
time_t t = makeTime(tm);
|
||||||
|
RTC.set(t);
|
||||||
|
RTC.read(currentTime);
|
||||||
|
}
|
||||||
|
http.end();
|
||||||
|
WiFi.mode(WIFI_OFF);
|
||||||
|
btStop();
|
||||||
|
}
|
||||||
|
worldTimeIntervalCounter = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
worldTimeIntervalCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef WTA_H
|
||||||
|
#define WTA_H
|
||||||
|
|
||||||
|
#include <Watchy.h>
|
||||||
|
|
||||||
|
#define WTA_URL "http://worldtimeapi.org/api/timezone/"
|
||||||
|
#define WTA_TIMEZONE "Etc/UTC"
|
||||||
|
#define WTA_UPDATE_INTERVAL 60 //minutes
|
||||||
|
|
||||||
|
class WatchySynced : public Watchy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void readWorldTime();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user