Code: Select all
import network
import machine
def connect():
count = 0
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('trying to connect to hotspot...')
sta_if.active(True)
# sta_if.ifconfig(('192.168.10.99', '255.255.255.0', '192.168.10.1', '8.8.8.8'))
sta_if.connect('TP-LINK_4A88F3', 'xyz')
while (count < 5):
utime.sleep(5)
count += 1
if sta_if.isconnected():
print('connected to the hotspot')
count = 0
break
else:
print('not connected to the hotspot')
while not sta_if.isconnected():
machine.reset()
A frustration was that every so often a new IP would be assigned to the device by the hotspot ... which made using WebREPL hit and miss. A static IP sorts that.