No Wifi connection on boot
-
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! -
@poebler
You loop throught all networks in range
but you pass parameter only for known networkwl.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 -
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!
-
@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() -
@livius 1.7.3.b2
-
@poebler
what happened if you change this line
wl.connect(ssid, (sec, known_nets[ssid]), timeout=5000)towl.connect(ssid=ssid, auth=(sec, known_nets[ssid]), timeout=5000)?
-
@livius tried this also - no change :/
-
@poebler
what if you add debug infoprint(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?
-
@livius I'm at work so i can try it first this evening. But the
connectmethods returns after the 5 sec timeout and if it is not connecting a static IP won't help :/ -
@poebler said in No Wifi connection on boot:
if it is not connecting a static IP won't help
Sometimes it help ;-)
-
@livius tried it. no success :(
-
@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) -
@markN Hi, Thanks for your help! I tried it - but again with no success!
-
@poebler
one more question. Where you put this code? Inboot.py?
If yest - move it tomain.pyand back withresults. -
@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!
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