Skip to main content

Remote Procedure Call (RPC)

Make request/reply calls from your app to devices. Unlike commands, RPC waits for the device to respond before returning.

Access via app.rpc.

API

call()

Send an RPC request to a device and wait for its response.

await app.rpc.call(params)
ParameterTypeDescription
device_identstringThe device identifier
namestringThe RPC name (must match a listener on the device)
dataanyThe request payload
timeoutnumber(optional) Timeout in seconds. Default: 10

Returns the response from the device

Throws TimeoutError if the device doesn't respond within the timeout

const response = await app.rpc.call({
device_ident: "sensor_01",
name: "get_status",
data: { include_logs: true },
timeout: 20,
});

console.log("Uptime:", response.data.uptime);
console.log("Firmware:", response.data.firmware);

Response Format

The device responds using request.respond(data) or request.error(data) from the Device SDK RPC module. The response object contains:

FieldDescription
status"ok" for success, "error" for errors
dataThe response payload from the device

Success response:

{
"status": "ok",
"data": {
"uptime": 86400,
"firmware": "1.2.0",
"temperature": 22.5
}
}

Error response (when the device calls request.error()):

{
"status": "error",
"data": {
"message": "Unknown service: analytics"
}
}

Error Handling

try {
const response = await app.rpc.call({
device_ident: "sensor_01",
name: "get_status",
data: {},
timeout: 5,
});

if (response.status === "error") {
console.error("Device error:", response.data);
} else {
console.log("Success:", response.data);
}
} catch (err) {
// TimeoutError — device didn't respond in time
console.error("RPC timed out:", err.message);
}