Common use cases
- Connect to MQTT servers to send sensor data
- Query web services over HTTP, HTTPS, and web sockets
- Run an HTTP server inside the ESP32 and connect to it from your browser (requires the Wokwi IoT Gateway)
Connecting to the WiFi
The simulator provides a virtual WiFi access point called Wokwi-GUEST. It is an open access point - no password is required.Connecting from Arduino
To connect from Arduino (on an ESP32) device, use the following code:Connecting from MicroPython
To connect from a MicroPython project, use the following code:Once connected, you can use the urequests library to send HTTP and HTTPS requests, and the umqtt library to establish MQTT connections.
Connecting from Rust (std)
To connect from Rust with esp-idf-svc (on an ESP32) device, use the following code:You need to specify the auth_method to
None in the ClientConfiguration.Internet Access
Wokwi uses a special gateway to connect your simulated ESP32 to the internet. This gateway is required since web browsers do not allow direct internet access. There are two ways you can use the Wokwi IoT Gateway: the Public Gateway, and the Private Gateway.| Public Gateway | Private Gateway | |
|---|---|---|
| Speed | Slower | Faster |
| Stability | Medium | High |
| Location | Remote, in the cloud | Runs on your computer |
| Privacy | Connections monitored | No monitoring |
| Outgoing connections | ✅ | ✅ |
| Incoming connections | ❌ | ✅ |
| Availability | All users | Paying users |
The Public Gateway
The Public Gateway is the default internet connection method. It works out of the box and enables access to the internet, but not to your local network. All the traffic is monitored for security purposes, so do not use it for private or sensitive data. We occasionally inspect the traffic and may enforce limits if we notice excessive usage of the gateway.The Public Gateway is a great choice for playing around and learning about WiFi and networking in the ESP32.
The Private Gateway
The Private Gateway is a small application that you download and run on your computer. It allows faster and more robust ESP32 internet access: the data goes directly from the simulator (running in your browser) to you computer’s network, without having to go through the cloud. Benefits:- There’s no monitoring. Your traffic stays private.
- Your ESP32 projects can access services running on your computer or your local network (e.g. a local MQTT or HTTP server)
- You can run a web server on the ESP32 and connect to it from your browser
Installation
Download
Download the latest version from the Wokwi IoT Gateway releases page. Versions are available for Windows, macOS, and Linux.
Extract and run
Extract the ZIP file and run the executable file inside. Your browser / operating system may warn you that the file may be unsafe, so you’ll have to tell them to run it anyway.
The gateway does not require any administrator / root permissions. It happily runs as a standard process on your computer.
Usage
Enable Private Gateway
After running the gateway, open any project in Wokwi, go to the code editor, press “F1” and select “Enable Private Wokwi IoT Gateway”. You’ll be prompted if you want to enable the gateway. Answer “OK” to enable the Private Gateway, or “Cancel” to disable it and switch back to the Public Gateway.
Run ESP32 project
Run any ESP32 project that uses the WiFi. Look at the gateway output, it should say “Client connected”. This means you are using the Private Gateway.
Connect to HTTP server (optional)
If your ESP32 project is an HTTP server, you can connect to it from your browser at http://localhost:9080/. The connection will be forwarded by the gateway to the default HTTP port (80) on the simulated ESP32.
Connecting to your local machine
To connect to your local machine (“localhost”) from the code running in the simulator, use the hostnamehost.wokwi.internal. For example, if you are running an HTTP server on port 1234 on your computer, you can connect to it from within the simulator using the URL http://host.wokwi.internal:1234/.
Advanced Usage
Network addresses
The ESP32 gets an IP address from a DHCP server running inside the Wokwi IoT gateway. The IP address depends on the type of the gateway that you use:- Public Gateway: 10.10.0.2
- Private Gateway: 10.13.37.2
Viewing WiFi traffic with Wireshark
Wokwi simulates a complete network stack: starting at the lowest 802.11 MAC Layer, through the IP and TCP/UDP layers, all the way up to protocols such as DNS, HTTP, MQTT, CoAP, etc. You can view the raw WiFi traffic using a network protocol analyzer such as Wireshark.Download PCAP
Click on the WiFi icon, and choose Download PCAP file. Your browser will download a file called wokwi.pcap.
As you can see, the PCAP file contains all sort of packets: 802.11 beacon frames, DNS query response (the first entry in the list), and HTTP request/response packets (No. 107 and 113).
Limitations
The Wokwi IoT Gateway supports both TCP and UDP. It does not support the ICMP protocol, so the Ping functionality is not available.Project Examples
NTP Client
Get current date and time from an NTP server
MicroPython MQTT Weather Logger
Report temperature changes to an MQTT server
ESP32 HTTP Server
Serve a web page that controls 2 LEDs (requires Private Gateway)