Databoom provides the possibility to connect your own device with the dedicated PubNub channell. In order to transmit the data, it is necessary to create a client that sends the parameters in the required format. Follows the procedure for Node.js.
pubnub module
For the creation of a PubNub client in Node.js the pubnub module is used
npm install pubnub
In your code the following fragment is then required:
var pubnub = require('pubnub');
Initializing PubNub in Node.js
In order to communicate with the dedicated channel, it is required to initialize pubnub as follows:
pubnub = pubnub.init({
publish_key : <PUBLISH KEY>,
subscribe_key : <SUBSCRIBE KEY>,
auth_key : <AUTH KEY>,
uuid: <DEVICE TOKEN>
});
The keys to replace for Databoom channel on PubNub are:
publish_key: 'pub-c-5e3c4a17-db74-4265-b1c9-861b15f29aca'
subscribe_key: 'sub-c-ce6cb094-2311-11e5-a6f9-0619f8945a4f'
auth_key: 'device'
uuid is your device token. auth_key authorizes the connection to the channel.
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().toISOString(),
apikey: <API KEY>,
signals: []
};
device is the token of your own device, it is retrieved from the settings of the client created in the previous step, while date is the communication date (in the example we use the current date). <API KEY> is your personal key, you can see it in your profile. 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.
Publishing data on the channel
Once the data cration has ended, it is possible to proceed with their publication on Databoom channel
pubnub.publish({
channel : 'databoom',
message : post_data,
callback : function(e) { console.log( "SUCCESS!", e ); },
error : function(e) { console.log( "FAILED! RETRY PUBLISH!", e ); }
});
The channel must be setted to databoom otherwise the data will be ignored. As message we use post_data. You can also specify the operations to do in the callback and in case of error.
Configuration completed!
Once the procedure has been completed, Databoom starts to record data sent with PubNub. To examine your data and have a correct representation, follow the instructions in Edit/validation of a signal.
0 Comments