Documentation Index
Fetch the complete documentation index at: https://docs.heylua.ai/llms.txt
Use this file to discover all available pages before exploring further.
When to Use MQTT
Use MQTT instead of the default Socket.IO transport when:- Your device has limited RAM (microcontrollers, Pico W)
- The network connection is unreliable or intermittent
- You need offline message queueing (commands delivered when the device reconnects)
- You are already running an MQTT infrastructure
- The device is battery-powered and needs a lightweight protocol
The Lua Device Gateway runs an MQTT broker at
wss://mqtt.heylua.ai/mqtt. You do not need to run your own broker.Configuration
Node.js
Python
MicroPython
Topic Structure
All MQTT topics follow a consistent prefix pattern:| Topic Suffix | Direction | QoS | Retained | Purpose |
|---|---|---|---|---|
status | Device publish | 1 | Yes | Online/offline status (retained for broker persistence) |
heartbeat | Device publish | 0 | No | Keepalive signal every 30 seconds |
response | Device publish | 1 | No | Command execution results |
trigger | Device publish | 1 | No | Device-to-agent event triggers |
command | Device subscribe | 1 | No | Incoming commands from the agent |
connected | Device subscribe | 1 | No | Server connection confirmation |
trigger_ack | Device subscribe | 1 | No | Trigger receipt acknowledgment |
trigger_result | Device subscribe | 1 | No | Trigger execution results (optional) |
error | Device subscribe | 1 | No | Server-side error messages |
pong | Device subscribe | 0 | No | Heartbeat response |
Last Will and Testament (LWT)
The MQTT client automatically sets a Last Will and Testament message on thestatus topic. If the device disconnects unexpectedly (network failure, power loss), the broker publishes the LWT message, which the gateway uses to immediately mark the device as offline.
QoS Levels
| QoS | Meaning | Used For |
|---|---|---|
| 0 | At most once (fire-and-forget) | Heartbeats — acceptable to miss one |
| 1 | At least once (with acknowledgment) | Commands, responses, triggers, status — must not be lost |
clean: false), this means commands are queued by the broker when the device is temporarily offline and delivered when it reconnects.
Authentication
MQTT authentication uses theusername and password fields of the MQTT CONNECT packet:
| Field | Value |
|---|---|
clientId | lua-{agentId}-{deviceName} |
username | {agentId}:{deviceName} |
password | Your API key |
Complete Example
A humidity and temperature monitor that fires an alert trigger when conditions are out of range:Next Steps
MicroPython Client
Run on a Raspberry Pi Pico W with native MQTT
Pico W Setup Guide
Step-by-step hardware setup with Thonny
Node.js Client
Socket.IO transport for full-featured Node.js devices
Architecture
Understand the full transport comparison

