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!



  • 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
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.