DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

Installing Node-RED on a Synology NAS



Setting up Node-RED and getting data from a Things Node connected to The Things Network

Having got my Things Node (135-9784) successfully reporting the temperature I wanted a way of making the data publicly available. I looked around at various options; I had already tried AllThingsTalk Maker and Cayenne, but it appears that people have to sign up for an account before you can share data with them. I wanted something more open than that, so I looked at Node-RED.

I have a Synology Diskstation at home (pictured above, all alone in its cupboard) — a NAS that runs its own proprietary Linux-based operating system, DSM, that I thought should be able to run Node-Red, which would allow me to share data via a web site, email or even Twitter.

I found a discussion topic that got me started. One option was to install it using Docker, but that’s only available on the higher-end Disktations, whereas mine is a lowly DS214.

Using Secure Shell (SSH)


Node RED is dependant on Node.js being installed on your Diskstation and you also need to make sure user home service is enabled in the Control Panel under user > advanced > user home. I already had that enabled and Node.js installed, so I went ahead with the Node-Red install.

I needed to SSH into my NAS to install Node-Red. As I was working on a Windows PC I used PuTTY for that, but any equivalent SSH client would do. I also needed to enable SSH on the Synology Diskstation – a setting you will find in the “Terminal & SNMP” link in the Control Panel of DSM. While you are there take a note of the port number, you’ll need that for your SSH client.


Once I had connected to the Diskstation and logged in I could install Node-RED using the command from https://nodered.org/docs/getting-started/installation

sudo npm install -g --unsafe-perm node-red

Once it has run through the installation process you simply type ‘node-red’ to start it up.

Automatically starting Node-RED


Look for the line displayed in the terminal window when you start it up that says [nas-ip-address]:1880 and that is the URL to view the User Interface. Now I needed to get it to start up automatically at boot. To do this I installed pm2, a process manager for Node.js, by entering:

sudo pm2 npm install -g pm2

And that successfully started Node-RED as a daemon, which meant it carried on running when I logged out of my SSH session.

What I could not do is get the pm2 start-up option to work. This may be due to a quirk of the Synology or it may have been my error but I decided to sidestep the problem by using Synology’s own Task Scheduler. I wrote a simple script and set up the Task Scheduler to run it at boot.

#!/bin/sh
HOME=/root
source $HOME/.profile
PATH=/opt/bin:/opt/sbin:$PATH
/usr/local/bin/node-red


I then wanted to make the installation more secure, so I followed the instructions here and edited the settings.js file which was in my in the .node-red folder which in turn was in my Synology home folder.

The Things Network nodes


So far, so good. The next thing was to install The Things Network nodes in Node-RED. I followed this quide, but kept getting error messages. I worked out this was due to having an old version of Node.js installed. I should have read the beginning of the Node-Red Installation guide more carefully and looked a bit more closely at the Node-js package on the Synology. It was version 4 that had installed with the Drive package (Synology’s own very good “Drop-Box” like app).

I decided the safest thing would be to uninstall Node-Red, install Node.js version8 and then re-install Node-RED, which should use the latest Node.js version by default.

I disabled the Start on Boot task and re-started the NAS, then used PuTTY / SSH again and used:

sudo npm uninstall -g node-red

Then deleted the .node-red folder in my Synology home folder.

I next installed Node.JS v8 using the Synology’s Package Manager and re-installed Node-RED.

Unfortunately, the Things Network node still would not install in Node-RED. I tried repeating the uninstall process and install Node.js v6 but still no luck. The only thing that worked was the version 1 of the Things Network node that you install with

npm i node-red-contrib-ttn@1.0.0

As detailed here

I tried installing other nodes and they worked so I’m not sure what it is that the Synology and the Things Network Nodes disagree about.

Getting around the problem

Once again I decided to sidestep the issue by using the MQTT nodes that come bundled with Node-red.

For those of you that have not used Node-RED, it is a tool for wiring together devices and services using a browser-based editor that lets you simply drag and drop the things you want to wire together into the workspace, and drag wires between them. It is a very pleasing graphical interface that makes it relatively simple to get things up and running.

I dragged an MQTT input node from the ‘palette’ on the left, onto the workspace followed by a debug output node and wired the two together. Now I just had to edit the MQTT node so it connected to my Things Node and started getting data. When I had got it set up I would them see the data under the Debug tab on the right.


To connect to the Things Network I gave the server a name – TTN Broker – then clicked on the pencil icon to edit its details.

 


The information I needed was:

  • The Things Node server – eu.thethings.network
  • Port – 1883
  • Username – my App ID on the Things Network
  • Password – the App Access Key

Click ‘Update and you are taken back to the node properties page.

After a bit of help I worked what to put in the Topic field:

+/devices/+/up/temperature

The ‘+’ is a wildcard so this was setting the topic to subscribe for any device sending uplink and get the data in the temperature field.

I edited the debug node so the Output was msg.payload, made sure ‘debug window’ was ticked and clicked Done.

After each change or edit you need to click the ‘Deploy’ button in the top right-hand corner of the main Node-RED window, which I did and after a moment could see data being displayed under the debug tab.


Telling the World the temperature at Pecket Well


I decided I would send the Temperature to my email. I dragged the Email Out node on to the canvas, double clicked it and entered my email details, clicked Done, then Deploy. And as simple as that I started getting messages like this:

I thought that could benefit from a bit of tidying up. A function node wired between the MQTT and the Email nodes, would pass the message through a JavaScript function.

 

Drag the Function node onto the work surface, double-click it to edit, enter the following ..

msg.payload = 'The temperature is: ' + msg.payload + 'C';

msg.topic = 'Pecket Well Temperature'
msg.to = 'dave@abopen.com'

return msg;

… wire it all up and click “Deploy” and this is the resulting email:

I could also easily add other people’s email addresses and use JavaScript conditional statements to only send messages if it was cold, or hot, for example.

Conclusion


This has not been a straightforward exercise by any stretch of the imagination, but I was trying to get the Synology Diskstation’s DSM OS to do something it was not really designed to do, and in the end, I have achieved what I set out to do. I can share the temperature data from my Things Node with anyone who wants it.

 

I currently look after production at AB Open. I have a background in the arts, environmental conservation and IT support. In my spare time I do a bit of DJing and I like making things.

29 May 2018, 8:10

Comments

April 11, 2019 07:55

This is the end of my installing and after a tried to start node-red.

0 Votes

April 11, 2019 07:55

Hello,
I tried to install node-red on my Synology DS116, but it not work. I made screenshots. What was the problem? Can You help me?

0 Votes

[Comment was deleted]

[Comment was deleted]

[Comment was deleted]

[Comment was deleted]

[Comment was deleted]

November 30, 2018 22:02

Hi, I have a synology nas 213j. Installed the node-red with some error, but it is run good and working from console. My problem is I cant run it in the background. When close the console close the node-red too. Tryed to install what in the instruction, pm2 but have some error too and when want to start pm2 get this: command not found.
How can I run in background node-red? Need help please.

0 Votes

December 3, 2018 10:20

@Spider2 Hi - installing and running pm2 fixed this for me. It's mentioned in the article

[Comment was deleted]

August 20, 2018 09:44

Hello,

I'm getting the same error all the time. Please see the screenshot. I am using a Synology DS416, Version: DSM 6.2-23739 Update 2.

I think the main problem is this:

Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v2.0.1/bcrypt_lib-v2.0.1-node-v57-linux-arm-unknown.tar.gz

This directory doesn't exist anymore. I tried to install bcrypt itself with no luck.

I think this causes that I can't start "node-red". I get the answer: command not found.

Do you have any ideas?

0 Votes

June 12, 2018 08:19

@Dave, this is my test reply. If you can see this, then I suggest contacting the web support.

June 12, 2018 08:19

@Boss yes I can see this

June 8, 2018 12:51

tried the above install , when entering "node-red" i get a command not found error

0 Votes

July 23, 2018 08:13

@leeb98 I had the same thing. Managed to find the map and run "node red" from there (without the dash). The location for me was "/volume1/@appstore/Node.js_v8/usr/local/lib/node_modules/node-red" but i found it by looking at the ouput when installing node-red.

June 12, 2018 08:19

@leeb98 that's strange. You might find some helpful info here - https://nodered.org/docs/getting-started/running