In this example we will write an Oficloud project for sending the data obtained form an Oficloud channel to the ThingsBoard Live Demo. You need to create a free personal account. You also can download ThingsBoard Community Edition and use it in your own server. In that case you should install the script of this example in that server.
STEPS
$ git clone https://github.com/juanjo75es/oficloud-sdk-base .
$ npm install --save mqtt
var oficloud = require('./oficloud');
var mqtt = require('mqtt')
var options={username:"YOUR_THINGSBOARD_KEY",password:""};
var client = mqtt.connect('mqtt://demo.thingsboard.io', options);
client.on('connect', function () {
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
})
oficloud.login('myuser@myemail.com','MYPASSWORD',function(res){
console.log("login res: "+res.res);
if(res.e==-1)
return;
function onmsg(msg)
{
//Process received messages here
client.publish("v1/devices/me/YOUR_THINGSBOARD_PROJECT_NAME", JSON.stringify(msg))
}
oficloud.open_channel('p',onmsg,function(err){
if(typeof err !="undefined")
{
console.log("open channel error: "+err);
return;
}
//Do your stuff here once you are logged in and joined a channel
//(...)
})
});