RTC class - available methods

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
BigMan
Posts: 22
Joined: Sat Oct 29, 2016 2:29 pm

RTC class - available methods

Post by BigMan » Sun Dec 18, 2016 9:47 am

According to http://docs.micropython.org/en/latest/e ... e.RTC.html, there is a Class RTC available in MicroPython. It seems this Class is in the Module machine. When I follow the example code from the link above (extented by import machine), it doesn't know the init() nor the now() method.

Code: Select all

import machine
rtc = machine.RTC()
rtc.init((2014, 5, 1, 4, 13, 0, 0, 0))
print(rtc.now())
Results into: AttributeError: 'RTC' object has no attribute 'init'

I am using a bare ESP8266, with "MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266"

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: RTC class - available methods

Post by deshipu » Sun Dec 18, 2016 7:49 pm

That documentation is for MicroPython on the WiPy board. The ESP8266 board has an RTC class too, but it's undocumented.

I once noticed the discrepancies and wanted to update the documentation to match what is there on ESP8266 (the pull request is at https://github.com/micropython/micropyt ... 2334/files), however, that would break the WiPy docs.

BigMan
Posts: 22
Joined: Sat Oct 29, 2016 2:29 pm

Re: RTC class - available methods

Post by BigMan » Sun Dec 18, 2016 10:50 pm

deshipu wrote:That documentation is for MicroPython on the WiPy board. The ESP8266 board has an RTC class too, but it's undocumented.

I once noticed the discrepancies and wanted to update the documentation to match what is there on ESP8266 (the pull request is at https://github.com/micropython/micropyt ... 2334/files), however, that would break the WiPy docs.
Finally, after I read some more general websites about Python, I learnt that I can do the following:

Code: Select all

>>> help(machine.RTC)
object <class 'RTC'> is of type type
  datetime -- <function>
  memory -- <function>
  alarm -- <function>
  alarm_left -- <function>
  irq -- <function>
  ALARM0 -- 0
From your github-link above, I learnt
-.. method:: RTC.alarm(id, time, /*, repeat=False)
Also I found the thread viewtopic.php?t=1083 which has following line of code:

Code: Select all

rtc.alarm(time=10000, repeat=True)
But when I am trying the following:

Code: Select all

import machine
rtc = machine.RTC()
rtc.alarm(time=10000, repeat=True)
==> TypeError: function does not take keyword arguments

But what is working:

Code: Select all

rtc.alarm(machine.RTC.ALARM0, 10000)
==> But how to set the repeat-argument to True?

Code: Select all

rtc.alarm(machine.RTC.ALARM0, 10000, True)
==> TypeError: function takes 3 positional arguments but 4 were given
Last edited by BigMan on Mon Dec 19, 2016 6:19 am, edited 2 times in total.

Post Reply