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)
    wlan = WLAN()
    if machine.reset_cause() != machine.SOFT_RESET:
        wlan.ifconfig(config=('', '', '', ''))
    if not wlan.isconnected():
        wlan.connect(ssid='SSID', auth=(WLAN.WPA2, 'password'))
        while not wlan.isconnected():
            machine.idle() # save power while waiting
    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

    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.


Hello World?

Pylife on Kickstarter - November 2018

Back Us On Kickstarter >

Pycom on Twitter