Advanced: configuration API - plan-d-io/P1-dongle GitHub Wiki
The P1-dongle has a REStful API to view and set the configuration. This API can be accessed over HTTP or MQTT.
Endpoint <dongle ip>/config
Supported methods GET, POST
A GET
to the config endpoint returns a JSON formatted string containing the current configuration.
Example output:
{ "HOSTNAME": { "varName": "Dongle hostname", "type": "string", "value": "P185978" }, "FW_VER": { "varName": "Firmware version", "type": "numeric", "value": 2.13 }, "EID_INTV": { "varName": "Allowed upload interval", "type": "string", "value": "Not yet set" }}
Each config variable has the following possible properties:
- varName: Human readable name of the config parameter
-
type: Type of variable, supported types are
bool
,int32
,uint32
,uint64
,numeric
,string
,password
,secret
,ipaddress
. - value: The current value of the variable
- defaultValue: The factory default value of the variable
Note that variables of the type password
and secret
do not contain a value
property, but instead contain a filled
key, indicating if this variable has been set by the user or not.
The preferred way of setting configuration variables is with a JSON formatted string which is POST
to the configuration endpoint. This config string should be key:value pairs, with the key being the config variable name and its value the desired value.
Example config string:
{"MQTT_TLS":false,"MQTT_PORT":1883,"MQTT_PASS":"password","EMAIL":"[email protected]"}'
You can also pass configuration variables as arguments of a GET
to the config endpoint.
Example GET URL:
<dongle-ip>/config?MQTT_TLS=false&MQTT_PASS=password&MQTT_PORT=1883&[email protected]
We do not recommend setting config variables over a GET as the values are visible in the URL
When MQTT is enabled, the dongle pushes its configuration to the <mqtt-prefix>/sys/config
topic. By subscribing this topic, you can view the current configuration of the dongle.
The
<mqtt-prefix>
defaults todata/devices/utility_meter
By default, the dongle only sends a small subset of the configuration to avoid problems with brokers with a small payload size limit
The dongle also subscribes to the <mqtt-prefix>/set/config
topic. You can post the same JSON-formatted strings to this topic as in the HTTP PUT example. The dongle will parse it in the same way and update its configuration.