API Based Sensor Data Sources

📘

Before you begin.

You will need:

Posting observations (data) to a datastream through HTTPS

To send data to a datastream via HTTPS, use the Senaps API. You can find full Senaps API documentation here.

Below is an example POST request in Python using the Requests package and as a curl request:

🚧

Important

The timestamp must be formatted as ISO8601, and can include a maximum of millisecond resolution.
Timestamps are both stored internally and returned as UTC. It is highly recommended timezone
information is included when providing timestamps. Timestamps provided with no timezone
information are interpreted as UTC.

curl -X POST "https://senaps.eratos.com/api/sensor/v2/observations?streamid=eratos-internal.example-platform.datastream.one" -H  "accept: */*" -H  "apikey: YOUR SENAPS API KEY" -H  "Content-Type: application/json" -d "{\"results\":[{\"t\":\"2015-11-12T00:00:00.000Z\",\"v\":{\"v\":1}}]}"
import requests
import pprint as pp

# Define your API key and the URL of the endpoint
api_key = 'YOUR API KEY'
url = 'https://senaps.eratos.com/api/sensor/v2/observations?streamid='
stream_id = 'eratos-internal.example-platform.datastream.one'

# Define the headers including the Content-Type and Authorization header with your API key
headers = {
    'Content-Type': 'application/json',
    'apikey': api_key
}

#Define your payload as a json. This is an example for a scalar stream. Other stream types can be found below.
payload = {
    "results": [
        {
            "t": "2015-11-13T00:00:00.000Z",
            "v": {
              "v": 1.0  
            }
        }
    ]
}

#Post the data through the API
response = requests.post(f'{url}{stream_id}', json=payload, headers=headers)

print("Response:")
pp.pprint(response.json())

Other Stream Types

Other types of payloads for different stream types can be found below:

---SCALAR STREAM---
It is also legal to send a CSV payload for scalar streams
{
  "results" : [
    {
      "t" : "2015-11-12T00:00:00.000Z",
      "v" : {
        "v" : 1.0
      }
    }
  ]
}

---GEOLOCATION STREAM---
{
  "results" : [
    {
      "t": "2014-10-07T00:47:03.000Z",
      "v": {
        "p": {
          "type": "Point",
          "coordinates": [
            150.369105,
            -31.742179,
            415.8
          ]
        }
      }
    }
  ]
}
---IMAGE STREAM---
The image file must be Base64 encoded in the imageData property. 
The supported mime types are "image/tiff", "image/jpeg" and "image/png".
{
  "results": [{
    "t": "2018-01-03T00:00:00.000Z",
      "v": {
        "m": "image/jpeg",
        "d": "[insert base64 encoded image binary data here]"
      }
    }
  ]
}
---VECTOR STREAM---
{
  "results" : [
    {
      "t" : "2015-11-12T00:00:00.000Z",
      "v" : {
        "v" : [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
      }
    }
  ]
}

---DOCUMENT STREAM---
Use field "d" for "text/plain", and field "j" for "application/json".
{
  "results" : [
    {
      "t" : "2015-11-12T00:00:00.000Z",
      "v" : {
        "j" : {"a_key": "a_value"}
      }
    }
  ]
}