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.
- JavaScript
- Python
await device.config.get()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.
- JavaScript
- Python
await device.config.set(data)await device.config.set(data)| Parameter | Type | Description |
|---|---|---|
data | object | The 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
- JavaScript
- Python
const config = await device.config.get();
console.log("Sampling interval:", config.samplingInterval);
console.log("Threshold:", config.alertThreshold);
config = await device.config.get()
print("Sampling interval:", config["samplingInterval"])
print("Threshold:", config["alertThreshold"])
Update Configuration
- JavaScript
- Python
const updated = await device.config.set({
samplingInterval: 5000,
alertThreshold: 80,
featureFlags: {
deepSleep: true,
logging: false,
},
});
console.log(updated ? "Config saved" : "Update failed");
updated = await device.config.set({
"samplingInterval": 5000,
"alertThreshold": 80,
"featureFlags": {
"deepSleep": True,
"logging": False,
},
})
print("Config saved" if updated else "Update failed")
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
- JavaScript
- Python
// fetch current config
const config = await device.config.get();
// modify a single field
config.alertThreshold = 90;
// save it back
await device.config.set(config);
# fetch current config
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.
- JavaScript
- Python
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");
}
}
try:
config = await device.config.get()
except NotConnectedError:
print("Device is offline")
except TimeoutError:
print("Server did not respond")