Automatically translate this page?

How To Automate Device Settings Management Over API?

Configuring trackers using via flespi REST API.

This guide shows how to automate the use of the flespi device configurator tool with API based on the example of switching outputs on Galileosky v5.0 device. We assume that the device is already connected to the flespi channel and can be configured via the appropriate flespi device (with ID=12345) UI configuration tool.

flespi panel device configurator

Step 1. Get the list of settings

List of all settings with the current values and latest update time can be fetched via GET /devices/settings call:

curl -X GET --header 'Authorization: FlespiToken Your_flespi_token' 
'https://flespi.io/gw/devices/12345/settings/all?fields=name'

Result

{
  "result": [
{"name": "network_sim0"},
{"name": "network_sim1"},
{"name": "backend_server"},
{"name": "backend_server2"},
{"name": "backend_server_cfg"},
{"name": "wr_period"},
{"name": "tracking",}
{"name": "output0"},
{"name": "output1"},
{"name": "output2"},
{"name": "output3"}
  ]
}

Let’s take the command named “output1”.

Step 2. Get the schema of the desired setting

Specify the request from the step above by adding field “schema” and replacing all selector with command name “output1”.

curl -X GET --header 'Authorization: FlespiToken Your_flespi_token' 
'https://flespi.io/gw/devices/12345/settings/name=output1?fields=schema'

Result

{
  "result": [
    {
      "schema": {
        "additionalProperties": false,
        "description": "Switching external trigger 1. By default trigger is switched off. \
State is hold in non-volatile memory, will be restored after reboot.",
        "properties": {
          "out_val": {
            "description": "State of external output 1.",
            "title": "Output 1 state",
            "type": "boolean"
          }
        },
        "required": [
          "out_val"
        ],
        "title": "Output 1",
        "type": "object",
        "x-view-order": [
          "out_val"
        ]
      }
    }
  ]
}

Here we can see that to update the state of the output via API, we need to pass “out_val” parameter of boolean type.

Step 3. Update setting value

Using the PUT /devices/settings method update the value of output1. For the setting to be updated the schema of the PUT request’s data must strictly correspond to the current setting.

curl -X PUT --header 'Authorization: FlespiToken Your_flespi_token' -d 
'{"address":"connection","properties":{"out_val":true},"ttl":86400}'
'https://flespi.io/gw/devices/12345/settings/name=output1'

Result

{
  "result": [
    {
      "address": [
        "connection"
      ],
      "current": null,
      "device_id": 12345,
      "mode": 3,
      "name": "output1",
      "pending": {
        "out_val": true
      },
      "tab": "Input/Output",
      "updated": 0
    }
  ]
}

Conclusion

To check that settings have been accepted you can perform GET /devices/settings request again and check the device Toolbox to see the appropriate log records. Or use a voltmeter on device outputs.

Flespi provides you with the REST (Representational state transfer) API to access your devices enabling you to work with device settings as if the tracker is on your table.


See also
Helping you quickly go through the real-life issues.
Figuring out at what step in the connectivity chain the problem is and how to fix it.