Connecting a Device
This guide walks through adding a new device and connecting it to VWire using the Arduino / ESP32 library.
1. Create the device in the dashboard
- Go to your Project → click + Add Device.
- Enter a name (e.g.
"Greenhouse Sensor") and click Create. - Copy two credentials from the device detail page:
| Credential | Example | Purpose |
|---|---|---|
| Auth Token | at_xxxxxxxx | MQTT password — proves who you are |
| Device ID | VW-ABC123 | Your device's address in MQTT topics |
Both are required. The Auth Token authenticates the connection; the Device ID is what your firmware uses in Vwire.setDeviceId().
2. Install the Vwire library
Manual install from GitHub
The VWire Arduino library is not currently available in Arduino Library Manager.
- Download the latest VWire Arduino ZIP archive from the official VWire GitHub repository.
- Open Arduino IDE → Sketch → Include Library → Add .ZIP Library.
- Select the downloaded ZIP archive.
- Install PubSubClient and ArduinoJson as dependencies.
PlatformIO
Place the VWire library in your project's local lib/VWire directory, then declare the remaining dependencies in platformio.ini:
; platformio.ini
lib_deps =
knolleary/PubSubClient
bblanchon/ArduinoJson
3. Basic sketch
#define VWIRE_PRINT_DEBUG // remove in production
#include <Vwire.h>
// ── Configuration ──────────────────────────────────────────
const char* SSID = "YourWiFiSSID";
const char* PASSWORD = "YourWiFiPassword";
const char* AUTH_TOKEN = "at_your-auth-token-here"; // from dashboard
const char* DEVICE_ID = "VW-XXXXXX"; // from dashboard
// ── Receive commands from dashboard ───────────────────────
VWIRE_RECEIVE(V1) {
int val = param.asInt();
digitalWrite(LED_BUILTIN, val);
}
// ── Setup ──────────────────────────────────────────────────
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Vwire.config(AUTH_TOKEN); // set auth token
Vwire.setDeviceId(DEVICE_ID); // set device ID
Vwire.begin(SSID, PASSWORD); // connect (uses mqtt.vwire.io:8883 by default)
}
// ── Loop ───────────────────────────────────────────────────
void loop() {
Vwire.run(); // MUST be called in every loop iteration
float temperature = 23.5; // replace with real sensor read
Vwire.virtualSend(V0, temperature);
delay(5000);
}
4. Verify connection
Check the Serial Monitor (115200 baud) for:
[VWire] Connecting to WiFi ...
[VWire] WiFi connected — 192.168.1.105
[VWire] Connecting to MQTT broker ...
[VWire] Connected to VWire!
The device status in the dashboard should change from Offline to Online within a few seconds.
5. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Stuck at "Connecting to WiFi" | Wrong SSID/password | Double-check credentials |
| "MQTT connect failed: 5" | Wrong auth token | Re-copy Auth Token from dashboard |
| "MQTT connect failed: 3" | Network / broker unreachable | Check WiFi and firewall on port 8883 |
| Device shows offline in dashboard | LWT published prematurely | Ensure Vwire.run() is called every loop |
| Values not appearing | Wrong pin number | Match V-pin in firmware and widget |