Skip to main content

Configuration

Read and update your device's configuration stored on RelayX.

Overview

The configuration module lets your device fetch its current configuration and push updates. This is useful for settings that should persist across device restarts — things like sampling intervals, thresholds, feature flags, or calibration values.

Access via device.config.

API

get()

Fetch the device's current configuration from RelayX.

await device.config.get()

Returns the device's configuration object, or {} if no configuration has been set

Throws TimeoutError if the server doesn't respond in time

Throws NotConnectedError if the device is not connected

set()

Replace the device's configuration on RelayX with a new object.

await device.config.set(data)
ParameterTypeDescription
dataobjectThe configuration object to store

Returns true if the configuration was updated successfully, false otherwise

Throws TimeoutError if the server doesn't respond in time

Throws NotConnectedError if the device is not connected

Get Configuration

const config = await device.config.get();
console.log("Sampling interval:", config.samplingInterval);
console.log("Threshold:", config.alertThreshold);

Update Configuration

const updated = await device.config.set({
samplingInterval: 5000,
alertThreshold: 80,
featureFlags: {
deepSleep: true,
logging: false,
},
});

console.log(updated ? "Config saved" : "Update failed");
info

set() replaces the entire configuration object. To update a single field, fetch the current config with get(), modify it, and pass the full object back to set().

Read-Modify-Write Pattern

// fetch current config
const config = await device.config.get();

// modify a single field
config.alertThreshold = 90;

// save it back
await device.config.set(config);

Error Handling

Both get() and set() require an active connection and will throw if the device is offline or the server doesn't respond.

try {
const config = await device.config.get();
} catch (err) {
if (err.name === "NotConnectedError") {
console.error("Device is offline");
} else if (err.name === "TimeoutError") {
console.error("Server did not respond");
}
}