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

    rtc.ntp_sync restart after 30 seconds?

    Scheduled Pinned Locked Moved WiPy 2&3
    6 Posts 2 Posters 460 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.
    • W Offline
      Wolli01
      last edited by

      How can it be done, that no internet connection to the time server will cause a restart after 30 seconds?
      This is my current code.

      rtc.ntp_sync("de.pool.ntp.org")
      while not rtc.synced():
      machine.idle() # save power while waiting
      utime.timezone(TimeDiff)
      time1 = utime.localtime() # Übergabe Datum und
      break

      robert-hhR 2 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Wolli01
        last edited by

        @Wolli01 So I understand that you code is:

        rtc.ntp_sync("de.pool.ntp.org")
        while not rtc.synced():
            machine.idle() # save power while waiting
        utime.timezone(TimeDiff)
        time1 = utime.localtime() # Übergabe Datum und
        break
        

        So why the break at the. Is there another while loop which you do not show?

        W 1 Reply Last reply Reply Quote 0
        • W Offline
          Wolli01 @robert-hh
          last edited by

          @robert-hh No there are no more loops

          1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @Wolli01
            last edited by

            @Wolli01 SO I extended your code snippet to a short test script:

            import utime
            import machine
            rtc=machine.RTC()
            
            TimeDiff = 0
            
            rtc.ntp_sync("de.pool.ntp.org")
            while not rtc.synced():
                machine.idle() # save power while waiting
            utime.timezone(TimeDiff)
            time1 = utime.localtime() # Übergabe Datum und
            print(time1)
            

            That works, does not restart after 30 seconds, but waits forever, if not WiFi is present. I disabled WIFi by calling disconnect().
            Pycom MicroPython 1.20.0.rc13 [1211d6c-dirty] on 2019-08-23; FiPy with ESP32

            W 1 Reply Last reply Reply Quote 0
            • W Offline
              Wolli01 @robert-hh
              last edited by

              @robert-hh Apart from the last line, what's the difference?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @Wolli01
                last edited by

                @Wolli01 The break in your code should simply cause an error while parsing:
                SyntaxError: 'break' outside loop

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

                Pycom on Twitter

                Pycom