RTC ntp time server not working on static ip



  • I am a new user but have been experimenting with LoPy using the latest firmware. I noticed that the RTC update using a time server doesn't work if the LoPy is using a static address.

    This prints the time from the time server

        wlan = WLAN()
        wlan.init(mode=WLAN.STA)
        wlan.ifconfig(0,config='dhcp')
        rtc = RTC()
        rtc.ntp_sync('pool.ntp.org', 3600)
        print(rtc.now())
    

    This just produces a 1970 time stamp!

        wlan = WLAN()
        wlan.init(mode=WLAN.STA)
        wlan.ifconfig(0,config=('192.168.1.91', '255.255.255.0', '192.168.1.254' ,'8.8.8.8'))
        rtc = RTC()
        rtc.ntp_sync('pool.ntp.org', 3600)
        print(rtc.now())
    


  • @shariq Obviously you can set up your own ntp server, if you like, which is called instead of the ntp server pool on the internet. if you get the date & time from a different source, like an external rtc, you can use rtc.init() to set the local date & time.



  • @livius does ntp works with internet only? in case I want to connect my pycom to update time for rtc.



  • @Rorence said in RTC ntp time server not working on static ip:

    I have no idea about how to fix this error. I just want to search answers on here.

    For now, there are two options:

    1. use dhcp instead of a fixed IP:
    wlan.ifconfig(0,config='dhcp')
    
    1. if you really have/want to use a fixed IP, use an IP-nummer for the ntp server instead of a FQDN. For example
    rtc.ntp_sync('128.199.44.119', 3600)
    

    instead of

    rtc.ntp_sync('pool.ntp.org', 3600)
    

    An issue has been posted with regards to this error, but no time line has been added for that. Once it has been fixed in the firmware, you shouldn't have to worry about it anymore. :)





  • Could you please create an issue outlining this on our GitHub repo? This is where Daniel and the team head first to tackle outstanding firmware issues/bugs :)

    https://github.com/pycom/pycom-micropython-sigfox/issues



  • Problem also in latest fimware

    >>> import os
    >>> os.uname()
    (sysname='LoPy', nodename='LoPy', release='1.6.13.b1', version='v1.8.6-607-g9c8a0e9e on 2017-05-01', machine='LoPy with ESP32', lorawan='1.0.0')
    >>> wlan.ifconfig()
    ('192.168.0.191', '255.255.255.0', '192.168.0.1', '213.46.228.196')
    >>> import machine
    >>> rtc = machine.RTC()
    >>> rtc.ntp_sync('pool.ntp.org', 3600)
    >>> rtc.now()
    (1970, 1, 1, 0, 2, 21, 96633, None)
    >>> rtc.ntp_sync('128.199.44.119', 3600)
    >>> rtc.now()
    (2017, 5, 16, 6, 3, 44, 126771, None)
    


  • @livius Don't know yet, I wanted to finish my write-up of connecting a GPS receiver first before disconnecting stuff and upgrading the firmware. Could be something fixed in the latest version.



  • @PiAir
    Then it looks like some error. In firmware?



  • @livius With other websites (my own) I have the same problem: sometimes it returns the IP-address, other times just zero's. Same as with the ntp.org site.



  • @PiAir
    What if you do the same for "normal" address not ntp e.g www.pycom.io?
    Ntp pool count requests and if you ask too frequent then you can have problem.



  • I can confirm this behavior.
    What 'fixed' it for me was to not use 'pool.ntp.org' but the/a actual IP address: 128.199.44.119.

    >>> import machine
    >>> rtc = machine.RTC()
    >>> rtc.ntp_sync('pool.ntp.org', 3600)
    >>> print(rtc.now())
    (1970, 1, 1, 0, 0, 39, 726100, None)
    >>> rtc.ntp_sync('128.199.44.119', 3600)
    >>> print(rtc.now())
    (2017, 5, 14, 16, 3, 6, 118200, None)
    

    Note: this is not a real fix, but it appears that, despite setting the DNS server, the LoPy can't always get the IP address
    For example, if I use socket.getaddrinfo() I often get an IP address, but not always:

    >>> wlan.ifconfig() ('192.168.0.191', '255.255.255.0', '192.168.0.1', '213.46.228.196')
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('0.0.0.0', 80))]
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('122.175.14.128', 80))]
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('16.88.252.63', 80))]
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('0.0.0.0', 80))]
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('0.0.0.0', 80))]
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('0.0.0.0', 80))]
    >>> socket.getaddrinfo('pool.ntp.org', 80)
    [(2, 1, 0, '', ('80.87.252.63', 80))]
    
    

    The info of my LoPy:

    >>> import os
    >>> os.uname()
    (sysname='LoPy', nodename='LoPy', release='1.6.9.b1', version='v1.8.6-535-g84855b2b on 2017-03-24', machine='LoPy with ESP32', lorawan='1.0.0')
    
    

    I will upgrade to the latest firmware asap to check if it is fixed there, but have to document a project I have been working on this weekend first.



  • @gandm
    yes



  • @livius Thanks - Why post it to a sigfox repo? I'm using LoRa. Is the sigfox repo applicable for all MSP code?



  • @gandm
    I do not tested this
    but if this behavior exist then write issue on Github
    https://github.com/pycom/pycom-micropython-sigfox/issues



  • @livius No it's a sample. I removed the WLAN join code as well as a time.sleep(1) before the print(rtc.now()) as it needs some time to retrieve the time from the ntp server. The WLAN access in both cases is fine I use Putty, WinSCP and Atom to access the device no problem.



  • @gandm
    Is this only sample? or you use in real code line:

    wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000)
    

Log in to reply
 

Pycom on Twitter