Docs

Gauge

The Gauge widget displays a value your board sends. It is the first widget that works the other way round: the board talks, the app listens.

Use it for a temperature, a humidity level, a battery voltage, a tank level, or any reading you want to see at a glance.

Temperature V2 = 23.5

The needle position comes from the value on V2 and the minimum and maximum you set in the app.

Example

This example reads a sensor on GPIO 34 and sends a value to a Gauge on V2 every two seconds.

gauge.ino
#include <PlynxSimpleEsp32.h>

#define SENSOR_PIN 34                 // any ADC1 pin works while WiFi is on

PlynxTimer timer;

void sendReading()
{
  int raw = analogRead(SENSOR_PIN);   // 0 to 4095 on the ESP32
  float celsius = raw * (3.3 / 4095.0) * 100.0;

  Plynx.virtualWrite(V2, celsius);
}

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

  // Auto setup: WiFi and the Plynx token are configured from the app.
  //
  // To provide them directly in the sketch instead, use:
  //   Plynx.begin(auth, ssid, pass);
  Plynx.begin();

  timer.setInterval(2000L, sendReading);
}

void loop()
{
  Plynx.run();
  timer.run();
}

Plynx.virtualWrite(V2, value) is the whole mechanism. Nothing is sent unless your code sends it, so a Gauge with no virtualWrite() behind it stays empty.

timer.run() must be in loop() next to Plynx.run(), otherwise the timer never fires.

The conversion above is for a linear sensor such as a TMP36. Replace it with whatever your sensor needs; the part that matters for the widget is the virtualWrite().

Do not use delay()

A Gauge invites you to write delay(2000) in loop(). Do not. While the board is inside delay(), Plynx.run() is not running, so the connection stops being served and the board drops offline.

PlynxTimer exists for this. It checks the clock and calls your function when it is due, without ever blocking.

Keep the rate reasonable. Ten values per second is the practical ceiling, and for a temperature every few seconds is plenty.

Set the range in the app

The Gauge needs a minimum and a maximum to know where the needle sits. They live in the widget settings, not in the sketch.

A reading outside that range is clamped to the ends, so a gauge stuck at full scale usually means the range is too narrow rather than the sensor being wrong.

Send only when it is worth it

If the value barely moves, sending it anyway costs battery and bandwidth. Send when it changed enough to matter:

Send on meaningful change
float lastSent = -999;

void sendReading()
{
  float celsius = readSensor();

  if (abs(celsius - lastSent) >= 0.2) {
    Plynx.virtualWrite(V2, celsius);
    lastSent = celsius;
  }
}

Troubleshooting

ProblemCheck
Gauge stays emptynothing is calling virtualWrite() on that pin, or the pin does not match
Board goes offline every few secondsdelay() in loop(); use PlynxTimer instead
Values never updatetimer.run() is missing from loop()
Needle pinned at one endthe range in the widget settings does not fit the values you send
Readings jump around on WiFiADC2 pins do not work while WiFi is on; use an ADC1 pin such as GPIO 32 to 39

Next