Introduction: Subscribing to a Helium Atom With Node

Picture of Subscribing to a Helium Atom With Node

Helium is a complete wireless platform for the internet of things, supplying integrated hardware, software interfacing, and infrastructure to easily, efficiently and securely connect objects to the internet. Helium has several SDKs for connecting to its wireless transceiver, the Atom. In this tutorial I will show you how to subscribe to your Helium Atom using the Node SDK, nodehelium.

Other helpful Helium resources include:

Helium Blog

Helium Forum

Helium Docs

Step 1: Installations

The Node SDK used to speak with the Helium Network is nodehelium, a binding around the C SDK libhelium.

Since nodehelium is a binding, libhelium must first be installed. If you have OS X there is a prepackaged installer available lower on that page that does all the heavy lifting for you. Instructions for manually building libhelium on OS X and Linux arealso included there. For Windows users a walkthrough is available here: Building libhelium on Windows.

After libhelium is installed, nodehelium can be installed on top of it.

To unpack the data coming from the Atom install Node MessagePack. MessagePack is similar to JSON, but more compact. Once the data is unpacked JSON can be utilized for all other conversions if desired.

Step 2: Code

For this exercise we are using a test device with MAC address 000000fffff00001 and base-64 token kdTl6U1w+sR61NBiQjm8sw==.

Include the required libraries. libhelium does not need to be explicitly included.

var helium = require('nodehelium');  
var msgpack = require('msgpack');   

Create a new Helium connection, then open in.

obj = new helium.Helium();;  

Set the MAC address and corresponding token for the device you are connecting to. Tokens can be found by registering your device's MAC address on your Helium Dashboard. The token is used to decrypt the secure data coming from your Atom.

var token = "kdTl6U1w+sR61NBiQjm8sw==";  
var mac = "000000fffff00001"; 

Every time a message is received we want it to be unpacked and displayed in the terminal. We can do this by triggering those functions every time obj receives a 'message'. The data object includes both a MAC address and a message, so you must specify the message be unpacked.

obj.on('message', function(data){  
	var message = msgpack.unpack(data.message);  

Finally, subscribe to your Atom.


This complete code can be found here.

Step 3: Run Your Code

Picture of Run Your Code

I prefer to run mine in the terminal. To do that open the terminal and cd yourself into the folder containing your program. When in the proper location enter:

node yourfilename.js 

You should see your device's messages coming up in the terminal. Strike ctrl+c to end the program.

If you need additional help, be sure to check out the Helium Forum.

Thank you, and have fun making!