1- HTTP/HTTPS Write/Read API

HTTP (Hypertext Transfer Protocol) is a request-response based protocol between a client and server. The HTTP can be used to enable communications between IoT devices (clients) and the AskSensors server.

The GET Request is one of the most common HTTP methods used to request data from a specified resource and can be used to write data to or read data from the AskSensors IoT platform.

a) API to write data to AskSensors:

The AskSensors users can write data to the AskSensors IoT platform over HTTP/HTTPS using the following structures:

– Write Sensor measurement:

The HTTP GET Request to send sensor measurement to AskSensors follows the structure below:

https://api.asksensors.com/write/apiKeyIn?module1=value1

Or

https://api.asksensors.com/write/apiKeyIn?module1=value1&module2=value2&module3=value3&module4=value4&module5=value5&module6=value6

Where,

  • apiKeyIn: is the sensor API KEY IN.
  • value1…value6: are the modules values.

If the HTTP Get Request is performed well, you should Get the number of modules updated successfully.
Here are the response codes that you should get when writing data to the AskSensors IoT platform over HTTP/HTTPS:

  • 200: Corresponds to an OK HTTP code.
  • 1..6: Number of modules successfully updated.

The URL below shows an example to write a value of “100” to the “module1” of the Sensor with “apiKeyIn = BmYlV171NKvTmCOJioDRCnclbZUNvpwY:

https://api.asksensors.com/write/BmYlV171NKvTmCOJioDRCnclbZUNvpwY?module1=100

The response is the number of module updated successfully: “1”.

 

– Write GPS position:
Below is the URL structure to send GPS position (latitude and longitude) to AskSensors over HTTPS Get Requests:

https://api.asksensors.com/write/apiKeyIn?module1=latitude;longitude

or

https://api.asksensors.com/write/apiKeyIn?module1=latitude;longitude&module2=value2&module3=value3&module4=value4&module5=value5&module6=value6

Example of URL with Latitude = 48.855071 and longitude= 2.350138 that will be sent to the “module1” of the Sensor with “apiKeyIn = BmYlV171NKvTmCOJioDRCnclbZUNvpwY:

https://api.asksensors.com/write/BmYlV171NKvTmCOJioDRCnclbZUNvpwY?module1=48.855071;2.350138

 

– Write timestamped data:
In many applications, users need to send their data along with timestamp. The following structure shows the integration of the timestamp in the HTTP/HTTPS payload:
“module1=value1&module2=value2...module6=value6&t=timestamp”.

Where “timestamp” is the local timestamp of the values being sent in the HTTP/HTTPS payload.
The timestamp format is UNIX Epoch time in ms(or Unix time or POSIX time or Unix timestamp), which describes the number of milliseconds that have elapsed since January 1, 1970 (midnight UTC/GMT)

Below is an example of a HTTP/HTTPS payload sent with timestamp of Human time (GMT): Tuesday 1 January 2019 00:00:00:
“module1=100&module2=200&t=1546300800000”.

b) API to read data from AskSensors:

This API allows user to read data stored in AskSensors cloud server in JSON format using the HTTPS GET Request. Here is the structure:

https://api.asksensors.com/read/apiKeyOut?module=Module_Number&maxResults=number_of_entiries

Where,

  • apiKeyOut: is the Sensor API KEY OUT.
  • Module_Number: is the module name (module1, module2…module6).
  • maxResults: is the number of latest entries to read (from 1 to 50).

If the HTTP Get Request is performed well, you should Get a buffer with the specified number of enrties in JSON format:
Here are the response codes that you should get when reading data from the AskSensors IoT platform over HTTP/HTTPS:

  • 200: Corresponds to an OK HTTP code.
  • [{“value”:”…”,”date”:”…”},{“value”:”…”,”date”:”…”}]: The data read buffer in JSON format.

The URL below shows an example to read the “latest three entries” stored in the “module1” of the Sensor with “apiKeyOut = eNWxlUQLAmAleOXRULIAL90GVrytXBqr”:

https://api.asksensors.com/read/eNWxlUQLAmAleOXRULIAL90GVrytXBqr?module=module1&maxResults=3

The response is the module values in Json format: [{“value”:”100″,”date”:”2019-04-18 17:27:45.259Z”},{“value”:”100″,”date”:”2019-04-18 17:27:43.992Z”},{“value”:”100″,”date”:”2019-04-18 17:27:42.593Z”}].

Was this article helpful to you? Yes 2 No

How can we help?