LoPy4 boot.py Wifi
-
Hi all
I am newI like to have script in boot.py in Lopy4 for Wifi. So I have connection all time with devices. No mater waht happed to main.py code to have access to change it.
Also I need to use external Antenna for wifi (alredy connected), so in script I like to specific antenna=WLAN.EXT_ANT and mode to be STEMy wifi Network is secure auth=WPA2, and I like dhcp to assigne IP to LoPY4 (I configure MAC IP reservation on router, so same IP is given to module)
Help. I need example of this script ?
-
@nemke-petrovic The break statement in the last line is wrong. That way, the code will not wait for a connection. And also, the antenna is internal.
-
import machine import time from network import WLAN wlan = WLAN() # get current object, without changing the mode if machine.reset_cause() != machine.SOFT_RESET: wlan.init(mode=WLAN.STA) # configuration below MUST match your home router settings!! if not wlan.isconnected(): # change the line below to match your network ssid, security and password wlan.connect('IoT Network', auth=(WLAN.WPA2, '19Akacki_Ryu86'), timeout=5000) while not wlan.isconnected(): machine.idle() # save power while waiting break
Interesting, it doesn't work. I write new using examples from pycom documenty, end this is work.
LoPy4 ver 1.20.2.rc6Many thanks for reply
-
@nemke-petrovic You could try that one, which is except for the antenna switch the one I am using:
def do_connect(): import network import time wlan = network.WLAN(mode=network.WLAN.STA) # create station interface wlan.antenna(WLAN.EXT_ANT) if not wlan.isconnected(): # check if the station is connected to an AP wlan.connect(ssid=WIFI_SSID, auth=(network.WLAN.WPA2, WIFI_PASSWD)) for _ in range(100): if wlan.isconnected(): # check if the station is connected to an AP break print('.', end='') time.sleep_ms(200) else: print("Connect attempt timed out\n") return print('\nnetwork config:', wlan.ifconfig()) do_connect()
WIFI_SSID and WIFI_PASSWD have to be set accordingly.
-
Yes, of course. But didn't manage to work.
So, i write here maybe someone have working script
-
@nemke-petrovic you can put any code into boot.py. Did you have a look at the examples in the documentation? E.g. https://docs.pycom.io/tutorials/all/wlan/