← index #4394Issue #5315
Related · high · value 3.295
QUERY · ISSUE

esp32 localtime and machine.RTC().datetime() inconformity

openby junhuanchenopened 2019-01-03updated 2026-03-24
port-esp32

see this

https://github.com/micropython/micropython/blob/b33f108cdeb57c9d84e5a4eff5a46aa49c6dd558/ports/esp32/modutime.c#L52

and this

https://github.com/micropython/micropython/blob/b9ec6037edf5e6ff6f8f400d70f7351d1b0af67d/ports/esp32/machine_rtc.c#L105

I know it seems to have been designed, but if I assign values like this, I won't be able to use the following code.

machine.RTC().datetime(time.localtime(546450051)) # 546450051 only a number.

Is there a better way to set seconds to RTC time.

Otherwise I'll fill in the third element to align the structures, is that so?

CANDIDATE · ISSUE

[esp32] machine/RTC.datetime() does not set microseconds

closedby nevercastopened 2019-11-11updated 2019-11-13
port-esp32

Unrelated to the other issues with RTC, https://github.com/micropython/micropython/issues/4394 and https://github.com/micropython/micropython/issues/3674. The ESP32 RTC implementation does not support the 8th argument in the datetime tuple. Microseconds.

When calling RTC.datetime() the format is year, month, day, weekday, hour, minute, second, microseconds. However, when setting the last component, microseconds are ignored. This means the RTC can only be set to the lower() second.

As seen here https://github.com/micropython/micropython/blob/258b1478307c1f9d89ed67309e145b9a55aeaadc/ports/esp32/machine_rtc.c#L105-L106, tv.tv_usec is not set.

This is an easy fix and a good improvement to the time functionality on the ESP32. Without it, the time cannot be accurately synchronized with other devices.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied