Skip to content

Instantly share code, notes, and snippets.

@agentzex
Created December 13, 2019 15:18
Show Gist options
  • Save agentzex/a981acc8a88975cecac0587d206f42ca to your computer and use it in GitHub Desktop.
Save agentzex/a981acc8a88975cecac0587d206f42ca to your computer and use it in GitHub Desktop.
import urllib.urequest
import time
import network
time.sleep(3)
print("\n\n\n***********\n")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if wlan.isconnected():
print("wlan connected at startup")
else:
print("wlan not connected, trying to connect")
wlan.connect("mywifi", "mypassword")
retries = 0
while not wlan.isconnected():
retries = retries + 1
if retries < 10000:
print("cant connect to wifi")
machine.idle()
else:
break
print("Connected after " + str(retries) + " tries")
ret = urllib.urequest.urlopen("http://192.168.1.100/hello")
time.sleep(3)
ret = urllib.urequest.urlopen("http://192.168.1.100/hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment