Hidden network issue - Update?

  • Re: Hidden network issue - not connecting


    is there any update / timeframe on when / if you add support for wifi networks with hidden ssids in pybytes?

    For now I modified my version of pybytes library, to support it, but I hope I don't have to stay seperate for long :)

    Kind regards,


  • @robi90

    Hello, great work! I will implement your solution, test and report.

    Many thanks.
    If I found a smoother way i will tell you.

    But for a workaround - great work! 👍

  • sure.

    So the reason it does not work with hidden networks is, that pybytes library doesn't know what security your wlan uses and therefore does a WLAN().scan() to figure that out.

    For that I added another key to the pybytes_config and called it "known_hidden_wlans" (I'm really bad at naming).

      "wifi": {"ssid": "your_ssid", "password": "your_pw"},
      "known_hidden_wlans": [{"ssid": "your_ssid", "sec": INT }]

    Where INT is one of the following values depending on the security of your wifi:

    1 <- WEP
    2 <- WPA
    3 <- WPA2
    5 <- WPA2_ENT

    then I edited a few lines in "pybytes_connection.py" on around line 100:

    <ins>       hidden_nets = self.__conf.get('known_hidden_wlans') if self.__conf.get('known_hidden_wlans') is not None else []  
    <ins>       hidden_ssids = frozenset([x['ssid'] for x in hidden_nets])
                available_nets = self.wlan.scan()
    <chg>       nets = frozenset([e.ssid for e in available_nets]) | hidden_ssids
                known_nets_names = frozenset([e[0]for e in known_nets])
                net_to_use = list(nets & known_nets_names)
                    net_to_use = net_to_use[0]
                    pwd = dict(known_nets)[net_to_use]
    <chg>           sec = ([e.sec for e in available_nets if e.ssid == net_to_use] + [x['sec'] for x in hidden_nets if x['ssid'] == net_to_use])[0] # noqa
                    self.wlan.connect(net_to_use, (sec, pwd), timeout=10000)
                    while not self.wlan.isconnected():
                except Exception as e:
                    if str(e) == "list index out of range":
                        print("Please review Wifi SSID and password inside config")
                        print("Error connecting using WIFI: %s" % e)

    <ins> symbolizes insert of that line
    <chng> an change on that line

    Now the "net_to_use" is either one of the scaned wifis or one of the additonal "known_hidden_wlans".

    Also after I iplemented that change I thought it would probably be more elegent to add sec as a possible key to the "wifi" key in the original config. And if sec exists there, you could try to connect to it instead of scaning.

    EDIT: The only thing I don't really understand is, how can the WLAN().scan() method return a namedtuple although that type is not part of default micropython. It confused me a bit.

  • @robi90

    Hello, can you share your edit lib?
    I have the same problem and need to support hidden ssids!

Log in to reply

Pycom on Twitter