MQTT — Add a New Event Kind
The device speaks MQTT for admin commands (fired from the web dashboard) and
status reports. Every command is an envelope shaped like
{"cmd": "data", "kind": "<kind>", "data": {…}}.
Sending an MQTT command from the backend
The web admin fires commands via the BFF endpoint
POST /device/{id}/send-message?listen=true, which relays over MQTT.
Web-side client wrapper (in the autonomous.ai frontend repo) is
StandToEarnApi.sendDeviceMessage.
Example payload:
{ "cmd": "data", "kind": "device.soft_reset", "data": {} }
Receiving on the device — add a new handler
Adding a new MQTT command is three edits inside os/services/:
-
Declare the kind constant in
os/services/domain/device.go:const (KindDeviceRename = "device.rename"KindDeviceSoftReset = "device.soft_reset" // ← your new one// …) -
Write the handler — one file under
os/services/server/device/delivery/mqtt/. Seedevice_soft_reset_handler.goanddevice_rename_handler.gofor reference patterns (envelope unmarshalling, ack viapublishDataResult, goroutine-off-callback for long work). -
Wire it into the dispatcher — one case in the switch in
os/services/server/device/delivery/mqtt/handler.godispatchData():case domain.KindDeviceSoftReset:return h.handleDeviceSoftReset(env)
Rebuild os-server (see Building + Shipping Code) and the new command is live.
The full MQTT protocol reference (topics, envelope shape, privacy vs inline
delivery, ack model) lives in the autonomous-os repo docs.