mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-14 15:05:53 +08:00
Fix Internet Time on ESP32
This commit is contained in:
parent
6f6c1842ce
commit
4b01d89095
@ -114,7 +114,7 @@ bool TimeService::begin() {
|
|||||||
s2 = ESP3DSettings::readString(ESP_TIME_SERVER2);
|
s2 = ESP3DSettings::readString(ESP_TIME_SERVER2);
|
||||||
s3 = ESP3DSettings::readString(ESP_TIME_SERVER3);
|
s3 = ESP3DSettings::readString(ESP_TIME_SERVER3);
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
configTzTime(_time_zone.c_str(), s1.c_str(), s2.c_str(), s3.c_str());
|
configTzTime(_time_zone_config.c_str(), s1.c_str(), s2.c_str(), s3.c_str());
|
||||||
#endif // ARDUINO_ARCH_ESP32
|
#endif // ARDUINO_ARCH_ESP32
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
configTime(t1.c_str(), s1.c_str(), s2.c_str(), s3.c_str());
|
configTime(t1.c_str(), s1.c_str(), s2.c_str(), s3.c_str());
|
||||||
@ -181,16 +181,26 @@ bool TimeService::updateTimeZone(bool fromsettings) {
|
|||||||
setTZ(stmp.c_str());
|
setTZ(stmp.c_str());
|
||||||
#endif // ARDUINO_ARCH_ESP8266
|
#endif // ARDUINO_ARCH_ESP8266
|
||||||
|
|
||||||
|
_time_zone_config = "<";
|
||||||
|
_time_zone_config += _time_zone[0];
|
||||||
|
_time_zone_config += _time_zone[1];
|
||||||
|
_time_zone_config += _time_zone[2];
|
||||||
|
_time_zone_config += _time_zone[4];
|
||||||
|
_time_zone_config += _time_zone[5];
|
||||||
|
_time_zone_config += ">";
|
||||||
|
_time_zone_config += _time_zone[0]=='+' ? "-" : "+";
|
||||||
|
_time_zone_config += &_time_zone[1];
|
||||||
|
esp3d_log_d("Time zone is %s", _time_zone_config.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* TimeService::getCurrentTime() {
|
const char* TimeService::getCurrentTime() {
|
||||||
struct tm tmstruct;
|
struct tm tmstruct;
|
||||||
|
static char buf[20];
|
||||||
time_t now;
|
time_t now;
|
||||||
// get current time
|
// get current time
|
||||||
time(&now);
|
time(&now);
|
||||||
localtime_r(&now, &tmstruct);
|
localtime_r(&now, &tmstruct);
|
||||||
static char buf[20];
|
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tmstruct);
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tmstruct);
|
||||||
esp3d_log("Time string is %s", buf);
|
esp3d_log("Time string is %s", buf);
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -45,6 +45,7 @@ class TimeService {
|
|||||||
bool _started;
|
bool _started;
|
||||||
bool _isInternetTime;
|
bool _isInternetTime;
|
||||||
String _time_zone;
|
String _time_zone;
|
||||||
|
String _time_zone_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TimeService timeService;
|
extern TimeService timeService;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user