Skip to content

Instantly share code, notes, and snippets.

@anecdata
Created September 29, 2022 00:23
Show Gist options
  • Save anecdata/3022ae221a6a78fd6c53d680f065b6c5 to your computer and use it in GitHub Desktop.
Save anecdata/3022ae221a6a78fd6c53d680f065b6c5 to your computer and use it in GitHub Desktop.
Raspberry Pi Pico W CircuitPython requests code for CP issue #6958
import time
import supervisor
import microcontroller
import wifi
import socketpool
import adafruit_requests
from secrets import secrets
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool)
while not wifi.radio.ipv4_address or "0.0.0.0" in repr(wifi.radio.ipv4_address):
print(f"Connected?")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print(f"{wifi.radio.ipv4_address}")
# 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)
# supervisor.reload() # not enough, must teset
microcontroller.reset()
timer_sec= time.time()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment