Retrieve IoT Sensor Data via API Gateway

HKUST users may retrieve HKUST IoT sensor data thru the following steps:

A) Request the API Key

B) Prepare an API tool

C) Search the data

A) Request the API Key

There are 2 related APIs in API Catalogue:

  • Sensor Inventory - list of IoT sensor with unique ID
  • IoT Sensor Data - records of IoT sensor data

An API key is needed to in order to retrieve the IoT sensor data. Please follow the following steps.

  1. Visit API Catalogue and sign up with your ITSC Account in the HKUST API Portal

 

  1. Click on "IoT Sensor Data" under Products and then click on "Subscribe".

 

  1. After you submit the request, it will be reviewed. You will get they API key thru email if approved.
  2. Similarly, you can request an API key for Sensor Data API.

 

B) Prepare an API tool

There are many API tool available. We use Postman, a popular one, as an example to demonstrate.

  1. Download postman from https://www.postman.com/ and then install it.

  1. Start postman, make sure "SSL certification verification" is OFF under "General" section of "SETTINGS".

 

  1. Try your first IoT sensor data query
  • Type “https://hkust.azure-api.net/sensor-data/_search?” in GET field.
  • Choose “Authorization” tab and choose “API Key” in the checkbox 
  • Type “X-Apim-Subscription-Key” in Key field
  • Type the API key in Value field
  • Finally, click "Send"

  1. If it is successful, there will be “200 OK” shown in Status and JSON format records list in the Body.

 

 

C) Search the data

For example. we are interested in sensors in LTL, we query and filter location in LTL from Sensor Inventory API and there are two records as shown below:

GET https://hkust.azure-api.net/sensor-inventory/_search?q=location:LTL

Result:

 

Particularly, we are only interested in SCAN project and Temperature sensor in LTL . We can refine the query of Sensor Inventory API and there are only one record returned as shown below:

Please note that %20 in the query is the URL encoding of space character.

GET https://hkust.azure-api.net/sensor-inventory/_search?q=location:LTA%20AND%20project:SCAN%20AND%20type_temperature:yes

Result:

 

Then we can use the ID to retrieve the temperature data from the IoT Sensor Data API .

GET https://hkust.azure-api.net/sensor-data/_search?q=ID:SCAN0006

Result:

 

Finally, we can filter to retrieve only the first 10 records in descending order during a specific time period.

Please note that %20 in the query is the URL encoding of space character.

GET https://hkust.azure-api.net/sensor-data/_search?sort=@timestamp:desc&size=10&q=ID:SCAN0006%20AND%20@timestamp:{2021-07-01T00:00:00%20TO%202021-07-31T23:59:59}

Result: