Connecting Onion Omega2 with nodejs



Taking advantage of free time this weekend, and recently recorded the Getting Started of the Onion Omega2 (so I have it on the desktop), I wanted to install nodejs (which I could not do in v1) and connect it to Cayenne using my recent library.

There is still no official library to control the omega2’s gpio, so I’ve used the shell commands (read about it here:

1. Update opkg
opkg update
2. Install Node.JS
opkg install nodejs
3. Install NPM
opkg install npm
4. Create a File for the Project Code
'use strict';
var Cayenne = require('cayenne-mqtt');

const spawn = require( 'child_process' ).spawnSync;

var options = {
  'clientId' : 'c1d7df70...',
  'username' : 'f671f020...',
  'password' : '6c7dbdf...',
  'debug': true

var Client = new Cayenne.Client(options);

var d = spawn( 'gpioctl', [ 'dirout', '1' ] );

var Ch4 = Client.Channel('4');

  if(msg == '1'){
	const dh = spawn( 'gpioctl', [ 'dirout-high', '1' ] );
  if(msg == '0'){
  	const dl = spawn( 'gpioctl', [ 'dirout-low', '1' ] );

5. Install libraries
npm install cayenne-mqtt
6. Run
node demo.js

Video demonstration pending!
At night I will record the video with the demonstration of the project working. Stay tuned! :wink:

And… the video is here:


**Thank you for your valuable material.
Node, npm.

How do I connect omega2 and cayenna?
Cayenna joined and connected to device
Should I connect with raspberry pie or api?
Please help me as a beginner.**