Programmatically perform operations on your Thing
OpenIoT provides REST API that lets you perform various operations on your Things, including read/write operations, reboot, data history, logs and more. The REST API uses HTTP POST requests and header token for authentication.
Input fields in POST request, token in header.
All endpoints requests should follow the following guideline:
- POST method
- TOKEN variable set to your private token in header
JSON response:
response
(response / error code) &data
(response data)
Following the REST API guidelines, API responses are in JSON format and include response code and associated data. Response codes are one of the following:
- 401: Forbidden access (invalid token)
- 403: Insufficient permissions (not your device / device shared with you and you don't have sufficient permissions)
- 500: Unknown error (issue on our end, if issue persists, let us know)
- 400: Input error (input data you've provided is invalid in some way)
- 204: No content (the data you've tried to get is empty)
- 422: Output error (there's an issue with the data you tried to get)
- 200: Valid response
When presented with a response code which is not 200
, read the associated data
response.
TOKEN
field in headers
Each request has to be authenticated. You authenticate your POST requests with TOKEN
field inside the request's headers. You can get your API token by going to the Account Page. You can generate a new token at any given time.
The base endpoint is
https://api.openiot.xyz/
The following request endpoints are currently available:
-
Input fields:
name
- Thing's name (required)board
- Board type [Options:esp8266
] (required)
-
Input fields:
id
- Thing's ID. If not set, then a list of all Things is returned.
-
Output fields:
-
connected
- Whether or not the Thing is connected to the platform. [Options: 1, 0] -
access
- Your permissions for the Thing. [Options: 1 (basic), 2 (admin)] -
name
- Thing's name -
ip
- Thing's IP address on the network -
status
- Whether or not it's online [Options: 0 (offline), 1 (online)] -
board
- Board type -
lastActivity
- Last time the Thing was updated -
version
- Code version (if you set it from the library) -
createdTime
- Creation date -
ports
- Array of attached GPIO- key/index - Port number
lastActivity
- Last time the port was updatedmode
- Port mode [Options: 0 (INPUT), 1 (OUTPUT)]type
- Port type [Options: analog, digital]name
- Port's name as set on the libraryvalue
-
variables
- Array of attached variables- key/index - Variable name
lastActivity
- Last time the variable was updatedtype
- Variable data type. [Options:int
,string
,char
(array),float
]value
-
functions
- Array of attached functions- key/index - Function name
-
-
Input fields:
-
id
- Thing's ID (required) -
action
- The element to which you want to transmit (required). Options:-
reboot
- Reboots the device -
gpio
- Updates a port's value. Required additional fields in this case:port
- Port numbervalue
- Value to which you update the port
-
variable
- Updates a variable's value. Required additional fields in this case:variable
- Variable nametype
- Variable data type. [Options:int
,string
,char
(array),float
]value
- Value to which you update the variable
-
function
- Executes a function. Required additional fields in this case:value
- Function name
-
-
-
Input fields:
name
- Element's name (required)thingID
- Thing's unique ID (required)
-
Output fields:
id
- Entry's unix timestamp0
- Entry's data
- Read thing's data:
curl -X POST -H 'TOKEN: API_TOKEN' -v -i 'https://api.openiot.xyz/thing/read?id=THING_ID'
- Transmit digital HIGH to port a0:
curl -X POST -H 'TOKEN: API_TOKEN' -v -i 'https://api.openiot.xyz/thing/transmit?id=THING_ID&action=gpio&port=a0&value=1'