LoRaWAN-and-Node-RED-Tutorial-and-Deployment-Tips-(Part II)

This series is intended for developers and hackers looking to test out a LoRaWAN network using MultiTech’s Conduit and mDot RF modules. The Things Network has an extensive forum and support for public gateways and nodes in Europe, but little documentation exists for those wanting to test a private network in the US.

This is the second post in a four part guide which covers:

  1. Configuring the Conduit & Starter Kit
  2. Node-RED & Bypassing IBM Bluemix
  3. Programming MultiTech Developer Kit & Adding Sensors
  4. Using the mDot, xbee shield, and Arduino

Node-RED & Bypassing IBM Bluemix

This post will focus on using Node-RED and bypassing the built-in IBM Bluemix connection so you can connect to the cloud service of your choice. The example here will use Azure’s IoT Hub, but the instructions should translate to any cloud service.

Node-RED on the Conduit

If you have the Conduit AEP version, Node-RED should already be installed on the gateway under Apps. It might be disabled by default with some weird behavior with firmware version 1.3.2, so you can either enable it every time it fails you or download firmware 1.3.3 and fix the issue more permanently.

It takes a while to open up Node-RED the first time. If it gets stuck in the loading page, you can ssh into the gateway, locate the node-red logs under /var/log/app/node-red.log and find the error. Commonly, firewall settings might prevent Node-RED from working, so check the Settings on the gateway.

Adding Custom Nodes to Node-RED

To add a custom node to Node-RED on the Conduit, you need to ssh into the gateway and follow these instructions:

ssh admin@<your-ip-address>
cd /opt/node-red/nodes

You only have access to admin and not root. Node-RED documentation says npm installed files will be in the $HOME/.node-red/nodes directory, but that does not exist on the gateway.

The nice thing is that npm is already installed on the gateway, so you can just issue npm install in the directory.

npm install node-red-azure-contrib-iot-hub

Now you must restart the Conduit using the web UI to properly update the .config.json file in /var/config/app/install/development directory.

Problem #1

You might get an error complaining about:

File exists: /home/root/.npm/5843fb3f-root-npm-debug-2-6-0-package-tgz.lock Move it away, and try again"

Even if you remove that file and reinstall, you will get the same message. To fix this issue, you can take the following steps.

npm -g install [email protected]
cd /opt/node-red/nodes
npm install node-red-contrib-azure-iot-hub

It will throw an error about npm not supporting Node.js v0.10.4. Apparently MultiTech is not going to update to newer versions of Node until it can run newer instructions on the ARM processor. After a painfully slow installation process, you should now see azure-iot-hub icons.

Problem #2

Now if you follow the Azure IoT Hub npm documentation, you will most likely run into the following error:

TypeError: undefined is not a function

It sometimes complains that node.log is not a function and in the end, I could not figure out why it wasn’t working. My best guess is that some of the dependencies require a higher version of Node.js. If you figure this out, please send me a message!

Problem #3

At this point, I decided to just delete this node and reroute the messages to Bluemix. Then I ran into this issue:

Error: node not deployed

This happens if you have configuration nodes (e.g. IoT-Hub, MQTT client) left hanging and not deployed. To find these, you can click the Menu → Sidebar → Configuration nodes and double click on unconfigured nodes to delete. I made the mistake of deleting the node_modules folder and reinstalling everything, which took forever. (You can just load the firmware on it to restore the files that way.)

Problem #4

After a while, I was rerouting messages from IBM Bluemix to Azure IoT Hub, then one day I came across this issue all of a sudden.

Error while trying to send message:Error: getaddrinfo ENOTFOUND undefined undefined:8883

I was confused, because I didn’t change a single thing and it was failing on me. This hasn’t been confirmed, but my guess is that the SAS token generated by the node-red module expired. This problem went away when I took down Node-RED and redeployed using IBM CLI.

Solution: RTFM

Hidden on the MultiTech docs is this beautiful document: “Connect Node-RED to Any Cloud Services’ REST API.” I could not get MQTT working with IoT-Hub, but at least HTTP works if you set the Headers correctly as shown in the example.

*** Update on May 5, 2017: See Multitech’s forum on getting Azure IoT Hub to work with MQTT courtesy of Peter Ferland. You need to inject a “protocol” entry in the node’s payload. ***

    "protocol": "mqtt", 
    "deviceId": "<your device id>", 
    "key":"<your key>", 
    "data":"<your json data>" 

Sign up for IoT for All’s newsletter!

Last Week in the Future is our weekly newsletter, covering the latest and greatest in IoT, AI, and other tech fields from last week.