Anniversary Sale · up to 80% off all librariesEnds Nov 9Shop now
SOFTTDocs
Cards

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.

Generic card

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::string

An 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

main.cpp
#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 symbol pointer and does not copy the string. Pass a string literal or a buffer that outlives the card.
  • dash::string is Arduino String by default, or std::string when DASH_USE_STL_STRING is defined.

On this page