Built-in project · ESP32 DevKit V1

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.

MicroPython WiFi weather on an ESP32 · ESP32 DevKit V1live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

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.

main.py · ESP32 DevKit V1
# 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.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.