Installation
DeviceClientConfig
The configuration object passed tonew DeviceClient().
Agent ID to connect to. Found in
.lua/lua.config.yaml or the Lua dashboard.API key for authentication. Generate with
lua auth configure.Unique name for this device. Lowercase with hyphens (e.g.,
label-printer, pico-sensor-01).Array of commands this device supports. Sent to the server at connect time so the agent can use them as tools. See Self-Describing Commands.
Transport protocol. Use
'mqtt' for constrained devices or environments where MQTT is preferred.Server URL for Socket.IO transport.
MQTT broker URL. Required when
transport is 'mqtt'.CDN URL for file uploads and downloads.
Optional device group name for fan-out commands (e.g.,
'printers', 'sensors-floor-2').DeviceCommandDefinition
Each entry in thecommands array describes one command the device supports.
Command name. Used by the agent to invoke the command (e.g.,
read_temperature).Human-readable description. Shown to the AI agent as the tool description. Write it as if explaining to a person what the command does.
JSON Schema for command input parameters. The agent uses this to know what arguments to pass.
Command timeout in milliseconds. If the device does not respond within this time, the command fails.
Retry configuration for failed commands. The gateway retries with exponential backoff.
Connection Lifecycle
The client automatically reconnects on network failures with jittered exponential backoff (1s to 30s). Call
disconnect() to stop reconnection. The client also registers SIGTERM and SIGINT handlers for graceful shutdown.Handling Commands
Register handlers for commands the agent can send to this device:Firing Triggers
Send events from the device to the agent:CDN Uploads
EveryDeviceClient instance includes a cdn property for uploading and downloading files:
Transport Configuration
- Socket.IO (default)
- MQTT
Complete Example
A device that simulates a smart thermostat with temperature reading, target temperature setting, and a high-temperature alert trigger:Next Steps
MQTT Transport
Deep dive into MQTT configuration and topic structure
CDN Uploads
Upload and download files from your device
Triggers
Send events from your device to the agent
API Reference
Complete class and method documentation

