Databoom provides the possibility to connect your own device with a server (broker) through MQTT protocol. 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.
For the creation of a MQTT client in Node.js the mqtt module is used
npm install mqtt
In your code the following fragment is then required:
var mqtt = require('mqtt');
Creation of a MQTT client in Node.js
The creation of the client follows the structure:
clientId is the token of your own device. The token is generated by Databoom when creating the device, and can be retrieved in the edit screen of the required device. To connect to the broker you need to authenticate yourself with your username and an OAuth token. The address of Databoom broker is mqtt.databoom.com, on port 1883, so we use mqtt://mqtt.databoom.com:1883.
The parameters to send must be in JSON format, in particular we use the following structure:
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, if the field is not specified, the receive date is used instead). The device field can be skipped, in this case the token from the topic is used instead. signals is the array that will contain the device signals. Signals consists of name, that is the signal token, and value.
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.
The parameters are then parsed to string so they can be sent to the topic of the broker correctly
post_data = JSON.stringify(post_data);
Publishing data on the topic
Once the data cration has ended, it is possible to proceed with their publication on the topic of Databoom broker
The topic must be setted to databoom/DEVICE TOKEN/data (otherwise the data will be ignored). post_data must be a string. In the callback are then showed some log messages to confirm parameters sending.
It is also possible to subscribe to the events topic databoom/TOKEN DISPOSITIVO/events to supervise events of the device, as for example published data reception confirm.
To send a command to the device, the topic to use is databoom/DEVICE TOKEN/commands. By sending a commmand, an event is created in Databoom.
The syntax to use is:
"description":"", //EVENT DESCRIPTION
"signal":"", //SIGNAL TOKEN
"tags":["",""] //EVENT TAGS
The payload can vary according to the format required by the device. It is also possible to subscribe to the same topic to verify the forwarded data.
For testing purposes, you can use the reserved ID debug for your client. With the debug ID it is possiblo to publish or subscribe to every topic (data, events o commands) of devices of which you are administrator or creator.
Once the procedure has been completed, Databoom starts to record data sent with MQTT. To examine your data and have a correct representation, follow the instructions in Edit/validation of a signal.