mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add NTPSERVERS to user_config_override.h
This commit is contained in:
parent
6cc646a93f
commit
e459583df1
@ -53,6 +53,9 @@
|
||||
/***************************************************
|
||||
* Timezone Settings
|
||||
**************************************************/
|
||||
#define NTPSERVER1 "pool.ntp.org"
|
||||
#define NTPSERVER2 "time.nist.gov"
|
||||
#define NTPSERVER3 "time.google.com"
|
||||
#define MYTZ \
|
||||
"CET-1CEST,M3.5.0,M10.5.0/3" // A full list with possible timezones can be found here
|
||||
// https://gist.github.com/alwynallan/24d96091655391107939
|
||||
|
@ -15,16 +15,40 @@
|
||||
#include "hasp/hasp.h"
|
||||
#include "sys/svc/hasp_mdns.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include "Preferences.h"
|
||||
#endif
|
||||
|
||||
#ifndef MYTZ
|
||||
#define MYTZ "EST5EDT,M3.2.0/2,M11.1.0"
|
||||
#endif
|
||||
|
||||
#ifndef NTPSERVER1
|
||||
#define NTPSERVER1 "pool.ntp.org"
|
||||
#endif
|
||||
|
||||
#ifndef NTPSERVER2
|
||||
#define NTPSERVER2 "time.nist.gov"
|
||||
#endif
|
||||
|
||||
#ifndef NTPSERVER3
|
||||
#define NTPSERVER3 "time.google.com"
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// These strings must be constant and kept in memory
|
||||
String mytz((char*)0);
|
||||
String ntp1((char*)0);
|
||||
String ntp2((char*)0);
|
||||
String ntp3((char*)0);
|
||||
#endif
|
||||
|
||||
#if HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0
|
||||
void networkStart(void)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
LOG_WARNING(TAG_MAIN, F("TIMEZONE: %s"), MYTZ);
|
||||
configTzTime(MYTZ, "pool.ntp.org", "time.nist.gov", NULL); // literal string
|
||||
configTzTime(MYTZ, NTPSERVER1, NTPSERVER2, NTPSERVER3); // literal string
|
||||
#endif
|
||||
|
||||
// haspProgressVal(255); // hide
|
||||
@ -36,6 +60,7 @@ void networkStart(void)
|
||||
httpStart();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS > 0
|
||||
mdnsStart();
|
||||
#endif // HASP_USE_MDNS
|
||||
@ -50,6 +75,7 @@ void networkStop(void)
|
||||
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
||||
httpStop();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS > 0
|
||||
mdnsStop();
|
||||
#endif
|
||||
@ -57,6 +83,22 @@ void networkStop(void)
|
||||
|
||||
void networkSetup()
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
Preferences preferences;
|
||||
preferences.begin("time", false);
|
||||
|
||||
mytz = preferences.getString("tz", MYTZ);
|
||||
ntp1 = preferences.getString("ntp1", NTPSERVER1);
|
||||
ntp2 = preferences.getString("ntp2", NTPSERVER2);
|
||||
ntp3 = preferences.getString("ntp3", NTPSERVER3);
|
||||
|
||||
LOG_WARNING(TAG_MAIN, F("TIMEZONE: %s"), mytz.c_str());
|
||||
LOG_WARNING(TAG_MAIN, F("NTPSERVER: %s %s %s"), ntp1.c_str(), ntp2.c_str(), ntp3.c_str());
|
||||
|
||||
configTzTime(mytz.c_str(), ntp1.c_str(), ntp2.c_str(), ntp3.c_str());
|
||||
preferences.end();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
ethernetSetup();
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user