I swore I had RTC ntp_sync() working on my Lopy and now I can't get it working at all?



  • Hi. I was writing a pair of Lora test apps to NTP sync the clock from one to the other, where ntp_sync() was used to setup the RTC. I swore I had this bit working yesterday and now I can't get anything working over

    import machine
    from machine import RTC
    from machine import UART
    from network import WLAN
    from network import LoRa
    
    import os
    import time
    import socket
    import pycom
    
    uart = UART(0, 115200)
    os.dupterm(uart)
    
    pycom.heartbeat(False)
    
    wlan = WLAN()
    if machine.reset_cause() != machine.SOFT_RESET:
        wlan.init(mode=WLAN.STA)
        wlan.ifconfig(config=('192.168.2.230', '255.255.255.0', '192.168.2.1', '192.168.2.3'))
    if not wlan.isconnected():
        wlan.connect(ssid='SSID', auth=(WLAN.WPA2, 'password'))
        while not wlan.isconnected():
            machine.idle() # save power while waiting
    print(wlan.ifconfig())
    
    print("Syncing RTC to NTP...")
    rtc = RTC()
    rtc.ntp_sync("pool.ntp.org", update_period=3600)
    while not rtc.synced():
        pass # save power while waiting
    print(rtc.now())
    

    Basically the ntp_sync() call and subsequent while loop just sits there while nothing syncs. I'm tempted to try and setup a wireshark sniffer on my router to watch what the Lopy is trying to do over the Wifi network.

    Any ideas? Thanks!



  • @paul-thornton I replied on another thread that I think you responded to that I have this issue with 1.20.0.rc0. I reverted back to my unmodified build of 1.19.0.b4 and the problem disappeared. I found that after machine.reset() the clock still would not sync reliably (or at all) and even sometimes after a hard reset by hitting the reset button.



  • @protean Can you confirm your on the latest firmware?



  • @protean
    Have you tried to use a IP adress instead of the URL? Just for testing...



  • Did you ever solve this? I'm still having this issue, today, on a FiPy.



  • Ah... I think my machine.SOFT_RESET might have had something to do with it. When I hit the reset button on the unit it reloaded and reconnected to my wifi correctly I believe, because I started ntp_sync()ing correctly. Thanks.


Log in to reply
 

Pycom on Twitter