# boot.py -- run on boot-up from network import WLAN import pycom import os from machine import UART import time known_nets = { # SSID : PSK (passphrase) 'ONOF5AC1':'2445418455', './mobile':'EverIsBeauty69', './home':'~/Crypt3dH0m3/~', 'WLAN_D096':'(CasaBarcelona6969)', 'JESUITESFP':'d7c48i52', 'JESUITES_FP':'d7c48i52', 'IoT-eCat':'clotClot' } # change this dict to match your WiFi settings uart = UART(0, 115200) os.dupterm(uart) pycom.heartbeat(False) pycom.rgbled(0x050000) wl = WLAN() # save the default ssid and auth original_ssid = wl.ssid() original_auth = wl.auth() # test needed to avoid losing connection after a soft reboot connected = False wl.mode(WLAN.STA) for ssid, bssid, sec, channel, rssi in wl.scan(): # Note: could choose priority by rssi if desired try: wl.connect(ssid, (sec, known_nets[ssid]), timeout=10000) connected = True break except KeyError: pass # unknown SSID else: wl.init(mode=WLAN.AP, ssid='pvSL4', auth=(WLAN.WPA2,'fanalBolet0'), channel=6, antenna=WLAN.INT_ANT) pycom.rgbled(0x050005) print('lopy-wlan-bda6') if connected: while not wl.isconnected(): print('.', end="") pycom.rgbled(0x000500) time.sleep_ms(150) pycom.rgbled(0x050000) print("Connexio WiFi establerta: ") pycom.rgbled(0x000500) print(wl.ifconfig()) time.sleep(3)