Generic Card
Display a numeric or text value with an optional symbol using dash::GenericCard.
The generic card displays a single value of any supported type together with an optional symbol or unit. Use it for counters, status strings and other values that no dedicated card covers.

Constructor
dash::GenericCard<T, Precision> card(dashboard, name, symbol);Prop
Type
Template parameters:
Prop
Type
dash::GenericCard<int> restarts(dashboard, "Restarts", "times");
dash::GenericCard<float, 3> energy(dashboard, "Energy", "kWh");
dash::GenericCard status(dashboard, "Status"); // dash::stringAn overload without the dashboard argument creates the card without attaching it to a dashboard; attach it later with dashboard.add(card).
Methods
setValue()
bool setValue(const T& value);Sets the displayed value. Returns true if the value changed and an update is pending, false if the new value equals the current one.
value()
const T& value() const;Returns the current value. Call it only when hasValue() returns true.
hasValue()
bool hasValue() const;Returns true if a value has been set.
removeValue()
bool removeValue();Clears the value. The dashboard then shows 0 for numeric types or an empty string for text types. Returns true if a value was removed.
setSymbol()
bool setSymbol(const char* symbol);Sets the symbol or unit displayed next to the value. Returns true if the symbol changed.
symbol()
const char* symbol() const;Returns the current symbol.
Example
#include <Arduino.h>
#include <WiFi.h> // ESP32; use the networking headers for your board
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESPDash.h>
AsyncWebServer server(80);
ESPDash dashboard(server);
dash::GenericCard<int> counter(dashboard, "Counter", "events");
int events = 0;
void setup() {
// ... connect to Wi-Fi
server.begin();
}
void loop() {
counter.setValue(++events);
dashboard.sendUpdates();
delay(3000);
}Notes
- The card stores the
symbolpointer and does not copy the string. Pass a string literal or a buffer that outlives the card. dash::stringis ArduinoStringby default, orstd::stringwhenDASH_USE_STL_STRINGis defined.
