Skip to content

Instantly share code, notes, and snippets.

@qbalsdon
Created August 30, 2024 10:59
Show Gist options
  • Save qbalsdon/942c304eef5988cad3723f25d710d209 to your computer and use it in GitHub Desktop.
Save qbalsdon/942c304eef5988cad3723f25d710d209 to your computer and use it in GitHub Desktop.
# Useful links
# https://randomnerdtutorials.com/raspberry-pi-pico-w-http-requests-micropython/
URL="..."
import json
import network
import requests
# contents of cred.json (on Pico file system, where main.py is)
# {
# "ssid": "WIFI NAME",
# "pass": "WIFI PASSWORD"
# }
# Wi-Fi credentials
wifi_info = open('cred.json')
credentials = json.loads(wifi_info.read())
# Connect to network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Connect to your network
wlan.connect(credentials["ssid"], credentials["pass"])
# Make GET request
response = requests.get(URL)
# Get response code
response_code = response.status_code
# Get response content
response_content = response.content
# Print results
print('Response code: ', response_code)
print('Response content:', response_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment