It is possible to send your own data to Databoom server using HTTP requests. In order that the parameters are interpreted correctly, you must use a particular format. Follows the procedure for Node.js.
request module
For the creation of an HTTP request in Node.js the request module is used
npm install request
In your code the following fragment is then required:
var request = require('request');
Parameters structure
The parameters to send must be in JSON format, in particular we use the following structure:
var post_data = {
device: <DEVICE TOKEN>,
date: new Date().toGMTString(),
signals: []
};
device is the token of your own device, while date is the communication date (in the example we use the current date). The token is generated by Databoom when creating the device, and can be retrieved in the edit screen of the required device. signals is the array that will contain device parameters. To insert parameters we proceed:
var signal_info = {
name: <PARAMETER NAME>,
value: <PARAMETER VALUE>
};
post_data.signals.push(signal_info);
If you want to update a signal that is already in Databoom, name must correspond to the token. If the signal is not in Databoom, it is inserted using name as token. The value must be unique within the device.
It is also possible to forward to Databoom the values history of a signal. In this case the data format to follow is:
var post_data = {
device: <TOKEN DEVICE>,
date: new Date().toGMTString(),
signals: {}
};
Where signals is an object structured as follows:
signals : {
<SIGNAL TOKEN>: {
description: <SIGNAL DESCRIPTION>
history: [{
date: <VALUE DATE>
value: <SIGNAL VALUE>
},
...
]
},
...
};
signals can contain more signals, using their tokens as keys, and every signal can contain more values in the history array.
Data forwarding
Once the data cration has ended, it is possible to proceed with their forwarding to Databoom server. Before sending the request, its options must be setted:
var options = {
uri: data_api,
method: 'POST',
headers: {
'Authorization': 'Bearer ' + oAuth_token
},
json: post_data
};
data_api is the Databoom API. to push data, while oAuth_token is a user generated token in Databoom. The values to replace are:
var data_api = https://api.databoom.com/v1/signals/push;
var oAuth_token = <OAUTH TOKEN DATABOOM>;
Once the options are ready, it is finally possible to proceed with the actual request:
request(options, function (error, response, body) {
...
});
Configuration completed!
Once the procedure has been completed, Databoom starts to record data sent with HTTP. To examine your data and have a correct representation, follow the instructions in Edit/validation of a signal.
1 Comments