@@ -951,22 +951,38 @@ def rsync(src_dir, dst_dir, mirror, dry_run, print_func, recursed, sync_hidden):
951951def set_time (rtc_time ):
952952 rtc = None
953953 try :
954- # Pyboard (pyboard doesn't have machine.RTC())
954+ # Pyboard (pyboard doesn't have machine.RTC()).
955+ # The pyb.RTC.datetime function takes the arguments in the order:
956+ # (year, month, day, weekday, hour, minute, second, subseconds)
957+ # http://docs.micropython.org/en/latest/library/pyb.RTC.html#pyb.RTC.datetime
955958 import pyb
956959 rtc = pyb .RTC ()
957960 rtc .datetime (rtc_time )
958961 except :
959962 try :
963+ import pycom
964+ # PyCom's machine.RTC takes its arguments in a slightly different order
965+ # than the official machine.RTC.
966+ # (year, month, day, hour, minute, second[, microsecond[, tzinfo]])
967+ # https://docs.pycom.io/firmwareapi/pycom/machine/rtc/#rtc-init-datetime-none-source-rtc-internal-rc
968+ rtc_time2 = (rtc_time [0 ], rtc_time [1 ], rtc_time [2 ], rtc_time [4 ], rtc_time [5 ], rtc_time [6 ])
960969 import machine
961970 rtc = machine .RTC ()
971+ rtc .init (rtc_time2 )
972+ except :
962973 try :
963- # ESP8266 uses rtc.datetime() rather than rtc.init()
964- rtc .datetime (rtc_time )
974+ # The machine.RTC documentation was incorrect and doesn't agree with the code, so no link
975+ # is presented here. The order of the arguments is the same as the pyboard.
976+ import machine
977+ rtc = machine .RTC ()
978+ try :
979+ # ESP8266 uses rtc.datetime() rather than rtc.init()
980+ rtc .datetime (rtc_time )
981+ except :
982+ # ESP32 (at least Loboris port) uses rtc.init()
983+ rtc .init (rtc_time )
965984 except :
966- # ESP32 (at least Loboris port) uses rtc.init()
967- rtc .init (rtc_time )
968- except :
969- pass
985+ pass
970986
971987
972988# 0x0D's sent from the host get transformed into 0x0A's, and 0x0A sent to the
0 commit comments