This guide explains how to monitor device status using Upswift REST API, Including Python scripts.
Time to read:
When it comes to managing edge Linux devices, one of the key points is to make sure that the devices are up and running. For example, when deploying an IoT app which connects many endpoints together, it can be extremely useful if there was a way to easily fetch a particular device’s online/offline status; preferably through a simple API call.
In this guide, we will be taking a look at Upswift's device online status API call, which is an HTTP GET request, which the posting payload should be in the form of JSON array.
For simplicity, the script is written in Python and the prerequisite modules are json and requests. These are by default installed with every Python installation, and the scripts are cross-platform compatible.
The user token can be found in the Settings section in the Upswift dashboard, by clicking on Show Account Token. This token is unique to your account and cannot be changed.
The Device ID is needed to obtain the device online status, and it can be found in the devices section. Each device is given a unique device ID after enrollment with the platform.
Following the official documentation for the API, the following Python script template can then be used to obtain device status from the dashboard.
Create a new file using nano <filename>.py and type in the script, and update the details accordingly. Then, press Ctrl+O and press Enter to confirm save.
Type in the command python <filename>.py (which was used to name the script in Step 3), and press Enter. (in the following example, the file has been saved as upswift_device_status.py)
Upon successful completion of the script, the above output should be displayed. If any error occurred, the script will print out the error message for further debugging.
For more information on the Upswift Change Device Details API, refer to the official documentation.