Skip to main content

Command

Receive commands from the App SDK asynchronously. Unlike RPC, commands are fire-and-forget — your device does not send a response back to the caller.

Overview

Commands use durable delivery — if your device is offline when a command is sent, it will be delivered when the device reconnects. If your handler throws an error, the command is automatically retried after a 5-second delay.

Access via device.command.

RPC vs Command

RPCCommand
DirectionApp SDK → Device → App SDKApp SDK → Device
ResponseDevice sends a responseNo response
DeliveryRequires active connectionDurable — delivered even if device is offline
RetryNo retryAuto-retry on handler failure (5s delay)

API

listen()

Register a handler for incoming commands matching a given name.

await device.command.listen(name, callback)
ParameterTypeDescription
namestringThe command name to listen for
callbackfunctionCalled when a command arrives. Receives the command payload

Throws DuplicateListenerError if a listener with the same name is already registered

Throws ValidationError if name contains invalid characters

Naming rules

Names can only contain letters, numbers, hyphens, and underscores (A-Z, a-z, 0-9, -, _).

off()

Unregister a previously registered command listener.

await device.command.off(name)
ParameterTypeDescription
namestringThe command name to stop listening for

Returns true if the listener was removed, false if no listener existed for that name

Listen for Commands

await device.command.listen("reboot", (payload) => {
console.log("Reboot requested:", payload);
initiateReboot();
});

await device.command.listen("update_firmware", (payload) => {
const { version, url } = payload;
console.log(`Updating to ${version} from ${url}`);
downloadAndInstall(url);
});

Guaranteed Delivery

Commands are durably stored and delivered even if your device is offline when the command is sent. Once your device reconnects, any pending commands are delivered in order.

If your handler throws an error, the command is automatically retried after a 5-second delay, up to a maximum of 5 attempts. If the handler succeeds (no error thrown), the command is acknowledged and won't be delivered again.

await device.command.listen("deploy", (payload) => {
const success = deployConfig(payload);

if (!success) {
// throwing an error triggers a retry in 5 seconds
throw new Error("Deploy failed — will retry");
}
});

Remove a Listener

await device.command.off("reboot");

Safe to call even if no listener exists for that name.