Now if you really can’t use an external RTC, and you NEED the real time, a third option is to keep track of the date/time in software and calculate the sleep time by checking the current time and then calculating how long you need to sleep for so you wake up at the right time. No need for the time struct you mentioned. If you just want to sleep for a duration (1 hour, 1 minute, etc), then you can just use the timer as wakeup source (sere link). Then you can set an “alarm” on it to pull a pin high/low at a specific time, and use that as external wakeup signal for your ESP32. They keep track of the real world date/time, once you set it correctly once (it’s also what’s in a normal computer/laptop). If you want to accurately wake up at a specific date/time, then your best bet is to use an accurate, external RTC. If you want to get the real world time (like 10pm), you need to manually keep track of it, since there is no “calendar” function in the builtin Real Time Clock (RTC) of the ESP32. The device must know which timezone it is in, since when it’s 10pm in London happens it’s some earlier time in the USA etc (GMT minus something). Using localtime however must be done carefully, since it expect the correct timezone to be set. You can then check that if you have passed the 10PM mark, aka 22 in the tm_hours field (referenced from 0 to 23!), and then go to deepsleep. You can then use localtime() to convert the output of time() into a struct tm, which has the desired tm_hours field. try and use time and functions ( docs) to see if you can output the correct real world time. First, you have to have a valid RTC time, so that has to be synchronized once ( e.g. So you have to slightly rethink your logic. So that’s syntactically incorrect.Īlso millis() will give the amount of elapsed milliseconds since the start of the firmware, not the absolute real-world time in milliseconds. ![]() Tm_hour is a member of the struct tm structure, not a standalone function / macro / variable definition in itself.
0 Comments
Leave a Reply. |