MCU Simulator Robotic and Embedded System Laboratory
โ† Open the simulator
Documentation

Connecting to IoT Platform

Using your IoT Platform devices: firmware templates, filling in tokens, topics, commands and camera pictures.

A simulated board talks to IoT Platform exactly like a real ESP32: over MQTT (telemetry, desired state, commands, status, firmware report, rule JSON) and HTTP (telemetry, camera pictures). Everything you see on the platform (dashboards, charts, rules, alarms) works with it.

Your devices

Signed in, the top bar has ๐Ÿ“Ÿ Devices. It lists your IoT Platform devices and the devices shared with you, with a dot showing whether each is online. For each device there are three buttons:

ButtonWhat it does
Open templateOpens the platform's firmware template for the device, with the server, broker, topic prefix and access token already filled in, on the matching board: ESP32-CAM devices get the camera template, ESP32-C3 OLED devices the OLED template, the others the ESP32 MQTT template. ESP8266 devices get the simulator's NodeMCU sketch with a DHT11 and an LED. It replaces the sketch and parts (you are asked first).
Template + variablesThe same template, plus a part and its code for every variable of the device that the template does not handle yet: a temperature and humidity variable gets a DHT22, lux a BH1750, a distance in cm an HC-SR04, a pump or fan a relay, an angle a servo, and so on. Variables it cannot guess become a potentiometer. The added code is marked // ---- added by MCU Simulator for the device variables. Needs a device with variables.
Token onlyKeeps your sketch and writes the device's token, topic prefix and broker into its constants (TOKEN, TOPIC_PREFIX, MQTT_HOST, MQTT_PORT, USE_TLS, SERVER); a sketch without them gets the token copied to the clipboard. The board follows the device's board type.

All three also use the device's MAC address for the simulated board. A device you can only view has no token for you: ask its owner to make you an editor.

The first time, IoT Platform asks you to allow the simulator to read your devices. If you signed in before that, the list shows Allow on IoT Platform: you stay signed in and are asked once.

Your first device on the platform

  1. On IoT Platform, create a device and give it a variable or two (for example temperature ยฐC and lamp).
  2. In the simulator, ๐Ÿ“Ÿ Devices โ†’ Template + variables next to the device.
  3. Press โ–ถ Run. The serial monitor shows Wi-Fi and MQTT connecting, the MQTT chip turns green, and the device becomes online on the platform.
  4. Move the temperature slider of the added sensor: the new value appears on the platform's dashboard. Switch lamp on the platform: the LED lights up in the simulator.

Topics and messages

The templates use the platform's MQTT topics, all under <prefix>/<token>/:

TopicDirectionMeaning
telemetryboard โ†’ platformmeasured values, JSON such as {"temperature": 24.5}
desiredplatform โ†’ board (retained)the state the board should have, e.g. {"lamp": 1}
commands/<id>, commands/<id>/responsebotha command and the board's answer; a command past its expires_at is not carried out
statusboard โ†’ platform (retained)online, and offline as Last Will when the board goes away
firmwareboard โ†’ platformfirmware name and version, board, MAC address
rules/<id>, rules/<id>/ackbothrule JSON published from the platform, and the board's receipt
errorsplatform โ†’ boardwhat the platform could not accept

On the platform's broker the username and password are the device's access token, and the topics must contain it: a wrong token gives state 5 (not authorised), as on a real board.

Camera pictures (ESP32-CAM)

With an ESP32-CAM device, Open template gives the platform's camera template on the ESP32-CAM board. The Capture now button on the platform sends the capture command: the board takes a picture (test pattern or your camera), uploads it to /api/v1/<token>/snapshot and answers with the picture's id. The flash, frame size, quality and snapshot interval can be set from the platform.

HTTP instead of MQTT

Example iot_platform_http.ino sends telemetry with HTTPClient to /api/v1/<token>/telemetry. HTTP requests go through the simulator server, see Network.

What differs from a real board

  • Firmware updates (OTA) are refused: the template reports the update as FAILED with OTA is not supported in the simulator.
  • CoAP is not available (a browser cannot send UDP); use MQTT or HTTP.
  • HTTP requests reach the platform from the simulator server's address, not from your computer.