Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Update my RTC value

    Scheduled Pinned Locked Moved LoPy
    2 Posts 2 Posters 27 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      M m
      last edited by

      I want to update the RTC of my Lopy. Reading the docs seems that I just have to write the following code:

      from machine import RTC
      
      rtc = RTC()
      rtc.ntp_sync("es.pool.ntp.org") # I'm from Spain
      print(rtc.now(),'\n')
      

      But the output is: (1970, 1, 1, 0, 0, 0, 817, None).

      Then I thought, ok, I need to be connected to internet, thus I write the following code:

      from machine import RTC, idle
      from network import WLAN
      
      wlan = WLAN(mode=WLAN.STA)
      wlan.connect(ssid='vodafone55s6654', auth=(WLAN.WPA2, 'uh5a55ss8d4wed55'))
      while not wlan.isconnected():
          idle()
      print("WiFi connected succesfully")
      rtc = RTC()
      rtc.ntp_sync("es.pool.ntp.org")
      print(rtc.now(),'\n')
      

      But I have the same output, (1970, 1, 1, 0, 0, 0, 817, None), yet.

      If I put print(rtc.synced()) returns False confirming that it could not sync. I tried to init it with a random date but
      it is useless.

      (With rtc.ntp_sync("pool.ntp.org") or "0.europe.pool.ntp.org" instead of rtc.ntp_sync("es.pool.ntp.org") the outputs are the same)

      Thank you for all!

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gijs
        last edited by

        Hi,
        It might take a couple of seconds / minutes before the device is synced to the ntp time, depending on the availability and how often you already tried (I think they have some sort of fair use policy). You might want to use a loop like this:

        while not rtc.synced():
           time.sleep(1)
        

        Which will continue after syncing

        1 Reply Last reply Reply Quote 2

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom