Node-RED

From Axel Public Wiki
Jump to navigation Jump to 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 (RECOMMENDED) 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.


Use the pre-configured Raspbian image Raspi.png

If you downloaded our pre-configured Raspbian (see Raspberry_Pi), 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 is the recommended way to use Node-RED with LogicLab.

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


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 (see above chapter).


Requirements

In order to make this package work, you have to install the JavaScript runtime Node.js, the package manager npm and Node-RED. Whether you installed our setup or a virgin Raspbian image, in both cases a version of Node.js and npm comes along with your installation.

Our packages are currently built and tested on versions v12.18.2 of Node.js and v6.14.4 of npm and so it is recommended that you have installed these releases, but they should also work for previous Node.js major releases since our nodes are build with N-API.


Install Node.js and npm

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

To download and install Node.js, it is recommended to download the binaries and install nodejs through apt-get:

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

Now install it by running:

sudo apt-get install nodejs

And finally check the versions:

node -v
npm -v

Additional information can be found here or here.

Install Node-RED

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

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

Further information can be found here.

Install the package

Download our package from here.

You do not need to move our package to a specific path, since all our libraries are referenced with relative paths.

The zip file comes with the package that will be installed by npm, a directory containing the Example project that you may want to test later and a txt file containing the release notes. Now you can install our package by this way (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 "X.X.X"):

unzip LLSymbols_Node-RED_raspberry_X.X.X.zip -d .
sudo npm install -g node-red-contrib-LLSymbols-X.X.X.tgz

This command will copy the whole content of the .tgz file into the directory containing the global installation on npm. 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 the path where all projects are saved for the Node-RED that is currently in execution:

 ~/.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

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 add them to the palette in order to make this example work. Please check this link for additional information.

By unzipping the LLSymbols_Node-RED_raspberry_X.X.X.zip file, you will see an Example folder. Please move it to the path containing all the projects created with your current execution of Node-RED:

~/.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.

Windows version Windows.png

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

Install Node.js, npm and Node-RED

1. Download the 32 bit or the 64 bit installer (they are both supported by Axel npm module) from nodejs.org and run it.

2. Add the module Node-RED with npm:

npm install -g node-red

Install our npm package

1. Download our package according to your 32/64 bit Node.js installation and unzip it:

- 32 bit

- 64 bit

2. Install the .tgz file (replace the 'X.X.X' substring with the number of the downloaded version):

npm install -g node-red-contrib-LLSymbols-X.X.X.tgz

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

Start Node-RED

node-red

General issues

If you are experiencing connection errors or problems regarding the debug tab of Node-RED not working properly and you are behind a Proxy, please make sure that it is configured to allow websocket connections through, or just disable the Proxy for your local addresses.




Node-red.png