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
Arduino Library Manager (recommended)
- Open Arduino IDE → Sketch → Include Library → Manage Libraries
- Search for VWire
- Click Install
Manual install
Download the ZIP from GitHub and install via Sketch → Include Library → Add .ZIP Library.
PlatformIO
; platformio.ini
lib_deps =
https://github.com/vwireiot/vwire-arduino.git
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 |