Skip to main content

Virtual Pins Reference

Virtual pins (V0V255) are the data channels between your firmware and your dashboard widgets.


Sending data to the dashboard

Call virtualSend inside your loop() at whatever interval makes sense for your sensor:

// Send a float
Vwire.virtualSend(V0, temperature);

// Send an integer
Vwire.virtualSend(V1, humidity);

// Send a formatted string
Vwire.virtualSend(V2, String(speed, 1) + " km/h");

// Send multiple values (CSV) — used by MAP widget
Vwire.virtualSend(V3, String(lat, 6) + "," + String(lon, 6));
Rate limiting

VWire will throttle extreme write rates. Sending data every 100–2000 ms is appropriate for most sensors.


Receiving commands from the dashboard

Register a handler for pins that widgets write back to (e.g. a Button or Switch):

VWIRE_RECEIVE(V5) {
int value = param.asInt();
digitalWrite(RELAY_PIN, value); // 1 = on, 0 = off
Vwire.virtualSend(V5, value); // echo back current state
}

VWIRE_RECEIVE(V6) {
int brightness = param.asInt();
analogWrite(LED_PIN, brightness); // 0–255 from a Slider
}

Reading pin state on connect

To restore state after a device reboots, sync the current server-side value in setup():

void setup() {
Vwire.begin(SSID, PASSWORD);

// Request current value from server
Vwire.syncVirtual(V5); // will trigger VWIRE_RECEIVE(V5) with current value
}

Data types

All values travel as strings over MQTT. The library provides helpers:

MethodReturns
param.asStr()const char*
param.asInt()int
param.asFloat()float
param.asDouble()double

Pin assignment tips

RangeSuggested use
V0V9Primary sensor readings
V10V19Secondary / computed values
V20V29Control outputs (relays, PWM)
V100V109GPS / location data
V200V255Metadata (heap, RSSI, IP, etc.)

Digital and analog pins (D / A prefix)

In addition to virtual pins, VWire supports addressing physical hardware pins directly using D-prefixed (digital) and A-prefixed (analog) pin names.

Pin prefixExampleDescription
D0D99D2, D13Digital GPIO — reads or writes 0/1, or PWM (2–255)
A0A15A0, A1Analog ADC input — reads raw ADC value
V0V255V0, V5Virtual pin — arbitrary data, no hardware mapping

Physical pin names map directly to the labels printed on your development board:

  • D4 on an ESP8266/NodeMCU board refers to the pin labeled D4, which is hardware GPIO 2
  • D4 on an ESP32 board refers to GPIO 4

The library resolves these mappings automatically — you never need to look up GPIO numbers.

When to use virtual pins vs physical pins

ScenarioUse
Sensor value (temperature, humidity, ADC)V0V255 (virtual)
Computed / formatted valueVirtual
Control a relay, LED, buzzer directlyD-pin via GPIO manager
Read a button or switch state directlyD-pin via GPIO manager
Read a potentiometer or analog sensorA-pin via GPIO manager
Multiple values per update (CSV)Virtual

Physical pins are managed by the GPIO Pin Manager feature. See GPIO Pin Manager for setup and usage.