我正在使用带有 LORA (Arduino LMIC) 的 ESP32, 当我连接到 LORA 网络时,我在 ESP32 中的时间由网络设置。
当我的 ESP32 进入“深度睡眠”时,我需要知道如何 几秒钟,直到晚上 03:00。
我试图比较两次(“现在时间”)和(“起床时间”)。 但它不起作用,我不知道为什么...
tmElements_t tm;
tmElements_t tmConvert(byte hh, byte mm, byte ss)
{
tm.Hour = hh;
tm.Minute = mm;
tm.Second = ss;
tm.Day = 1;
tm.Month = 1;
tm.Year = 1970;
return tm;
}
unsigned long timeDiff(tmElements_t& tm1, tmElements_t& tm2)
{
return makeTime(tm2) - makeTime(tm1);
}
void test()
{
tmElements_t Time_wake = tmConvert(1, 0, 0);
tmElements_t Time_now = tmConvert(18, 0, 0);
int _diff = (timeDiff(Time_wake, Time_now));
Serial.println("hours: ");
Serial.print(_diff / 3600);
}
答案 0 :(得分:0)
我解决了:
我也必须使用日期,
如果“时间”在午夜之后,日期(天)必须是第二天...