Content
01 March 2016 / Last updated: 27 Jan 2017

New Supervisor endpoint: Device State

Execution time:
Difficulty:
Cost:
A while ago, we introduced the Resin Supervisor v1 and its API, which allows you to have more control over what happens on your device.
Now, we have released a new Supervisor version, v1.6.0, that adds a new endpoint to this API: GET /v1/device. This endpoint returns a JSON object which allows you to query the device's current state, and therefore gives you even more power over your device, because knowledge is power, isn't it?
The docs for this endpoint can be found here.
Basically, if you install curl and jq and run this on your app:
curl -X GET --header "Content-Type:application/json" \
    "$RESIN_SUPERVISOR_ADDRESS/v1/device?apikey=$RESIN_SUPERVISOR_API_KEY" \
	| jq '.'
You will get a response that looks like this:
{
"ip_address": "172.17.0.1",
"api_port": 48484,
"os_version": "Resin OS 1.0.6",
"supervisor_version": "1.6.0",
"download_progress": null,
"status": "Idle",
"commit": "08677a7451c0ebad5773fccdf050368191584d9b",
"update_pending": false,
"update_failed": false,
"update_downloaded": false
}
There are several things you can do with this information: query or display the version of your running app (using commit), give feedback to your users when an update is being downloaded (using status and download_progress), or even implement opt-in updates.
Opt-in updates? Yes, you can complement this new feature with the update lock to give users the possibility to opt-in to updates, or decide by yourself when an update will be applied. You can do this by locking updates on your devices, and then using the update_pending and update_downloaded fields returned by this endpoint to detect whether there's an update ready to be installed, then release or override the lock when the time to apply the update comes.
Think there are more things that this can be used for? Are there other fields that you'd like to see on this endpoint? Leave us a comment or come chat to us on Gitter!

Share this post