Hi everyone,
after many days and weeks, I got connected my BBG (my favorite board) to Cayenne using MQTT API. I prefered to use BBG instead of Raspberry because, BBG has native Analog Input.
BBG has bonescript, but in my case this doesn’t work, then researching in Internet I found mraa library
Prepare your Dashboard
- Add new device.
- Run the example code (index.js) see details above.
- Add new widget (Led) using Channel “1”
- Try and Fun (video record is comming).
What’s Needed to Code
- NodeJS v6.*
- MRAA Library v1.*
npm install mraa@1.*
- MQTT Library
- Cayenne MQTT Library
npm install cayenne-mqtt
Example Code (index.js)
var m = require('mraa'); //require mraa
console.log('MRAA Version: ' + m.getVersion()); //write the mraa version to the console
var Cayenne = require('cayenne-mqtt');
var myLed = new m.Gpio(60); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)
myLed.dir(m.DIR_OUT); //set the gpio direction to output
var options = {
'clientId' : 'your-client-id',
'username' : 'your-username',
'password' : 'your-password'
}
var Client = new Cayenne.Client(options);
Client.connect();
var Ch1 = Client.Channel('1');
Ch1.on('message',function(msg){
if(msg == '1') myLed.write(1);
if(msg == '0') myLed.write(0);
});