mirror of
				https://github.com/luc-github/ESP3D.git
				synced 2025-10-24 11:50:52 -07:00 
			
		
		
		
	Fix Internet Time on ESP32
This commit is contained in:
		| @@ -114,7 +114,7 @@ bool TimeService::begin() { | ||||
|   s2 = ESP3DSettings::readString(ESP_TIME_SERVER2); | ||||
|   s3 = ESP3DSettings::readString(ESP_TIME_SERVER3); | ||||
| #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 | ||||
| #if defined(ARDUINO_ARCH_ESP8266) | ||||
|   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()); | ||||
| #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; | ||||
| } | ||||
|  | ||||
| const char* TimeService::getCurrentTime() { | ||||
|   struct tm tmstruct; | ||||
|   static char buf[20]; | ||||
|   time_t now; | ||||
|   // get current time | ||||
|   time(&now); | ||||
|   localtime_r(&now, &tmstruct); | ||||
|   static char buf[20]; | ||||
|   strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tmstruct); | ||||
|   esp3d_log("Time string is %s", buf); | ||||
|   return buf; | ||||
|   | ||||
| @@ -45,6 +45,7 @@ class TimeService { | ||||
|   bool _started; | ||||
|   bool _isInternetTime; | ||||
|   String _time_zone; | ||||
|   String _time_zone_config; | ||||
| }; | ||||
|  | ||||
| extern TimeService timeService; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user