Timeout for wlan.connect()



  • 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?



  • @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?





  • @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.



  • 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.



  • @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.



  • @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 :/



  • @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.



  • @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)
    


  • @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
    

Log in to reply
 

Pycom on Twitter