Configure Devices
Distribute configuration to devices through a protected
device property, a named JSON value
that operators set and the device can only read. A service on the device reads
the property and applies it. This guide configures an example sensor service
from the com.example.sensor.config property; adapt the property name,
configuration path, validation, and reload command to your own service.
You need a device connected through Nexigon Agent and
Nexigon CLI on your workstation. The device-side
setup runs as root on Linux with Bash, systemd, and jq, and assumes a sensor
service that reads /etc/sensor-service/config.json and supports
systemctl reload.
The Nexigon CLI commands assume an organization API token. With a user token,
add --organization <org-id> to each command, as
Organization Selection
describes.
How Declarative Configuration Works
The property records the desired configuration, and the service on the device periodically reconciles its local configuration with it. After a reboot or a temporary connection failure, the next run applies the same desired state, so operators never need to resend a change.
Setting the property does not mean that the device has applied it. The device reads the value, validates it, writes its local configuration, and reloads the service. Reporting the applied state in a separate property lets operators tell a requested change from a completed one.
Set the Desired Configuration
Run this on your workstation:
nexigon-cli devices properties set --protected=true <device-id> com.example.sensor.config \
'{"sample_rate_hz": 10, "enabled_channels": ["temperature", "humidity"]}'
Your service defines the meaning of the fields; here, sample_rate_hz requests
ten readings per second, and enabled_channels selects the readings to
collect. Prefix custom property names with your own domain, because
dev.nexigon is reserved for properties that Nexigon defines.
Apply the Configuration on the Device
Create this script on the device:
#!/usr/bin/env bash
set -euo pipefail
response=$(nexigon-agent device properties get com.example.sensor.config)
config=$(printf '%s\n' "$response" | jq -e '
if .result == "Found" and (.value | type == "object")
then .value
else error("configuration property is missing or is not an object")
end
')
printf '%s\n' "$config" >/etc/sensor-service/config.json.tmp
mv /etc/sensor-service/config.json.tmp /etc/sensor-service/config.json
systemctl reload sensor-serviceThe script refuses to replace the file if the property is missing or is not an object, and the rename replaces the file in one step. Add the validation that your service needs before the rename; a JSON object can still contain invalid fields. A failed reload does not restore the previous file, so add recovery if your service needs it.
Run the script every five minutes with a systemd service and timer:
[Unit]
Description=Apply Sensor Service Configuration
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/apply-sensor-config.sh[Unit]
Description=Apply Sensor Service Configuration Timer
[Timer]
OnBootSec=1min
OnUnitInactiveSec=5min
[Install]
WantedBy=timers.targetchmod +x /usr/local/bin/apply-sensor-config.sh
systemctl daemon-reload
systemctl enable --now apply-sensor-config.timer
Change the property from your workstation and check the sensor service after
the next run. journalctl -u apply-sensor-config.service shows failures. If
the device cannot reach Nexigon Hub, the script fails and leaves the file in
place, and a later run applies the change.
The timer reloads the service on every run, even if the value is unchanged.
If reloads are expensive or disruptive, compare the desired configuration with
the current file first. To report the applied configuration, have the script
set an unprotected property, such as com.example.sensor.state, after a
successful reload, or emit an event when it fails.
Add a Configuration Form
A property schema describes the fields of a property, so that the web
interface can show a form and check values, such as a sample rate within its
range. Open Project Settings → Property Schemas → Add Schema and save this
schema under the property name com.example.sensor.config:
{
"type": "object",
"properties": {
"sample_rate_hz": {
"type": "integer",
"title": "Sample Rate (Hz)",
"minimum": 1,
"maximum": 100
},
"enabled_channels": {
"type": "array",
"title": "Enabled Channels",
"items": { "type": "string", "enum": ["temperature", "humidity"] }
}
},
"required": ["sample_rate_hz", "enabled_channels"]
}
On the device’s Properties page, editing the property now shows the schema’s fields. Source opens the complete JSON value, and Form returns to the fields without discarding other values. Saving checks the value against the schema; to save it anyway, select Set property despite validation errors and choose Force Set Property. Schemas only guide the web interface and do not restrict writes through the agent or the API. Property Schemas lists the supported schema versions.
Share Configuration Through Profiles
Use device profiles to supply common property values to several devices. Profiles combine configuration in order; a device’s own values can override individual settings. Assignment makes the configuration available, and the device’s service still has to apply it.
Distribute Configuration Files
For configuration in other formats, such as YAML, store the files in a
repository and set the property to a file’s
path. The script then downloads the selected file with
nexigon-agent repositories issue-url and applies it with the service’s own
tooling.