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

    No Wifi connection on boot

    Scheduled Pinned Locked Moved Issues & Bugs
    lopywifi
    15 Posts 3 Posters 3.6k Views 3 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.
    • P Offline
      poebler
      last edited by poebler

      Hi,

      it tried all example and tutorials but my LoPy is not connecting to wifi after a reset. The problem is always the same - it tries and fails. If i interrupt the script after a failed connection and paste the connect() to the REPL it is connecting fine, so basiclly my settings / credentials are fine.

      here is my current wifi code:

      known_nets = {
              # SSID : PSK (passphrase)
              'waterworld': '​secretkey'
          } # change this dict to match your WiFi settings
      
      # test needed to avoid losing connection after a soft reboot
      if machine.reset_cause() != machine.SOFT_RESET:
          from network import WLAN
          wl = WLAN(mode=WLAN.STA)
      
          while not wl.isconnected():
              print("new round")
              for ssid, bssid, sec, channel, rssi in wl.scan():
                  # Note: could choose priority by rssi if desired
      
                  try:
                      print("trying to connect to " + ssid)
                      wl.connect(ssid, (sec, known_nets[ssid]), timeout=5000)
      
                      if not wl.isconnected():
                          print("reinit")
                          time.sleep(5)
                          wl.deinit()
                          wl.init(mode=WLAN.STA)
                      break
                  except KeyError:
                      pass # unknown SSID
      print(wl.ifconfig())
      

      The funny thing on my code is now, after a reinit, th LoPy doesn't find my network anymore, so after that is goes to an endless loop.

      What am i doing wrong?
      Thanks for help!

      L M 2 Replies Last reply Reply Quote 0
      • L Offline
        livius @poebler
        last edited by livius

        @poebler
        You loop throught all networks in range
        but you pass parameter only for known network

        wl.connect(ssid, (sec, known_nets[ssid]), timeout=5000)
        

        for unknown you pass None - i suppose this can be a problem here
        i known that you include try except - but here it is reall wrong.
        change your logic and
        check before connect if this is known network if not then do not try to connect to it

        think about people first, then computers

        1 Reply Last reply Reply Quote 0
        • P Offline
          poebler
          last edited by

          Hi,
          thanks for your reply. This could be a problem - but not the initial one, that i find my network but i'm not able to connect though my credentials are right and a manual connect succededs ...

          Any other ideas?

          Thanks in advance!

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

            @poebler
            i was wrong in first post.
            You do not pass None - you got error on dictionary key access and not tried to connect
            then problem must be somewhere else.

            But first question should be - what is your firmware version?

            os.uname()
            

            think about people first, then computers

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

              @livius 1.7.3.b2

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

                @poebler
                what happened if you change this line
                wl.connect(ssid, (sec, known_nets[ssid]), timeout=5000) to

                wl.connect(ssid=ssid, auth=(sec, known_nets[ssid]), timeout=5000)
                

                ?

                think about people first, then computers

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

                  @livius tried this also - no change :/

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

                    @poebler
                    what if you add debug info

                    print(time.ticks_ms())
                    wl.connect(ssid, (sec, known_nets[ssid]), timeout=5000)
                    print(time.ticks_ms())
                    if not wl.isconnected():
                              print(time.ticks_ms())
                              print("reinit")        
                    

                    show debug info
                    and what if you change connection as static IP?

                    # go for fixed IP settings (IP, Subnet, Gateway, DNS)
                    wlan.ifconfig(config=('192.168.0.107', '255.255.255.0', '192.168.0.1', '192.168.0.1'))
                    

                    any change?

                    think about people first, then computers

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

                      @livius I'm at work so i can try it first this evening. But the connect methods returns after the 5 sec timeout and if it is not connecting a static IP won't help :/

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

                        @poebler said in No Wifi connection on boot:

                        if it is not connecting a static IP won't help

                        Sometimes it help ;-)

                        think about people first, then computers

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

                          @livius tried it. no success :(

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            markN @poebler
                            last edited by

                            @poebler said in No Wifi connection on boot:
                            I had a similar problem connecting to my home wifi network using the standard wifi code example.
                            After some experimentation I found that a short wait immediately after the line containing "wlan.connect(...)" cured the issue in my code. I assume this may be a bug, possibly some kind of internal race condition between wlan.connect() and wlan.isconnected().
                            If its the same problem this extra line in your code might help.

                                        wl.connect(ssid, (sec, known_nets[ssid]), timeout=5000)
                                        time.sleep(1)
                            
                            P 1 Reply Last reply Reply Quote 0
                            • P Offline
                              poebler @markN
                              last edited by

                              @markN Hi, Thanks for your help! I tried it - but again with no success!

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

                                @poebler
                                one more question. Where you put this code? In boot.py?
                                If yest - move it to main.py and back withresults.

                                think about people first, then computers

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

                                  @livius First i tried it in boot.py - then i moved it to main.py. Both with no success. Then i had an idea. I'm using a FritzBox with Wifi on 2.4 and 5 GHz with the same ssid. I think this is the root cause. I enabled the guest AP and tried to connect to this - and this is working. So at least i have workaround for me! But anyway , thanks a lot for your help!

                                  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