changed now to nowTime dow to conflict with function name now(), settimeofday got incorrect timevalue

This commit is contained in:
Marius Gripp 2019-05-13 14:32:27 +02:00
parent 646d60e9c5
commit f475a634d5

View File

@ -247,18 +247,18 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec) {
if(gettimeofday(&tv, &tz) != 0) { if(gettimeofday(&tv, &tz) != 0) {
ESP_LOGI(TAG, "ERROR gettimeofday"); ESP_LOGI(TAG, "ERROR gettimeofday");
} }
struct timeval before = tv; struct timeval beforeTime = tv;
struct timeval now; struct timeval nowTime;
now.tv_sec = t_sec; nowTime.tv_sec = t_sec;
now.tv_usec = t_msec; nowTime.tv_usec = t_msec;
if(settimeofday(&tv, &tz) != 0) { if(settimeofday(&nowTime, &tz) != 0) {
ESP_LOGE(TAG, "ERROR settimeofday"); ESP_LOGE(TAG, "ERROR settimeofday");
} }
struct timeval diff; struct timeval diff;
diff.tv_sec = now.tv_sec-before.tv_sec; diff.tv_sec = nowTime.tv_sec-beforeTime.tv_sec;
diff.tv_usec = now.tv_usec-before.tv_usec; diff.tv_usec = nowTime.tv_usec-beforeTime.tv_usec;
// sum up diff_s and diff_ms to one ms value // sum up diff_s and diff_ms to one ms value
int32_t diff_s = diff.tv_sec; int32_t diff_s = diff.tv_sec;