Page 1 of 1

RTC class - available methods

Posted: Sun Dec 18, 2016 9:47 am
by BigMan
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"

Re: RTC class - available methods

Posted: Sun Dec 18, 2016 7:49 pm
by deshipu
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.

Re: RTC class - available methods

Posted: Sun Dec 18, 2016 10:50 pm
by BigMan
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