Page 1 of 1

ESP32 RTC.now() is not in MicroPython v1.14?

Posted: Tue Mar 09, 2021 3:17 pm
by enzo
Hi,
I get this error

Code: Select all

>>> rtc.now()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'RTC' object has no attribute 'now'
in MicroPython v1.14 on 2021-02-02 I flashed into my ESP32.
Indeed "now" isnìt in the dir of rtc but I can't see any other method to retrieve date and time from it: 'datetime', 'init', 'memory' are the only ones i can find.
How can I retrieve the date and time?
Thanks.

Re: ESP32 RTC.now() is not in MicroPython v1.14?

Posted: Thu Mar 11, 2021 5:53 am
by jimmo
enzo wrote:
Tue Mar 09, 2021 3:17 pm
How can I retrieve the date and time?
I don't know why ESP32 is different, but I think rtc.datetime() is what you want.

Re: ESP32 RTC.now() is not in MicroPython v1.14?

Posted: Thu Mar 11, 2021 8:06 am
by pythoncoder
jimmo wrote:
Thu Mar 11, 2021 5:53 am
...
I don't know why ESP32 is different, but I think rtc.datetime() is what you want.
I raised this PR well over a year ago. It is a minimal fix to the docs so that the example code actually works. No code change, just docs. It was never merged, possibly because as a fix it is only partial. Or maybe just another manifestation of MicroPython time dilation. It would be good, when we take the trouble to raise a PR and it is ignored, to be given a reason. But broken examples aren't good.

The RTC docs are a shambles, with rtc.datetime() necessary but undocumented. It also suffers multiple port dependent problems. RTC issues are recurrent in this forum.

Re: ESP32 RTC.now() is not in MicroPython v1.14?

Posted: Fri Mar 12, 2021 1:28 pm
by enzo
jimmo wrote:
Thu Mar 11, 2021 5:53 am
enzo wrote:
Tue Mar 09, 2021 3:17 pm
How can I retrieve the date and time?
I don't know why ESP32 is different, but I think rtc.datetime() is what you want.
Thanks! I didn't try that :-)