micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.14k stars 7.66k forks source link

esp32: machine.RTC() function issue in ntptime.py #4454

Open hetvishah08 opened 5 years ago

hetvishah08 commented 5 years ago

I think there is an issue with RTC in ntptime.py whenever i use this module it gives me either this error or no response. I tried it by removing the RTC functions and it worked fine. I am using Ethernet as my network with ESP32 DevkitC and LAN8720 module.

Code and Debug Messages:

>>>from machine import Pin
>>> import network
>>> l = network.LAN(mdc = Pin(23), mdio = Pin(18), power = Pin(17), phy_type=network.PHY_LAN8720, phy_addr=1)
I (37895) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
>>> l.active(1)
I (44815) emac: emac start !!!

I (44815) emac: emac resetting ....
I (44815) emac: emac reset done
I (44825) emac: emac start success !!!
I (44825) network: event 20
True
>>>
 I (48825) emac: eth link_up!!!
I (48825) network: event 22
I (51675) event: eth ip: 192.168.29.71, mask: 255.255.255.0, gw: 192.168.29.1
I (51675) network: event 24
>>> import ntptime
I (71525) modsocket: Initializing
>>> ntptime.settime()
>>>
>>> ntptime.settime()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ntptime.py", line 30, in settime
  File "ntptime.py", line 22, in time
OSError: [Errno 110] ETIMEDOUT

I get no response maybe because settime() function isn't returning any value according to ntptime.py. When i downloaded the ntptime.py file and removed the RTC part and it worked.I also tried with the RTC part and just added return to the settime() function, it still gave me the same to errors.Here is the log with RTC part removed and return value added:

> >>> from machine import Pin
>>> import network
>>> l = network.LAN(mdc = Pin(23), mdio = Pin(18), power = Pin(17), phy_type=network.PHY_LAN8720, phy_addr=1)
I (70375) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
>>> l.active(1)
I (78135) emac: emac start !!!

I (78135) emac: emac resetting ....
I (78135) emac: emac reset done
I (78145) emac: emac start success !!!
I (78145) network: event 20
True
>>> 
 (82145) emac: eth link_up!!!
I (82145) network: event 22                                                                                                                                                     I (83195) event: eth ip: 192.168.29.71, mask: 255.255.255.0, gw: 192.168.29.1
I (83195) network: event 24

>>> import ntptimee
I (93075) modsocket: Initializing
>>> ntptimee.settime()
(2019, 2, 1, 11, 45, 38, 4, 32)
>>>

Here are the changes and i also added 19800 to get time in IST:

def settime():
   t=time()
   import utime
   tm = utime.localtime(t)
   return tm
jonnor commented 1 week ago

Is this issue still present in recent MicroPython versions (1.23 or later)?