MicroPython WiFi weather on an ESP32
MicroPython on an ESP32 DevKit: network.WLAN joins the simulated access point and urequests fetches the weather from http://weather.mokxi/ every ten seconds. The whole build, an ESP32 DevKit, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate Runs in your browser. Free, and no account needed.
The parts retail for about $9. On Mokxi they're free.
The code
The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.
# MicroPython on an ESP32 DevKit: join WiFi and fetch the weather.
# The board joins Mokxi's simulated access point; its name and password are
# the board's WiFi properties. On a real board, put in your own network's.
import network
import time
import urequests
SSID = "Mokxi-Lab"
PASSWORD = "breadboard"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
print("Connecting to", SSID)
while not wlan.isconnected():
time.sleep_ms(250)
print("Connected, IP address", wlan.ifconfig()[0])
while True:
r = urequests.get("http://weather.mokxi/")
weather = r.json()
r.close()
print("%s: %.1f C, %d %% humidity" % (weather["location"], weather["temperatureC"], weather["humidity"]))
time.sleep(10)
Parts list
1 part, plus the jumper wires. They retail for about $9; on Mokxi they're free.
- 1 × ESP32 DevKit V1
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.