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

    Syncing RTC To Network Time

    Scheduled Pinned Locked Moved LoPy
    24 Posts 8 Posters 13.8k Views 10 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.
    • R Offline
      rdixey @santorcuato
      last edited by rdixey

      @santorcuato I used it as a function in the boot.py of my LoPy. I had to set a delay to allow for the round trip to pool.ntp.org or else the function completed before ntp_sync and RTC remained = Unix Epoch . When I ping pool.ntp.org from my LAN the longest round trip was 630ms so I set sleep at 750ms. Less than that was too short.

      def setRTCLocalTime():
          rtc = machine.RTC()
          rtc.ntp_sync("pool.ntp.org")
          utime.sleep_ms(750)
          print('\nRTC Set from NTP to UTC:', rtc.now())
          utime.timezone(-18000)
          print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')
      
      Connecting to a LoPy...
      Connected
      >>> 
      PYB: soft reboot
      
      RTC Set from NTP to UTC: (2017, 2, 26, 13, 18, 54, 225113, None)
      Adjusted from UTC to EST timezone (2017, 2, 26, 8, 18, 54, 6, 57)
      
      S 1 Reply Last reply Reply Quote 0
      • R Offline
        rdixey @livius
        last edited by

        @livius Excuse Me :) I already know what mktime() is. And I don't need anyone to give me instructions on using google to find info. I was pointing out a typo in the doc's.

        https://docs.pycom.io/pycom_esp32/library/utime.html

        mktime is the first function in the list and is described as 'Convert a time expressed in seconds since the Epoch.' I believe this is an error and should be gmtime().

        mktime is listed again as the third functon and described correctly.

        gmtime() is not in the list at all.

        L 1 Reply Last reply Reply Quote 2
        • L Offline
          livius @rdixey
          last edited by

          @rdixey said in Syncing RTC To Network Time:

          instructions

          Without explanation that function is twice in doc - this was my first hint ;-)

          think about people first, then computers

          1 Reply Last reply Reply Quote 0
          • S Offline
            santorcuato @rdixey
            last edited by

            @rdixey Ok, it seems interesting. Will try!

            Thanks

            1 Reply Last reply Reply Quote 0

            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
            • 2
            • 2 / 2
            • First post
              Last post

            Pycom on Twitter

            Pycom