Skip to content
Matthew Dowdell edited this page May 8, 2017 · 4 revisions

Contents

Creating new data

This should only ever be executed by the device itself and thus requires the credentials of the device, i.e. its identity and token, rather than any particular user.

To submit data, send the following to /v1/data as a POST request:

{
    "identity": "$identity",
    "token": "$token",
    "humidity": "$humidity",
    "pressure": "$pressure",
    "temperature": "$temperature",
    "log_time": "$time",
    "data": [{
        "sensor_type": "$type",
        "sensor_error": "$error",
        "sensor_r0": "$r0",
        "sensor_data": "$data"
    }]
}

Where:

  • identity is the identity of the device.
  • token is the token assigned to the device during registration.
  • humidity is the relative humidity (0-100).
  • pressure is the pressure in hPa.
  • temperature is the temperature in degrees Celsius.
  • log_time is the current time expressed in Unix time.
  • data is an array of objects which contain the following:
    • sensor_type is the name of the sensor type as a hexadecimal SHA1 hash.
    • sensor_error is a value between 0 and 1 denoting the standard error of the sensor.
    • sensor_r0 is the R0 value of the sensor.
    • sensor_data is the ADC value from the sensor.

A set of data can contain readings from multiple sensors, but only one reading from each sensor.

The response to this request if no errors occur will be the following:

{
    "gases": {
        "Alchohol": 0.0,
        "Methane": 0.0,
        "Hydrogen": 0.0
    }
}

The gases returned will vary based on the sensors used to make up the data set.

Example

import requests

server = 'http://sensly.io/v1%s'
create_data = {'identity': '00000000000000000000000000000000',
               'token': '00000000000000000000000000000000',
               'humidity': 30.0,
               'pressure': 1000.0,
               'temperature':  25.0,
               'log_time': '1494239045',
               'data': [{
                   'sensor_type': '00000000000000000000000000000000',
                   'sensor_error': 0.0,
                   'sensor_r0': 0.0,
                   'sensor_data': 1000
               }]}

r1 = requests.post(server % '/data', json=create_data)
print r1.json()

Retrieving data

To access data associated with a particular device, a user must be a member of the group it is associated with.

To get the data for a specific device, send a GET request to /v1/data/:identity, where identity is the identity of the device. A list of devices associated with a group can be found via the Groups API.

The response to this request if no errors occur will be:

/* TODO */

Example

import requests

session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': '[email protected]'
              'password': 'password'}

r1 = session.post(server % '/tokens')
token = r1.json()['token']
login_data['token'] = token

session.post(server % '/users/login', json=login_data)

r1 = session.get(server % '/groups')
identity = r1.json()['devices'][0]['identity']

r2 = session.get(server % '/data/' + identity)
print r2.json()
Clone this wiki locally