Skip to content

Instantly share code, notes, and snippets.

@anecdata
Created September 29, 2022 00:24
Show Gist options
  • Save anecdata/466fae65a6bbb2394a6043b2a959c15c to your computer and use it in GitHub Desktop.
Save anecdata/466fae65a6bbb2394a6043b2a959c15c to your computer and use it in GitHub Desktop.
Raspberry Pi Pico W MicroPython requests code for uP issue #9455
import time
import machine
import network
import urequests as requests
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("ssid", "passw0rd")
while not wlan.isconnected() and wlan.status() >= 0:
print(f"Connected? {wlan.isconnected()} Status? {wlan.status()}")
time.sleep(1)
print(wlan.ifconfig()[0])
# increase delay between requests each time
interval_sec = 0
increment_sec = 60
timer_sec = time.time() - interval_sec
while True:
if time.time() - timer_sec > interval_sec:
try:
r = requests.get(TEXT_URL)
print(f"{interval_sec:>5} {r.status_code} {r.reason.decode()} {r.content}")
r.close()
interval_sec += increment_sec
except OSError as e:
print(e)
machine.reset()
timer_sec = time.time()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment