BeagleBone Green and Cayenne via MQTT

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

  1. Add new device.

  2. Run the example code (index.js) see details above.

  3. Add new widget (Led) using Channel “1”

  4. 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);

var Ch1 = Client.Channel('1');

  if(msg == '1') myLed.write(1);  
  if(msg == '0') myLed.write(0);  
1 Like

@laurencehr great stuff. Just curious why did you end up creating a node lib for cayenne? It looks like they have an official node lib.

Oh well! I wasn’t see these library… I will test the cayenne library :wink: thanks for advice

But If you see my way (in my library) I handle each Channel independently, I think that is better because I can do interact the Channels, or code actions independently, (code look better).

Anyway I will talk with Cayenne team, for improve the official library :wink:

Nice! Maybe I’ll finally make that node-red node now that I can just require the official version.

1 Like