better time zone handling
This commit is contained in:
parent
dfdac04820
commit
334fecb472
|
@ -59,7 +59,7 @@ const uint8_t *digits[10] = { image_data_icon_digit_0, image_data_icon_digit_1,
|
|||
char *ssid = "Freifunk";
|
||||
char *pass = "";
|
||||
char *calendarURL = "https://mail.unitas-network.de/mergedCalendars.json";
|
||||
int timeZone = 2;
|
||||
char *timeZone = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
|
||||
//Set to 1 to flip the screen 180 degrees
|
||||
#define ROTATION 3
|
||||
|
@ -98,9 +98,8 @@ void setup() {
|
|||
display.load1b();
|
||||
|
||||
//Update data
|
||||
// if (timeDigits[0]+timeDigits[1]+timeDigits[2]+timeDigits[3] == 0) {
|
||||
if ((timeDigits[1] == 5) && (timeDigits[0] == 9)) {
|
||||
network.begin(); // every midnight set the time from internet
|
||||
network.begin(); // every hour set the time from internet
|
||||
network.off();
|
||||
networking = true;
|
||||
}
|
||||
|
|
12
Network.cpp
12
Network.cpp
|
@ -34,15 +34,13 @@ void Network::begin()
|
|||
// Gets time from ntp server
|
||||
void Network::getTime(int *timeDigits)
|
||||
{
|
||||
// Get seconds since 1.1.1970.
|
||||
time_t nowSecs = time(nullptr);
|
||||
|
||||
// Used to store time
|
||||
struct tm timeinfo;
|
||||
gmtime_r(&nowSecs, &timeinfo);
|
||||
|
||||
// Setting time string timezone (Better defined modulo, in case timezone makes hours to go below 0)
|
||||
timeinfo.tm_hour = ((timeinfo.tm_hour + timeZone) % 24 + 24) %24;
|
||||
setenv("TZ", timeZone, 1);
|
||||
tzset();
|
||||
|
||||
time_t nowSecs = time(nullptr);
|
||||
localtime_r(&nowSecs, &timeinfo);
|
||||
|
||||
// fill in the digits
|
||||
timeDigits[0] = timeinfo.tm_min % 10; //minutes (units)
|
||||
|
|
Loading…
Reference in New Issue