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

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

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

Post by enzo » Tue Mar 09, 2021 3:17 pm

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.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

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

Post by jimmo » 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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Thu Mar 11, 2021 8:06 am

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.
Peter Hinch
Index to my micropython libraries.

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

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

Post by enzo » Fri Mar 12, 2021 1:28 pm

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 :-)

Post Reply