Page tree
Skip to end of metadata
Go to start of metadata

In this tutorial, we will create two datasources (one for temperature and another for humidity) and submit three dummy measurements for each. We will use curl as a simple http client but you can use any modern tool such as httpie or Postman for these operations. 


Create two data streams

Create Humidity

The resource field is the name of this datasource which must be a valid URI. 

curl -X POST -i \
  http://localhost:8085/registry/ \
  -d '{	"name": "dummy/location1/sensor1/humidity",	"datatype": "float" }'

Response would be as follows:

HTTP/1.1 201 Created
Location: /registry/dummy/location/humidity
Vary: Origin
Date: Fri, 07 Jun 2019 09:20:12 GMT
Content-Length: 0

The location header is the path to the created datasource :  

 /registry/dummy/location1/humidity

Create Temperature

curl -X POST -i \
  http://localhost:8085/registry/ \
  -d '{	"name": "dummy/location1/sensor1/temperature",	"datatype": "float" }'

Response would be as follows

HTTP/1.1 201 Created
Location: /registry/dummy/location1/temperature
Vary: Origin
Date: Fri, 07 Jun 2019 09:20:12 GMT
Content-Length: 0

Copy the location header from the response:

Check the Registry

Query the registry to see what is created:

curl http://localhost:8085/registry



{
  "url": "/registry",
  "streams": Array[6][
    {
      "name": "dummy/location1/sensor1/humidity",
      "source": {
        "type": ""
      },
      "dataType": "float",
      "retain": {
        "max": ""
      }
    },
    {
      "name": "dummy/location1/sensor1/temperature",
      "source": {
        "type": ""
      },
      "dataType": "float",
      "retain": {
        "max": ""
      }
    }
  ],
  "page": 1,
  "per_page": 100,
  "total": 2
}


Submit Sensor Measurements

Now, submit some sensor values. You can add other SenML fields (e.g. u for unit)

curl -X POST \
  http://localhost:8085/data/b9dd5208-d0f0-41e7-948a-22b9cf31236c \
  -H 'content-type: application/senml+json' \
  -d '[{"n":"dummy/location1/sensor1/temperature","v":24.5}]'
curl -X POST \
  http://localhost:8085/data/7c16fb04-a0a4-43ee-a87e-53c86346ffb1 \
  -H 'content-type: application/senml+json' \
  -d '[{"n":"dummy/location1/sensor1/humidity","v":45}]'

You can also send values for multiple datasources in a single request (you have to give both UUIDs in the URL):

curl -X POST \
  http://localhost:8085/data/b9dd5208-d0f0-41e7-948a-22b9cf31236c,7c16fb04-a0a4-43ee-a87e-53c86346ffb1 \
  -H 'content-type: application/senml+json' \
  -d '[{"bn":"dummy/location1/sensor1/","n":"temperature","v":25}, {"n":"humidity","v":42.005}]'


Get the Measurements

To get the humidity data (Change the url to http://localhost:8085/data/dummy/location1/sensor1/temperature  in order to get temperature measurements): 

curl http://localhost:8085/data/dummy/location1/sensor1/humidity
{
   "selfLink":"/data/dummy/location1/sensor1/humidity?\u0026perPage=1000\u0026sort=desc\u0026to=2019-06-07T09:46:01Z",
   "data":[
      {
         "n":"dummy/location1/sensor1/humidity",
         "t":1559900747.3420002,
         "v":42.005
      },
      {
         "n":"dummy/location1/sensor1/humidity",
         "t":1559900696.496,
         "v":45
      }
   ],
   "took":0,
   "nextLink":""
}
  • No labels