Skip to main content

MQTT Protocol Reference

Vwire uses a structured MQTT topic hierarchy for all device communication. This page covers the broker details, how authentication works, the topic schema, payload format, and keep-alive behaviour.

For the complete topic reference including notification and OTA topics, see the MQTT API Reference.


Broker endpoints

FieldValue
Hostmqtt.vwire.io
Port (TLS)8883 (recommended)
Port (plain TCP)1883
TLSRequired on port 8883
ProtocolMQTT 3.1.1

Authentication — two credentials

Every Vwire device has two separate credentials:

CredentialMQTT fieldPurpose
Auth TokenpasswordAuthenticates the connection
Device ID (e.g. VW-ABC123)clientId and usernameIdentifies which MQTT topics belong to this device

Both are available on the device detail page in the dashboard. The library sets them automatically when you call Vwire.config(AUTH_TOKEN) and Vwire.setDeviceId(DEVICE_ID).


Topic schema

All topics use the Device ID (never the auth token) as the identifier:

Device → Server

TopicPurpose
vwire/{deviceId}/pin/{pin}Publish virtual pin value (e.g. pin/V0)
vwire/{deviceId}/statusDevice online / offline (LWT)
vwire/{deviceId}/heartbeatDevice health (uptime, heap, RSSI, IP, firmware)
vwire/{deviceId}/sync/{pin}Request server to resend last stored value for pin
vwire/{deviceId}/notifyPush notification to user
vwire/{deviceId}/alarmPersistent alarm requiring acknowledgment
vwire/{deviceId}/emailEmail notification to user
vwire/{deviceId}/ack/{msgId}Reliable delivery acknowledgment
vwire/{deviceId}/ota_statusOTA progress / result report
vwire/{deviceId}/logDebug log message

Server → Device

TopicPurpose
vwire/{deviceId}/cmd/{pin}Dashboard writes a value to a pin (e.g. cmd/V1)
vwire/{deviceId}/otaOTA firmware command (URL, hash, version)
vwire/{deviceId}/alarm_ackAlarm acknowledgment from mobile app

Payload format

All pin values are wrapped in a JSON array:

["value"]

For multiple values at once (multi-param):

["value1", "value2", "value3"]

Examples:

["23.5"]                   ← temperature
["255"] ← integer
["48.858844,2.294351"] ← GPS as string
["255","128","0"] ← R, G, B

The Vwire library handles JSON wrapping automatically via Vwire.virtualSend(). If you publish raw MQTT, wrap values in a JSON array.


QoS levels

Message typeQoSRationale
Sensor data (frequent)0Best-effort; occasional loss acceptable
Commands (control)1At-least-once; duplicates handled on device
OTA trigger1Must not be lost
LWT1Must be delivered on disconnect

Last Will Testament (LWT)

The library configures LWT automatically during Vwire.begin():

FieldValue
LWT Topicvwire/{deviceId}/status
LWT Payload{"status":"offline"}
QoS1
Retaintrue

Keep-alive

The library sets the MQTT keep-alive to 60 seconds.
After 30 seconds without a PUBLISH, the client sends a PINGREQ.
If the broker receives no traffic for 60 seconds, it publishes the LWT and disconnects the client.


Example raw MQTT session

# Publish temperature on V0
mosquitto_pub \
-h mqtt.vwire.io -p 8883 \
--cafile /etc/ssl/certs/ca-certificates.crt \
-i "VW-ABC123" \
-u "VW-ABC123" \
-P "at_your-auth-token" \
-t "vwire/VW-ABC123/pin/V0" \
-m '["23.5"]'
# Subscribe to commands on V1
mosquitto_sub \
-h mqtt.vwire.io -p 8883 \
--cafile /etc/ssl/certs/ca-certificates.crt \
-i "VW-ABC123" \
-u "VW-ABC123" \
-P "at_your-auth-token" \
-t "vwire/VW-ABC123/cmd/V1"

Broker endpoints

FieldValue
Hostapp.vwire.io
Port (MQTTS)8883
Port (WebSocket TLS)443
TLSRequired
AuthenticationDevice Token

Topic schema

All topics follow the pattern:

vwire/{deviceToken}/{direction}/{pinType}/{pinNumber}

Publish (device → server)

TopicPurpose
vwire/{token}/data/v/{pin}Push virtual pin value
vwire/{token}/statusDevice status / heartbeat
vwire/{token}/infoDevice metadata (firmware version, etc.)

Subscribe (server → device)

TopicPurpose
vwire/{token}/cmd/v/{pin}Receive value written to virtual pin
vwire/{token}/otaOTA firmware update trigger
vwire/{token}/syncSync pin values on reconnect

Payload format

Virtual pin value

["value"]

or for multiple values at once:

["value1", "value2", "value3"]

Examples:

["23.5"]                      ← temperature
["255"] ← integer
["48.858844,2.294351"] ← GPS as string
["{\"a\":1,\"b\":2}"] ← JSON string escaped

The VWire library handles JSON wrapping automatically via virtualSend(). If you publish raw MQTT, wrap values in a JSON array.


QoS levels

Message typeQoSRationale
Sensor data (frequent)0Best-effort; occasional loss acceptable
Commands (control)1At-least-once; duplicates handled on device
OTA trigger1Must not be lost
LWT1Must be delivered on disconnect

Last Will Testament (LWT)

The library configures LWT automatically during Vwire.begin():

FieldValue
LWT Topicvwire/{token}/status
LWT Payload{"status":"offline"}
QoS1
Retaintrue

When the device disconnects cleanly or drops, the broker publishes this automatically.


Keep-alive

The library sets the MQTT keep-alive to 60 seconds by default.
After keepAlive / 2 seconds without a PUBLISH (30 s), the client sends a PINGREQ.
If the broker receives no PINGREQ for keepAlive seconds, it considers the client disconnected and publishes the LWT.


Example raw MQTT session

# Using mosquitto_pub to publish temperature
mosquitto_pub \
-h app.vwire.io -p 8883 \
--cafile /etc/ssl/certs/ca-certificates.crt \
-u "dt_your-device-token" \
-P "dt_your-device-token" \
-i "dt_your-device-token" \
-t "vwire/dt_your-device-token/data/v/0" \
-m '["23.5"]'
# Subscribe to commands on V1
mosquitto_sub \
-h app.vwire.io -p 8883 \
--cafile /etc/ssl/certs/ca-certificates.crt \
-u "dt_your-device-token" \
-P "dt_your-device-token" \
-i "dt_your-device-token" \
-t "vwire/dt_your-device-token/cmd/v/1"