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

    Hidden network issue - Update?

    Scheduled Pinned Locked Moved Pybytes IoT platform
    4 Posts 2 Posters 325 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.
    • R Offline
      robi90
      last edited by

      Re: Hidden network issue - not connecting

      Hello,

      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,

      Robert

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        svonbentzel @robi90
        last edited by

        @robi90

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

        1 Reply Last reply Reply Quote 0
        • R Offline
          robi90
          last edited by robi90

          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)
          
                      try:
                          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():
                              time.sleep(0.1)
                      except Exception as e:
                          if str(e) == "list index out of range":
                              print("Please review Wifi SSID and password inside config")
                          else:
                              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.

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            svonbentzel @robi90
            last edited by

            @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! 👍

            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