A web page cannot open the TCP connections and UDP packets a real ESP32 uses. The simulator therefore takes two paths: MQTT over WebSocket straight from your browser, and HTTP through the simulator server.
MQTT
When the sketch calls mqtt.connect() for a broker such as iot.reslab-csub.cloud port 1883 or 8883, the
simulator opens a WebSocket connection to that broker instead (for IoT Platform: wss://…/mqtt). For the sketch nothing
changes: the same host name, port, username, topics and Last Will, and the same result codes (state()).
- Only brokers with a WebSocket address can be reached. IoT Platform's broker is set up already.
- For any other broker, add its WebSocket address in ⚙ Settings (see below). Public brokers with WebSocket
support work, for example
broker.emqx.io = wss://broker.emqx.io:8084/mqtt. - As on a real board,
PubSubClientpublishes at QoS 0 and drops messages larger than its buffer (256 bytes by default,setBufferSize()to change it), with a warning in the serial monitor.
Network settings
⚙ Settings has:
- the broker map: one line per broker,
host = urlorhost:port = url, e.g.mybroker.example.com = wss://mybroker.example.com:8084/mqtt. A broker named in the sketch is reached at that URL; - the hosts HTTP requests may go to (set on the server);
- the MAC address of the simulated board (
WiFi.macAddress()). Devices of IoT Platform set it for you.
The settings are kept in this browser.
HTTP
HTTPClient requests are sent to the simulator server, which makes them for the board and passes the answer back.
To keep the server from being misused, there are limits:
| Limit | On this server |
|---|---|
| Hosts allowed | iot.reslab-csub.cloud |
| Requests | at most 30 per minute |
| Size of a request body | 768 KB (enough for a camera picture) |
| Size of an answer | 64 KB; longer answers are cut |
| Redirects | not followed: the sketch gets the 301 / 302, like a real HTTPClient |
A request to another host fails with a negative code and a message in the network log. https:// works; the server
checks the certificate.
The network log
The Network tab next to the serial monitor shows the board's traffic as it happens: Wi-Fi, MQTT connect and disconnect with the reason, subscriptions, every message published and received (topic and payload), and HTTP requests with their status. Use it to see whether a message left the board, and what came back.