-
Notifications
You must be signed in to change notification settings - Fork 0
Data
Contents
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:
-
identityis the identity of the device. -
tokenis the token assigned to the device during registration. -
humidityis the relative humidity (0-100). -
pressureis the pressure in hPa. -
temperatureis the temperature in degrees Celsius. -
log_timeis the current time expressed in Unix time. -
datais an array of objects which contain the following:-
sensor_typeis the name of the sensor type as a hexadecimal SHA1 hash. -
sensor_erroris a value between 0 and 1 denoting the standard error of the sensor. -
sensor_r0is the R0 value of the sensor. -
sensor_datais 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.
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()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 */import requests
session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': 'bill@example.com'
'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()