MicroPython WiFi access point mode on an ESP32, on an ESP32-DevKitC V4
MicroPython on an ESP32: network.WLAN(AP_IF) starts a hotspot of the board’s own and prints its name and its IP settings. The whole build, an ESP32-DevKitC V4, 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.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $10. On Mokxi they're free.
What you'll learn
- Access point mode versus station mode
- Setting a WiFi name and password with ap.config
- Reading the network settings with ifconfig
- Using the network module in MicroPython
- Difficulty: Beginner
- Time: About 10 minutes
- Board: ESP32-DevKitC V4
- Parts: 1
How it works
Access point mode means the board makes a WiFi network of its own instead of joining one. The script creates it with network.WLAN(network.AP_IF), turns it on, and sets the name ESP32-Hotspot with the password 12345678 and WPA/WPA2 security.
It then prints the network name and its settings, including the IP address. Every 10 seconds it prints whether the hotspot is still up. In Mokxi the hotspot starts, but no phone or laptop can join it.
Parts list
1 part, plus the jumper wires. They retail for about $10; on Mokxi they're free.
- 1 × ESP32-DevKitC V4
Kits that can build it
These 3 starter kits have every part in the circuit. Each kit's page lists what else it can build.
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.
# AP mode: the ESP32 starts a WiFi network of its own and prints its
# settings. In Mokxi the hotspot starts, but no phone or laptop can join it.
import network
import time
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid="ESP32-Hotspot", password="12345678", authmode=network.AUTH_WPA_WPA2_PSK)
print("Hotspot:", ap.config("essid"))
print("Settings:", ap.ifconfig())
while True:
time.sleep(10)
print("hotspot up:", ap.active())
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The hotspot does not show up on your phone This project
In Mokxi nothing outside the simulator can join it. On a real board, the password must be at least 8 characters. - The board is not found, or upload fails with a connecting message. ESP32-DevKitC V4
Use a USB cable that carries data, not charge only. Pick the ESP32 Dev Module board. If it still fails, hold BOOT while uploading starts, then release. - Some pins never read right, or the board will not boot with a wire attached. ESP32-DevKitC V4
GPIO34 to 39 are input only and have no pull-ups. GPIO6 to 11 run the flash, so leave them alone. GPIO0, 2 and 12 are boot pins; avoid pulling them the wrong way at reset.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.