Node-RED

From Axel Public Wiki
Jump to: navigation, search

This wiki document explains how to install and configure our Node-RED modules. At the moment, we have developed the following ones:

GetTagValue.png

SetTagValue.png

These nodes interact with LogicLab and their aim is to, respectively, read/write a value for a requested symbol target.

After the installation, these nodes will appear into the function tab of the palette.

Follow the guidelines taken from the section that fits with your own specific case, since you could use our pre-configured Raspbian image or, on the other hand, manually install our package, Node-RED and all its dependencies on a new virgin Raspbian. Instead, the last section provides you information on how to install our package on Windows.


Manual setup on a virgin Raspbian image Raspi.png

This section explains how to manually install our package on a virgin Raspbian image.

If you have downloaded our pre-configured Raspbian, you don't have to follow this section since Node-RED is already installed and set up to auto-start on boot: skip to the section explaining how to use our package on our configured image.


[ Requirements ]

In order to make this package work, you have to install the JavaScript runtime Node.js, the package manager npm and Node-RED.

Note: The package has been developed and tested with v8.11.1 of Node.js and v5.6.0 of npm.


Install Node.js and npm

The package manager npm is provided along with the Node.js installation package.

Open up a terminal and execute the following commands:

sudo apt-get update 
sudo apt-get dist-upgrade
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Now you can check that both Node.js and npm have been installed with:

node -v
npm -v

Look here for further details.

Install Node-RED

You can install Node-RED using the following npm command:

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

Ignore any error regarding the module node-pre-gyp.

Further information can be found here.


[ Install the package ]

Download our package from here.

After that, move the file you just downloaded to the following path:

/home/pi/

Now open up a terminal, unzip the file and change the directory path to the folder where Node-RED had been installed. After that you can add the package by using the appropriate npm command (the following commands summarize all these steps; please note that you have to insert the correct version of the zip file for the following command instead of "XXX"):

cd /home/pi
unzip LLSymbols_Node-RED_raspberry_XXX.zip -d .
cd /usr/lib/node_modules/node-red
sudo npm install /home/pi/LLSymbols_Node-RED

Now you are ready to start Node-RED, but before that it's highly recommended that you enable the projects feature for your Node-RED installation.

[ Enable the projects feature ]

If you want to open and close projects as you please, you have to edit the settings.js file sited into your Node-RED installation folder.

If you have followed the steps above, the settings.js file should be located at this path:

 /home/pi/.node-red/settings.js

Now edit it by adding or modifying (if it's already there) the following option within the module.exports block:

 editorTheme: {
       projects: {
           enabled: true
       }
 },

Finally, you can start Node-RED manually or by configuring it to start up on boot.


[ Start Node-RED manually ]

Our nodes are designed to interact with LogicLab: open the project whose variables you want to read/write, then connect to the target and download the code.

Now you can start Node-RED with the following command:

node-red start


[ Configure Node-RED to auto-start on boot ]

In order to make Node-RED auto-start on boot, please execute the following commands:

sudo wget -O /tmp/download https://gist.github.com/bigmonkeyboy/9962293/download 
sudo unzip /tmp/download -d /etc/init.d
sudo chmod 755 /etc/init.d/nodered
sudo update-rc.d nodered defaults

You can check further information from here.


[ Run the Example project ]

Note 1: you have to enable the projects feature in order to make this example work.

Note 2: you have to install the dashboard nodes and then add them to the palette in order to make this example work. Please check this link for additional information.

When you unzipped the LLSymbols_Node-RED_raspberry_XXX.zip file, you also got an Example folder; please move it to the following path:

/home/pi/.node-red/projects/ 

This project is binded to the LogicLab example named RaspPI_PlcSample: open it from LogicLab, then connect to your target and finally download the code.

Now open up a browser and set the URL bar to your device IP address at port 1880: you should see a Node-RED empty flow.

The next step consists of setting our project as the active one by creating a new empty project from Menu > Projects > New and by giving it a default name of your choice: this is not relevant to our goal, but this custom project is just created with the aim to enable the Open choice into the Projects tab of the Menu, since this one is disabled if you have never created at least one project by yourself.

After that choose our example from Menu > Projects > Open > Example.

Now you should be able to see the example flows and you can start working with them.

Use the pre-configured Raspbian image Raspi.png

If you downloaded our pre-configured Raspbian, you don't have to do anything more since Node-RED is already set up to auto-start on boot and, as a result, ready to be used.

This image already comes with the project feature enabled and the dashboard and MySql nodes added.

This section only gives you the information required to run the Example project and, if it is of interest, to enable the pre-installed MQTT message broker.


[ Credentials ]

If you want to access to the command line, you can log in with the default user pi by specifying the following credentials:

user: pi
password: axel


[ Run the Example project ]

The Example folder containing the project core is already located at the requested path (i.e. /home/pi/.node-red/projects/).

This project is binded to a LogicLab sample named RaspPI_PlcSample: open it from LogicLab, then connect to your target and finally download the code.

Reboot the system and then open up a browser and change the URL to your device address at port 1880 in order to open a Node-RED page.

You have to set our project as the active one: click on the menu button that you can see on the top-right side of your Node-RED page, then select Projects > Open > Example.

Now you should be able to see the example flows and work with them.


[ RabbitMQ ]

Our pre-configured Raspbian also has an interesting package that you can interact with through the MQTT nodes provided by Node-RED: this is RabbitMQ.

What is it

RabbitMQ is an open source message broker written in Erlang that implements the most widely used queue-based message protocols such as AMQP or MQTT. You can check additional information from here.

Enable it

Since it is disabled by default, if you want to use it you have to allow it to auto-run on boot with the following command:

 sudo systemctl enable rabbitmq-server 

then reboot the system.

Now you should be able to use the MQTT nodes inside Node-RED and you can also check the RabbitMQ management dashboard at port 15672 of your device. The credentials to access the dashboard are the following:

username: pi
password: axel

Use the MQTT nodes

Now you can use the two Node-RED nodes to publish messages and to subscribe to specific topics of interest. Configure them with the IP address of the device that is running the RabbitMQ server service.

Disable it

If you enabled RabbitMQ, but you don't want to use is anymore, write this from command line:

 sudo systemctl disable rabbitmq-server

then reboot the system.


[ Disable / Re-enable Node-RED on boot ]

This image comes with Node-RED ready to be used, but since you may want to run it manually to inspect the debug messages within the terminal, you can stop it from starting up on boot with the following command:

 sudo systemctl disable nodered

and then reboot the system. Now start Node-RED from command line with

 node-red start

to view the messages related to your nodes.

Obviously, you can always set Node-RED to start up on boot again with:

 sudo systemctl enable nodered


Windows version Windows.png

If you want to configure our package on Windows, first of all you have to install both Node.js, npm and Node-RED.

[ Install Node.js, npm and Node-RED ]

Download the 32 bit version of the Node.js installer from here and run it.

Now install Node-RED from command line:

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

[ Add our package ]

Download our zip from here and extract it into a folder you want. Copy the path to that folder (for instance, let's assume it's equal to PATH\TO\FOLDER) and type the following command:

npm install PATH\TO\FOLDER\LLSymbols_Node-RED

Now you should be able to start Node-RED and ready to use our nodes.

[ Start Node-RED ]

Type the following command:

node-red




Node-red.png