API Documentation – Device-HTTP-API

Device http api

HTTP basics

HTTP is a general-purpose network protocol that can be used in IoT applications. You can find more information about HTTP here. HTTP protocol is TCP based and uses request-response model.

Cloudchip server nodes act as an HTTP Server that supports both HTTP and HTTPS protocols.

In order to publish telemetry data to Cloudchip server, send POST request to the following URL:

Telemetry HTTP API:

http://www.cloudchip.io/api/v1/$ACCESS_TOKEN/telemetry

Json data format #1:

{“key1″:”value1”, “key2″:”value2”}

Json data format #2:

[{“key1”:“value1”}, {“key2”:true}]

Json data format #3:

{“ts”:1451649600512, “values”:{“key1″:”value1”, “key2″:”value2”}}

Json data format #4:
{“ts”:1451649600512, “values”:{“key1”:“value1”, “key2”:“value2”}}
 

where as “1451649600512” is a unix timestamp with milliseconds precision. For example, the value ‘1451649600512’ corresponds to ‘Fri, 01 Jan 2019 12:00:00.512 GMT’

Example  

curl:

curl -v -X POST -d ‘{“key1”:25}’ http://www.cloudchip.io/api/v1/$ACCESS_TOKEN/telemetry -H “Content-Type:application/json”

Cloudchip attributes API allows devices to

  • Upload client-side device attributes to the server.
  • Request client-side and shared device attributes from the server.
  • Subscribe to shared device attributes from the server.

API:
http://web.cloudchip.io/api/v1/$ACCESS_TOKEN/attributes

Json Attributes Data: 

{“attribute1″:”value1”, “attribute2”:true, “attribute3”:42.0, “attribute4”:73}

Curl:
curl -v -X POST -d ‘{“attribute1″:”value1”}’ http://www.cloudchip.io/api/v1/$ACCESS_TOKEN/attributes –H “Content-Type:application/json”

Response:

NA

In order to subscribe to widget commands from the server, send GET request with optional “timeout” request parameter to the following URL:

http://www.cloudchip.io/api/v1/$ACCESS_TOKEN/rpc

Once subscribed, a client may receive widget request or a timeout message if there are no requests to a particular device. An example of widget request body is shown below:
{
  “id”: “1”,
  “method”: “setGpio”,
  “params”: {
    “pin”: “23”,
    “value”: 1
  }
}

where

  • id – request id, integer request identifier
  • method – RPC method name, string
  • params – RPC method params, custom json object

and can reply to them using POST request to the following URL:

API:

http://www.cloudchip.io/api/v1/$ACCESS_TOKEN/rpc

curl:

curl -X POST -d @rpc-client-request.json http://www.cloudchip.io/api/v1/$ACCESS_TOKEN/rpc –header “Content-Type:application/json”
 
Response:
{“method”: “getTime”, “params”:{}}