2.6. Sensor Data

In the WoTKit, sensor data consists of a timestamp followed by one or more named fields. There are a number of reserved fields supported by the WoTKit:

Reserved field name Description
timestamp the time that the sensor data was collected. This is a long integer representing the number of milliseconds from Jan 1, 1970 UTC. Optional; if not supplied, a server-supplied timestamp will be used.
id a unique identifier for the data reading. This is to distinguish one reading from another when they share the same timestamp. Read only; This field is read only and should not be sent by the client when sending new data.
sensor_id the globally unique sensor id that produced the data. Read only; This is a read only field generated by the wotkit that should not be sent by a client when sending new data.
sensor_name the globally unique sensor name, in the form {username}.{sensorname}. Read only; This is a read only field and should not be sent by the client when sending new data.

When a new sensor is created, a number of default fields are created by the wotkit for a sensor as follows. Note that these can be changed by editing the sensor fields.

In addition to these reserved fields, additional required or optional fields can be added by updating the sensor fields in the WoTKit UI or sensor_fields in the API.

Note

* Python’s time.time() function generates the system time in seconds, not milliseconds.

To convert this to an integer in milliseconds use int(time.time()*1000). Using Java: System.currentTime().

2.6.1. Sending New Data

To send new data to a sensor, POST name value pairs corresponding to the data fields to the /sensors/{sensorname}/data URL.

There is no need to provide a timestamp since it will be assigned by the server. Data posted to the system will be processed in real time.

To send new data:

URL http://wotkit.sensetecnic.com/api/sensors/{sensorname}/data
Privacy Private
Format not applicable
Method POST
Returns HTTP status code; No Response 201 (Created) if successful

example

curl --user {id}:{password} --request POST
-d value=5 -d lng=6 -d lat=7 'http://wotkit.sensetecnic.com/api/sensors/test-sensor/data'

2.6.2. Sending Bulk Data

To send a range of data, you PUT data (rather than POST) data into the system. Note that data PUT into the WoTKit will not be processed in real time, since it occurred in the past

  • The data sent must contain a list of JSON objects containing a timestamp and a value.
  • If providing a single piece of data, existing data with the provided timestamp will be deleted and replaced. Otherwise, the new data will be added.
  • If providing a range of data, any existing data within this timestamp range will be deleted and replaced by the new data.

To update data:

URL http://wotkit.sensetecnic.com/api/sensors/{sensorname}/data
Privacy Private
Format JSON
Method PUT
Returns HTTP status code; No Response 204 if successful

Example of valid data:

[{"timestamp":"2012-12-12T03:34:28.626Z","value":67.0,"lng":-123.1404,"lat":49.20532},
{"timestamp":"2012-12-12T03:34:28.665Z","value":63.0,"lng":-123.14054,"lat":49.20554},
{"timestamp":"2012-12-12T03:34:31.621Z","value":52.0,"lng":-123.14063,"lat":49.20559},
{"timestamp":"2012-12-12T03:34:35.121Z","value":68.0,"lng":-123.14057,"lat":49.20716},
{"timestamp":"2012-12-12T03:34:38.625Z","value":51.0,"lng":-123.14049,"lat":49.20757},
{"timestamp":"2012-12-12T03:34:42.126Z","value":55.0,"lng":-123.14044,"lat":49.20854},
{"timestamp":"2012-12-12T03:34:45.621Z","value":56.0,"lng":-123.14215,"lat":49.20855},
{"timestamp":"2012-12-12T03:34:49.122Z","value":55.0,"lng":-123.14727,"lat":49.20862},
{"timestamp":"2012-12-12T03:34:52.619Z","value":59.0,"lng":-123.14765,"lat":49.20868}]

example

curl --user {id}:{password} --request PUT --data-binary @data.txt
'http://wotkit.sensetecnic.com/api/sensors/test-sensor/data'

where data.txt contains JSON data similar to the above JSON array.

2.6.3. Deleting Data

Currently you can only delete data by timestamp, where timestamp is in numeric or ISO form. Note that if more than one sensor data point has the same timestamp, they all will be deleted.

To delete data:

URL http://wotkit.sensetecnic.com/api/sensors/{sensorname}/data/{timestamp}
Privacy Private
Format not applicable
Method DELETE
Returns HTTP status code; No Response 204 if successful

2.6.4. Raw Data Retrieval

To retrieve raw data use the following:

URL http://wotkit.sensetecnic.com/api/sensors/{sensor-name}/data?{query-params}
Privacy Public or Private
Format json
Method GET
Returns On success, OK 200 with a list of timestamped data records.

The query parameters supported are the following:

Name Value Description
start the absolute start time of the range of data selected in milliseconds. (Defaults to current time.) May only be used in combination with another parameter.
end the absolute end time of the range of data in milliseconds
after the relative time after the start time, e.g. after=300000 would be 5 minutes after the start time (Start time MUST also be provided.)
afterE the number of elements after the start element or time. (Start time MUST also be provided.)
before the relative time before the start time. E.g. data from the last hour would be before=3600000 (If not provided, start time default to current time.)
beforeE the number of elements before the start time. E.g. to get the last 1000, use beforeE=1000 (If not provided, start time default to current time.)
reverse true: order the data from newest to oldest; false (default):order from oldest to newest

Note

These queries looks for timestamps > “start” and timestamps <= “end”

2.6.5. Formatted Data Retrieval

To retrieve data in a format suitable for Google Visualizations, we support an additional resource for retrieving data called the dataTable.

URL http://wotkit.sensetecnic.com/api/sensors/{sensor-name}/dataTable?{query-params}
Privacy Public or Private
Format json
Method GET
Returns On success, OK 200 with a list of timestamped data records.

In addition to the above query parameters, the following parameters are also supported:

   
tqx A set of colon-delimited key/value pairs for standard parameters, defined here.
tq A SQL clause to select and process data fields to return, explained here.

Note

When using tq sql queries, they must be url encoded. When using tqx name/value pairs, the reqId parameter is necessary.


For instance, the following would take the “test-sensor”, select all data where value was greater than 20, and display the output as an html table.


2.6.6. Aggregated Data Retrieval

Aggregated data retrieval allows one to receive data from multiple sensors, queried using the same parameters as when searching for sensors or sensor data. The query must be specified using one of the following 5 patterns.

Pattern 1 - With Start/End

start The most recent starting time of the query. This value is optional and defaults to the current time.
end A timestamp before the start time.
limit Specifies the limit to return. This value is optional, with a default value of 1000.
offset Specifies the offset to return. This value is optional, with a default value of 0.

Pattern 2 - With Start/After

start A starting timestamp.
after A relative timestamp after start.
limit Specifies the limit to return. This value is optional, with a default value of 1000
offset Specifies the offset to return. This value is optional, with a default value of 0

Pattern 3 - With Start/Before

start A starting timestamp.
before A relative timestamp before start.
limit Specifies the limit to return. This value is optional, with a default value of 1000
offset Specifies the offset to return. This value is optional, with a default value of 0

Pattern 4 - With Start/BeforeE

start A starting timestamp.
beforeE The number of elements to return before start
offset Specifies the offset to return. This value is optional, with a default value of 0

Pattern 5 - With Start/AfterE

start A starting timestamp.
afterE The number of elements to return after start
offset Specifies the offset to return. This value is optional, with a default value of 0

The following parameters may be added to any of the above patterns: * scope * tags * private (deprecated, use visibility instead) * visibility * text * active * orderBy * sensor: which groups data by sensor_id * time (default): which orders data by timestamp, regardless of the sensor it comes from.

To receive data from more that one sensor, use the following:

URL http://wotkit.sensetecnic.com/api/data?{query-param}={query-value}&{param}={value}...
Privacy Public or Private
Format json
Method GET
Returns On success, OK 200 with a list of timestamped data records.