Quick Start · MQTT · ~10 minutes

Your first live dashboard — MQTT

Connect an ESP8266 or ESP32 to the Virtuino Cloud MQTT broker, publish a sensor value and watch it update live — then build a dashboard and add an automation rule.

Create free account Jump to the code

Create your account & sign in

Register for a free account and log in to the console.

Get your MQTT credentials

From the console copy your MQTT username (your account short_id, e.g. vr_ab12cd34) and your MQTT password. You'll use them in the sketch.

Create a device & fields

Add a device (e.g. ESP32) and its fields (e.g. temperature) from the console. The device and field names must match exactly the topic in your code.

Devices  ·  Fields

Flash your ESP8266 / ESP32

Install the PubSubClient library (by Nick O'Leary) in the Arduino IDE. Paste the sketch for your board, fill in your WiFi + MQTT credentials, then upload. It publishes a demo temperature value every 10 seconds.

Broker: cloud.virtuino.com : 8883 (TLS)  ·  Topic: <short_id>/in/device/<deviceName>/<fieldName>  ·  Payload: the value as text (e.g. "25.4")
#include <ESP8266WiFi.h>
#include <WiFiClientSecureBearSSL.h>
#include <PubSubClient.h>          // install "PubSubClient" by Nick O'Leary

const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";

const char* MQTT_HOST = "cloud.virtuino.com";
const int   MQTT_PORT = 8883;                       // TLS
const char* SHORT_ID  = "YOUR_SHORT_ID";            // MQTT username (Console)
const char* MQTT_PASS = "YOUR_MQTT_PASSWORD";       // MQTT password (Console)
const char* DEVICE    = "ESP32";                    // must match the device in the console
const char* FIELD     = "temperature";              // must match the field

BearSSL::WiFiClientSecure net;
PubSubClient mqtt(net);

void connectMqtt() {
  while (!mqtt.connected()) {
    String cid = "esp8266-" + String(random(0xffff), HEX);
    if (mqtt.connect(cid.c_str(), SHORT_ID, MQTT_PASS)) Serial.println("MQTT connected");
    else { Serial.printf("MQTT failed rc=%d, retrying...\n", mqtt.state()); delay(2000); }
  }
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
  Serial.println("\nWiFi connected");
  net.setInsecure();                                // skip TLS cert check (simple)
  mqtt.setServer(MQTT_HOST, MQTT_PORT);
}

void loop() {
  if (!mqtt.connected()) connectMqtt();
  mqtt.loop();

  float temperature = 20.0 + random(0, 100) / 10.0;             // demo value
  String topic = String(SHORT_ID) + "/in/device/" + DEVICE + "/" + FIELD;
  mqtt.publish(topic.c_str(), String(temperature).c_str());
  Serial.println("published " + String(temperature) + " -> " + topic);

  delay(10000);                                                 // every 10 seconds
}
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>          // install "PubSubClient" by Nick O'Leary

const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";

const char* MQTT_HOST = "cloud.virtuino.com";
const int   MQTT_PORT = 8883;                       // TLS
const char* SHORT_ID  = "YOUR_SHORT_ID";            // MQTT username (Console)
const char* MQTT_PASS = "YOUR_MQTT_PASSWORD";       // MQTT password (Console)
const char* DEVICE    = "ESP32";                    // must match the device in the console
const char* FIELD     = "temperature";              // must match the field

WiFiClientSecure net;
PubSubClient mqtt(net);

void connectMqtt() {
  while (!mqtt.connected()) {
    String cid = "esp32-" + String(random(0xffff), HEX);
    if (mqtt.connect(cid.c_str(), SHORT_ID, MQTT_PASS)) Serial.println("MQTT connected");
    else { Serial.printf("MQTT failed rc=%d, retrying...\n", mqtt.state()); delay(2000); }
  }
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
  Serial.println("\nWiFi connected");
  net.setInsecure();                                // skip TLS cert check (simple)
  mqtt.setServer(MQTT_HOST, MQTT_PORT);
}

void loop() {
  if (!mqtt.connected()) connectMqtt();
  mqtt.loop();

  float temperature = 20.0 + (millis() % 100) / 10.0;          // demo value
  String topic = String(SHORT_ID) + "/in/device/" + DEVICE + "/" + FIELD;
  mqtt.publish(topic.c_str(), String(temperature).c_str());
  Serial.println("published " + String(temperature) + " -> " + topic);

  delay(10000);                                                 // every 10 seconds
}
Prefer simple HTTP instead of MQTT? Follow the HTTP getting-started guide.

Run it & check the console

Open the Serial Monitor (115200 baud) — you should see MQTT connected and the published values. Then open the Data Monitor to see them arriving live.

Build your dashboard

Create a dashboard, add a widget (gauge, chart, value display…) and bind it to your temperature field. Your live data appears instantly.

Add a rule (automation)

Make it smart: add a rule such as "if temperature > 30 °C, send me an email" — or trigger another device, run a schedule, or execute a script.

Start now — it's free