Intel Edison + Arduino Kit + Grove Starter Kit + MQTT + Node.js

Hello,
For those that want to use Node.js on Intel Edison, I will show how to send data to the Cayenne dashboard using Cayenne JS library. Some of the steps are initial and are the same as my other post about running this device with python.

Except the Edison Board, I have Arduino Kit and some sensor (temperature) connected to the Grove board that comes with the Grove starter Kit.

FIRST, please setup the Intel Edison Board. I have gone through all the process step by step from the official page of Intel Edison board here1. It is not more than 15 minutes process, but is very important. Also there you will learn all the basics that you need to know about this devices as well as how to assemble it and which port is used for what.

After you are done - you have to choose your IDE. You can skip this step if you know how to connect to your device by serial connection. For beginners I recommend to install Intel XDK - this is a whole separate software platform (IDE) that gives you a lot power. It is created for JAVASCRIPT programming (Node.js) with the device, but there you have integrated both serial, ssh and system terminals, that are on one place. Also you can connect easy the device to the WiFi. You have as well a good examples already written on Node.js Please take no more that 5-10 minutes to explore the software for future use.

The Interesting Part:

After you go through all the steps and setup the device and connect it to the WIFI, please open the Intel XDK Platform.
You have to select the desired device from the drop down list as showed bellow:

If your device is not found, please insert “Rescan”.

  1. After your device is listed, select it and another screen like this bellow is showed:

You can populate your data and insert the “Connect” button.
2. You will see a connected message and also the Intel XDK IoT tab will look something like this:

This means that your software (Intel XDK) is connected to the device and you can download source code to the device directly with the buttons above.
3. You have to make a new project from the up left corner button “Project”. After you click this button, there is a button on the left down corner “Start a new project”


4. Then on the next screen, you have to choose the tab with “Templates” and choose a new blank project (the first blue icon on the left):

After you are done with the creation of the new project. We have to install the cayenne dependencies.
5. Open the ssh console and type: npm install cayennejs
6. After the command is complete successful, we can start coding. Open the main file of the project, in this case: main.js and delete the sample code that was generated.

I have connected the temp sensor on analog pin A1.


Enter this code:

var Cayenne = require('cayennejs');
var sleepTime = require('sleep-time');
var groveSensor = require('jsupm_grove');
var temp = new groveSensor.GroveTemp(1);

// Initiate MQTT API
const cayenneClient = new Cayenne.MQTT({
  username: "username",
  password: "pass",
  clientId: "id"
});

cayenneClient.connect((err, mqttClient) => {
    //var celsius = temp.value();
    setInterval(function() { cayenneClient.celsiusWrite(3,temp.value())}, 10000);
  // dashboard widget automatically detects datatype & unit 
  // sending raw values without datatypes
  //cayenneClient.rawWrite(4, 123);
  // subscribe to data channel for actions (actuators)
  cayenneClient.on("cmd9", function(data) {
    console.log(data);
  });

});

Don’t forget to generate Username, Password and ID as you add new “Bring your own device” in the dashboard.
7. After completing this operation, you have to download the code to the device. This is done with the following button in the Intel XDK IDE:


8. After the code is downloaded, you have to run your code with the following button:

Congratulations! You are ready. Reload the dashboard and the temperature widget should be added automatically.


Enjoy :slight_smile:

3 Likes

Another very nice step by step project, thanks for sharing!

what does this command line do?

I moved this to “The Library” category :slight_smile:

~Benny

Hello @shramik_salgaonkar
This line is doing the following: subscribe to data channel for actions (actuators)