← index #5361Issue #5315
Related · high · value 1.489
QUERY · ISSUE

Class RTC on ESP32 documentation bug

openby sengpwopened 2019-11-26updated 2025-10-17
docsport-esp32

RTC.datetime
Testing showed that the 8-tuple has the following format:
(year, month, dayofmonth, dayofweek (0..6, mon=0), hours, minutes, seconds, subseconds)
Not sure about the content/validity of "subseconds", cause this can be set to any value, even bigger 255.
Tested on firmware versions:
esp32spiram-idf3-20190529-v1.11.bin
esp32spiram-idf3-20191126-v1.11-607-g01e5802ee.bin

But documentation says:
Datetime is a tuple of the form:
(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
This is definitely wrong, documentation of pyb.RTC also does not match, cause there weekday is in range 1-7. Can not test this cause only ESP32 available.

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