Data Processors

Data Processor

A data processor executes Octave commands on a given interval. GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments (http://www.gnu.org/software/octave/).

Users can upload their own Octave script to be executed or use standard commands and functions.
The maximum runtime of a data processor is 5 seconds, after 5 seconds the process will be terminated.
The output of the data processor is a new sensor data point.

To read sensor data from CommonSense the function getSensorData can be used:

function getSensorData(sensor_id, start_date, end_date)
  • sensor_id: the id of the sensor to get the data from
  • start_date: the start date in unixtime (optional)
  • end_date: the end date in unixtime (optional)

if no start and end date are given the last data point is returned.

This function returns a matrix with the following structure:

id, sensor_id, value, date

  • id: the data point id
  • sensor_id: the sensor id
  • value: the data value, JSON values are returned as a scalar structure
  • date: the date of the data point in unixtime

Example - Using data from a sensor with JSON structured values: sensor data value in JSON:

{"pitch":0,"roll":0,"azimuth":268}

Octave script:

data = getSensorData(710); % returns the last data point;
printf("id:%d\n",data{1}); % return the id of the data point
printf("sensor_id:%d\n",data{2}); % return the id of the sensor
printf("pitch:%d\n",data{3}{1}.pitch); % return the pitch value of the data point
printf("roll:%d\n",data{3}{1}.roll); % return the roll value of the data point
printf("azimuth:%d\n",data{3}{1}.azimuth); % return the azimuth value of the data point

CommonSense Octave scripts (for GNU Octave, version 3.4.3): commonsense-octave-scripts-v1.1.tar.gz

List data processors: GET /dataprocessors

Lists the dataprocessors of the user.

URLhttps://api.sense-os.nl/dataprocessors
MethodGET
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType
totalBy adding this parameter a total item count will be added to the result. xsd:integer
pageThis parameter specifies which page of the results must be retrieved. The page offset starts at 0. xsd:integer
per_page(opcontenttional) This parameter specifies the amount of items that must be received at once. The maximum amount is 1000 items and the default amount is 100 items. xsd:integer

Delete data processor: DELETE /dataprocessors/{id}

This method deletes the data processor.

URLhttps://api.sense-os.nl/dataprocessors/{id}
MethodDELETE
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

Create data processor: POST /dataprocessors

This method creates a data processor. A data processor is an Octave script that runs on a given interval.
Command is the octave command to execute. The output of the command is a new sensor data point for the supplied sensor. Command can be a serie of Octave commands and functions or any of the uploaded Octave scripts of the user.
execution_interval is the time in seconds between executions of the script. The minimum interval is 60 seconds.
The data processor can be connected to a sensor by supplying either a sensor id in the sensor_id field or a sensor object (see example) in which case a new sensor will be created.

URLhttps://api.sense-os.nl/dataprocessors
MethodPOST
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

Request Body

The data processor object

{
    "dataprocessor": {
        "command": "disp(rand);",
        "execution_interval": 60
    },
    "sensor": {
        "name": "random number generator",
        "data_type": "float"
    }
}

Update data processor: PUT /dataprocessors/{id}

This method updates the data processor.

URLhttps://api.sense-os.nl/dataprocessors/{id}
MethodPUT
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

Request Body

The data processor object

{
    "dataprocessor": {
        "command": "disp(rand);",
        "execution_interval": 60
    },
    "sensor_id": 1001
}

Test Data Processor: GET /dataprocessors/{id}/execute

This call can be used to execute a Data Processor in order to test it.

URLhttps://api.sense-os.nl/dataprocessors/{id}/execute
MethodGET
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

Create file: POST /dataprocessors/files/{filename}

Creates the file in the user's directory. Existing files with the same file name will be overwritten. The body of the POST request will be stored as the file data.

URLhttps://api.sense-os.nl/dataprocessors/files/{filename}
MethodPOST
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

List files: GET /dataprocessors/files

Lists the files to which the data processors have access.

URLhttps://api.sense-os.nl/dataprocessors/files
MethodGET
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

Delete file: DELETE /dataprocessors/files/{filename}

This method deletes the file with the filename

URLhttps://api.sense-os.nl/dataprocessors/files/{filename}
MethodDELETE
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType

List sensor data processor: GET /sensors/{id}/dataprocessors

Lists the data processor that is the input for this sensor

URLhttps://api.sense-os.nl/sensors/{id}/dataprocessors
MethodGET
Need AuthTrue

Request Headers

NameDefaultTypeStyleRequired
Accept*xsd:stringheaderTrue

Request Parameters

NameDescriptionType