ClavdaClavda

Build a live ESP32 dashboard with gauges, charts and controls

Lay out cards, charts, toggles and sliders for an ESP32 in the Clavda console, then feed them from your sketch with ClavdaWidget. No server or MQTT broker to run.

Updated 2 min read

A Clavda dashboard is a live page of cards, gauges, charts and controls for one board. You build it in the console, and the sketch gives it its values and reacts to its controls. There is no web server on the board and no broker to run: the values travel over the same connection the ClavdaOTA library already keeps open.

Every widget has an ID. A ClavdaWidget in the sketch with the same ID gives that widget its values, or runs your code when someone uses it.

What you need

Build the dashboard in the console

Open the editor

Open the device's Connect sheet, press Dashboard, and switch on Edit.

Add widgets

Drag cards, charts and controls onto the grid, or click them in the list.

Set each widget up

Select a widget to set its title, size and units. Its Widget ID is the name the sketch uses, and the line to paste into the sketch is under Firmware.

Save

Press Save. Firmware code gives you a starting sketch for the whole dashboard.

Feed it from the sketch

Declare one ClavdaWidget per widget, by its ID. Display cards and charts get their values from set() and add(), and controls run the code you give onChange().

This sketch fits a dashboard with a temperature card, a line chart, a status card, a toggle and a slider that drive an LED:

Dashboard sketch
#include <Arduino.h>
#include <WiFi.h>

// Your firmware version. Change it for every build you upload: the
// console counts an update done once the board reports it.
#define CLAVDA_FIRMWARE_VERSION "1.0.0"

// The library, then this board's credentials from the console.
#include <ClavdaOTA.h>
#include "clavda_device.h"

const char *ssid = "your-wifi";
const char *password = "your-wifi-password";

const int LED_PIN = 2;

// One ClavdaWidget per widget on the dashboard. The text in quotes is the
// widget's ID: copy it from the widget's settings in the console.
ClavdaWidget temperature("temperature");  // Value or Gauge card
ClavdaWidget history("temp_history");     // Line chart
ClavdaWidget status("status");            // Status card
ClavdaWidget led("led");                  // Toggle
ClavdaWidget brightness("brightness");    // Slider, 0 to 255

bool ledOn = false;
int ledLevel = 128;
unsigned long lastSample = 0;

void showLed() {
  analogWrite(LED_PIN, ledOn ? ledLevel : 0);
}

void setup() {
  Serial.begin(115200);

  // Controls: these run when someone uses the toggle or slider.
  led.onChange([](const ClavdaInput &in) {
    ledOn = in.asBool();
    showLed();
    if (ledOn) status.set("LED on", CLAVDA_SUCCESS);
    else status.set("LED off", CLAVDA_INFO);
  });
  brightness.onChange([](const ClavdaInput &in) {
    ledLevel = in.asInt();
    showLed();
  });

  // Starting values, so a dashboard opened now has something to show.
  led.set(ledOn);
  brightness.set(ledLevel);
  status.set("Starting", CLAVDA_INFO);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  ClavdaOTA.begin(CLAVDA_DEVICE);
}

void loop() {
  ClavdaOTA.loop();

  // Display: a reading every 2 s. set() only sends when it changes.
  if (millis() - lastSample >= 2000) {
    lastSample = millis();
    float celsius = temperatureRead();  // the chip's own sensor
    temperature.set(celsius);
    history.add(celsius);               // the console adds the time
  }
}

Widget reference

WidgetIn the sketch
Value, Gaugew.set(23.4): a number, or text for a Value card
Statusw.set("Door open", CLAVDA_WARNING), also CLAVDA_INFO, CLAVDA_SUCCESS, CLAVDA_DANGER
Line chartw.add(23.4): one point; the console adds the time
Bar chartw.setSeries(labels, values, count)
Toggle, Slider, Button, Text inputw.onChange(...), reading in.asBool(), in.asInt(), in.asFloat() or in.asText()
Device metricNothing: free heap, Wi-Fi signal and uptime come from the heartbeat

Tips

  • Only the ID has to match. The text in quotes must match the dashboard; the variable name is yours.
  • Avoid short generic variable names. The ESP32 Wi-Fi library has globals of its own, and ClavdaWidget bars("bars") fails to link with multiple definition of bars. barChart works. The console's snippets end every name in Widget for that reason.
  • set() is cheap. It only sends a value when it changes, so calling it on every loop costs nothing extra.
  • Flashed the sketch first? In edit mode, From the device lists the IDs the board sends that the dashboard does not show yet, ready to add in one click.
  • Controls are protected. Values and controls are end-to-end encrypted. Using a control needs permission to edit devices, and the board itself checks it.

Next steps