← index #4394Issue #3674
Related · high · value 5.871
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 tuple parameters don't match documentation

openby ed-frenchopened 2018-03-19updated 2024-09-19
docsport-esp32

Micropython documentation: http://docs.micropython.org/en/latest/wipy/library/machine.RTC.html
Shows machine.rtc.init documented with tuple like this:

RTC.init(datetime)
Initialise the RTC. Datetime is a tuple of the form:

(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

However, the code suggests a different order is used: https://github.com/micropython/micropython/blob/master/ports/esp32/machine_rtc.c

timeutils_seconds_since_2000(mp_obj_get_int(items[0]), mp_obj_get_int(items[1]), mp_obj_get_int(items[2]), mp_obj_get_int(items[4]), mp_obj_get_int(items[5]), mp_obj_get_int(items[6]))

Likewise with machine.rtc.datetime actually returns this order of parameters in the tuple:

r.datetime()
(2018, 3, 21, 2, 6, 8, 19, 258907)
r.datetime()
(2018, 3, 21, 2, 6, 8, 22, 828728)
r.datetime()
(2018, 3, 21, 2, 6, 9, 31, 888997)
r.init((2018,3,19,0,7,5,0,0))
r.datetime()
(2018, 3, 19, 0, 7, 5, 4, 368663)
r.datetime()
(2018, 3, 19, 0, 7, 5, 16, 608804)
r.datetime()
(2018, 3, 19, 0, 7, 5, 38, 98816)

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