如果这是一个新手问题,很抱歉,但是我已经通过http://www.cplusplus.com/reference/ctime/tm/教程等耗尽了我的研究。
我正在使用ESP32的Arduino SimpleTime示例,但希望能够在没有互联网接入的情况下设置时间。
我在过去的一个项目中使用TimeLib.h,该项目使用setTime(Hour, Minute, Second, MDay, Mon, Year)函数设置时间功能,但是根据Espressif问题#120:https://github.com/espressif/arduino-esp32/issues/120,该库和时钟实现似乎容易受到时间推进的影响
我已经测试了SimpleTime草图,没有发现任何时间提前漂移由于模数转换器读取,所以希望能够设置从启动ESP32也在没有互联网接入的情况下,仍然能够运行的时间,以便我可以使用time(NULL),mktime(tm_struct)等。
有没有不同的configTime(gmtOffset_sec, daylightOffset_sec, ntpServer)实现方式呢?
提前感谢:)
发布于 2019-11-21 05:26:42
我遇到了完全相同的问题,并找到了一种方法。我想将时间存储在EEPROM中,并且很少通过ntp同步时间。因此,在掉电的情况下,时间将从EEPROM加载。
这就是我设定时间的方式
tm local;
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_UNDEFINED) { // if reset or power loss
struct timeval val;
loadStruct(&local); // e.g. load time from eeprom
const time_t sec = mktime(&local); // make time_t
localtime(&sec); //set time
} else {
getLocalTime(&local);
}就这样!你的时间定好了。
发布于 2021-01-19 13:00:04
查看这个库,ESP32Time
时间可以设置如下;
setTime(30, 24, 15, 17, 1, 2021); // 17th Jan 2021 15:24:30
setTime(1609459200); //specify the epoch, 1st Jan 2021 00:00:00
setTime(); // default 1st Jan 2021 00:00:00https://stackoverflow.com/questions/54458116
复制相似问题