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

    Timeout for wlan.connect()

    Scheduled Pinned Locked Moved SiPy
    wlan
    10 Posts 6 Posters 2.6k Views 6 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.
    • A Offline
      alidaf
      last edited by

      Does this timeout just silently stop trying to disconnect?

      In the example given, where

          wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000)
          while not wlan.isconnected():
              machine.idle() # save power while waiting
      

      If the timeout is reached, the loop becomes infinite. So what use is it?

      L robert-hhR 2 Replies Last reply Reply Quote 1
      • L Offline
        livius @alidaf
        last edited by

        @administrators @daniel

        i see in sources that timeout is currently silently ignored - passed to wlan_do_connect but not used
        and in sources is

        // TODO Add timeout handling!!

        will be good to have something like wlan.istimeout()
        and then above loop can be changed to:

        while not wlan.isconnected() or not wlan.istimeout():
                machine.idle() # save power while waiting
        

        think about people first, then computers

        P R 2 Replies Last reply Reply Quote 1
        • robert-hhR Offline
          robert-hh @alidaf
          last edited by

          @alidaf wlan.connect() returns immediately, while the connection is attempted. That's why the loop waiting for a connection follows. In my standard script I let the loop terminate after 10 seconds, if not connection is flagged. So it looks like:

              wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000)
              for _ in range (10):
                  if wlan.isconnected():
                      break
                  else:
                      time.sleep(1)
          
          A L 2 Replies Last reply Reply Quote 0
          • A Offline
            alidaf @robert-hh
            last edited by

            @robert-hh Yes, I implemented my own timeout. The problem is that there really shouldn't be any examples that are essentially broken because the function implementation is incomplete or the coding is just poorly thought out, as is the case here.

            1 Reply Last reply Reply Quote 0
            • L Offline
              livius @robert-hh
              last edited by

              @robert-hh
              Yes, but it still try to connect after the loop finished (i do not know how long is default timeout set)
              e.g if internal timeout is e.g 30 s and you finish loop after 5 s
              it still wait for timeout :/

              think about people first, then computers

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

                @livius @alidaf I agree that the situation is not the best one, technically, because in case of your own set timeout you do not know, whether the connection is evatually made later on. Documentation wise too. The documentation is partially copied over from the initial micropython project, and both the inherited content and the examples need a careful review, not to speak about new features, which may not be documented at all. But there seems to be progress, since @Xykon seems to take care fo it now.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TravisT
                  last edited by

                  I wanted to bring this up again when trying to implement my own robust wlan handling.

                  At the very least the documentation should state that it is not fully implemented, better yet it would be fixed.

                  1 Reply Last reply Reply Quote 0
                  • P Offline
                    Prawnhead @livius
                    last edited by

                    @livius Old post, I know. But could you please link me to the source file handling WLAN? I can't find it and I'm chasing a similar issue. Thanks.

                    L 1 Reply Last reply Reply Quote 0
                    • L Offline
                      livius @Prawnhead
                      last edited by

                      @prawnhead
                      https://github.com/pycom/pycom-micropython-sigfox/blob/master/esp32/mods/modwlan.c

                      think about people first, then computers

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        r.groesbeek @livius
                        last edited by

                        @livius said in Timeout for wlan.connect():

                        @administrators @daniel

                        i see in sources that timeout is currently silently ignored - passed to wlan_do_connect but not used
                        and in sources is

                        // TODO Add timeout handling!!

                        will be good to have something like wlan.istimeout()
                        and then above loop can be changed to:

                        while not wlan.isconnected() or not wlan.istimeout():
                                machine.idle() # save power while waiting
                        

                        An 'wlan.istimeout()' would seem like a good suggestion!
                        How can we check currently if there was a timeout occuring?

                        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