-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change of wait for reconfig is now disable * Add NTP client (not configurable)
- Loading branch information
1 parent
65cd2c4
commit ba58323
Showing
9 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <Arduino.h> | ||
|
||
void ntp_setup(); | ||
String getFormattedTime(); | ||
|
||
/** time is not set due to NTP failed or NTP disabled */ | ||
const String TIME_NOT_READY = "0000/00/00 00:00:00"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <Arduino.h> | ||
|
||
#ifdef esp32 | ||
#include <esp_sntp.h> | ||
|
||
#endif | ||
#ifdef ESP8266 | ||
#include <time.h> | ||
#endif | ||
|
||
#include "log.h" | ||
#include "network/time_client.h" | ||
|
||
void ntp_setup() { | ||
|
||
cfglog("Communicating NTP server."); | ||
|
||
configTzTime("JST-9", "10.1.0.10"); | ||
|
||
cfglog("Communicating NTP server done."); | ||
} | ||
|
||
#ifdef esp32 | ||
struct tm timeinfo; | ||
|
||
String getFormattedTime() { | ||
if (!getLocalTime(&timeinfo, 1)) { | ||
return TIME_NOT_READY; | ||
} | ||
|
||
char buf[64]; | ||
strftime(buf, 64, "%Y/%m/%d %H:%M:%S", &timeinfo); | ||
// String s = fmt.Sprintf(&timeinfo, "%A, %B %d %Y %H:%M:%S"); | ||
return String(buf); | ||
} | ||
#endif | ||
#ifdef ESP8266 | ||
time_t t; | ||
struct tm *tm; | ||
|
||
String getFormattedTime() { | ||
|
||
char buf[50]; | ||
|
||
t = time(NULL); | ||
tm = localtime(&t); | ||
|
||
sprintf(buf, " %04d/%02d/%02d %02d:%02d:%02d", | ||
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, | ||
tm->tm_hour, tm->tm_min, tm->tm_sec); | ||
|
||
return String(buf); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters