ESP32 set time offset
Posted: Tue May 04, 2021 11:56 am
I want to load the time from my own server and set the ESP32 clock to the received time.
The time from my server is a php script that returns this:
The EPS32 receives the time and sets the internal clock like this:
I don't want to set a timezone because every device can be placed around the world where there are different timezones so i want my php script to take care of that (in the future).
The only problem is that the EPS has 1 hour and 43 minutes time difference than the current time.
PHP shows the right time but the EPS converts it "wrong" to display the correct time.
To show the time, i use this code:
If i add 6130 seconds to the php time, i get the correct time in the ESP32
What am i doing wrong here?
The time from my server is a php script that returns this:
Code: Select all
<?PHP
echo strtotime(date('Y-m-d H:i:s'));
?>
Code: Select all
struct timeval tv;
tv.tv_sec = atol(receivedTime);
settimeofday(&tv, NULL);
The only problem is that the EPS has 1 hour and 43 minutes time difference than the current time.
PHP shows the right time but the EPS converts it "wrong" to display the correct time.
To show the time, i use this code:
Code: Select all
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
What am i doing wrong here?