watchy lib 1.3 fixes

This commit is contained in:
Klemek
2022-04-09 18:31:34 +02:00
parent 7d4a64b865
commit 084aa665ca
18 changed files with 222 additions and 79 deletions
+2 -4
View File
@@ -1,11 +1,9 @@
#include "Watchy_Below.h"
WatchyBelow::WatchyBelow()
{
} //constructor
void WatchyBelow::drawWatchFace()
{
readWorldTime();
display.fillScreen(GxEPD_BLACK);
display.drawBitmap(0, 0, background, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_WHITE);
+5 -4
View File
@@ -3,12 +3,13 @@
#include <Watchy.h>
#include "below.h"
#include "wta.h"
class WatchyBelow : public Watchy
class WatchyBelow : public WatchySynced
{
public:
WatchyBelow();
void drawWatchFace();
using WatchySynced::WatchySynced;
public:
void drawWatchFace();
};
#endif
+2 -1
View File
@@ -1,6 +1,7 @@
#include "watchy_below.h"
#include "settings.h"
WatchyBelow watchy;
WatchyBelow watchy(settings);
void setup()
{
+28
View File
@@ -0,0 +1,28 @@
#ifndef SETTINGS_H
#define SETTINGS_H
//Weather Settings
#define CITY_ID "5128581" //New York City https://openweathermap.org/current#cityid
#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :)
#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api
#define TEMP_UNIT "metric" //metric = Celsius , imperial = Fahrenheit
#define TEMP_LANG "en"
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * 1 //New York is UTC -5
#define DST_OFFSET_SEC 3600
watchySettings settings{
CITY_ID,
OPENWEATHERMAP_APIKEY,
OPENWEATHERMAP_URL,
TEMP_UNIT,
TEMP_LANG,
WEATHER_UPDATE_INTERVAL,
NTP_SERVER,
GMT_OFFSET_SEC,
DST_OFFSET_SEC
};
#endif
+42
View File
@@ -0,0 +1,42 @@
#include "wta.h"
RTC_DATA_ATTR int worldTimeIntervalCounter = 0;
void WatchySynced::readWorldTime()
{
if (worldTimeIntervalCounter == 0)
{
worldTimeIntervalCounter = WTA_UPDATE_SHORT_INTERVAL;
if (connectWiFi())
{
HTTPClient http;
http.setConnectTimeout(WTA_UPDATE_TIMEOUT);
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 = y2kYearToTm(datetime.substring(0, 4).toInt());
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;
RTC.set(tm);
RTC.read(currentTime);
worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL;
}
http.end();
WiFi.mode(WIFI_OFF);
btStop();
}
}
else
{
worldTimeIntervalCounter = worldTimeIntervalCounter < 0 ? 0 : worldTimeIntervalCounter - 1;
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef WTA_H
#define WTA_H
#include <Watchy.h>
#define WTA_URL "http://worldtimeapi.org/api/timezone/"
#define WTA_TIMEZONE "Europe/Paris"
#define WTA_UPDATE_SHORT_INTERVAL 30 //minutes
#define WTA_UPDATE_LONG_INTERVAL 300 //minutes
#define WTA_UPDATE_TIMEOUT 10000 //ms
class WatchySynced : public Watchy
{
using Watchy::Watchy;
public:
void readWorldTime();
};
#endif