Adding timezone settings

This commit is contained in:
Sébastien Vallée 2018-03-26 23:30:05 +02:00
parent 771feec8c2
commit 25e1fd5ab3
2 changed files with 14 additions and 6 deletions

View File

@ -3,6 +3,8 @@
#include "config.h" #include "config.h"
//################# LIBRARIES ########################## //################# LIBRARIES ##########################
//#include <NTPClient.h>
#include <Timezone.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
@ -13,6 +15,7 @@
#include <Max72xxPanel.h> #include <Max72xxPanel.h>
#include <time.h> #include <time.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
//#include <WiFiUdp.h>
#include "OTAsetup.h" #include "OTAsetup.h"
#include "d_helper.h" #include "d_helper.h"
#include "FS.h" #include "FS.h"
@ -28,14 +31,12 @@
// CLK -> D5 (Same Pin for WEMOS) // CLK -> D5 (Same Pin for WEMOS)
//################ PROGRAM SETTINGS #################### //################ PROGRAM SETTINGS ####################
String version = "0.1b"; String version = "0.2b";
int PORT = 80; int PORT = 80;
int wait = 50; int wait = 50;
int spacer = 1; int spacer = 1;
int width = 5 + spacer; int width = 5 + spacer;
String SITE_WIDTH = "1000"; String SITE_WIDTH = "1000";
int timezone = 1;
int dstOffset = 1;
const char* ntpServer = "fr.pool.ntp.org"; const char* ntpServer = "fr.pool.ntp.org";
int brightness = 16; int brightness = 16;
int pinCS = D4; int pinCS = D4;
@ -52,6 +53,10 @@ Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVe
#ifdef DEBUG_TELNET #ifdef DEBUG_TELNET
WiFiServer telnetServer(23); WiFiServer telnetServer(23);
WiFiClient telnetClient; WiFiClient telnetClient;
TimeChangeRule CET = {"CET", Last, Sun, Oct, 2, 60}; //UTC + 1 hour
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //UTC + 2 hours
Timezone CentralEuropean(CET, CEST);
void handleTelnet(void) { void handleTelnet(void) {
if (telnetServer.hasClient()) { if (telnetServer.hasClient()) {
@ -111,7 +116,7 @@ void setup() {
DEBUG_PRINTLN(WiFi.localIP()); DEBUG_PRINTLN(WiFi.localIP());
// First sync with NTP // First sync with NTP
configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP configTime(0, 0, ntpServer); // First sync of time with (S)NTP in UTC
// Initialise Telnet Server for debugging purposes // Initialise Telnet Server for debugging purposes
#ifdef DEBUG_TELNET #ifdef DEBUG_TELNET
@ -147,6 +152,7 @@ void loop() {
// Getting and parsing the time // Getting and parsing the time
time_t now = time(nullptr); time_t now = time(nullptr);
now = CentralEuropean.toLocal(now);
String time = String(ctime(&now)); String time = String(ctime(&now));
time.trim(); time.trim();
time.substring(11,19).toCharArray(time_value, 10); time.substring(11,19).toCharArray(time_value, 10);
@ -171,6 +177,8 @@ void loop() {
matrix.setIntensity(brightness); matrix.setIntensity(brightness);
brightness = 16; brightness = 16;
} }
// Managing OTA thing
ArduinoOTA.handle(); ArduinoOTA.handle();
#ifdef DEBUG_TELNET #ifdef DEBUG_TELNET

View File

@ -81,12 +81,12 @@
<body> <body>
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse fixed-top"> <nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse fixed-top">
<a class="navbar-brand" href="#">LibreMetric v0.1b</a> <a class="navbar-brand" href="#">LibreMetric v0.2b</a>
<a href='javascript:location.reload(true);' class='btn-success btn-lg md-only'>Reload</a> <a href='javascript:location.reload(true);' class='btn-success btn-lg md-only'>Reload</a>
</nav> </nav>
<div id="wrapper" class="container"> <div id="wrapper" class="container">
<br /><br /><br /><br /><br /> <br /><br /><br /><br /><br />
<h1>LibreMetric v0.1b</h1> <h1>LibreMetric v0.2b</h1>
<form id="form-work" class="" name="form-work" action="http://ipaddress" method="post"> <form id="form-work" class="" name="form-work" action="http://ipaddress" method="post">
<fieldset> <fieldset>