Node-RED

From Axel Public Wiki
Revision as of 16:57, 2 July 2018 by Axelpwiki (talk | contribs)
Jump to navigation Jump to search

This wiki document describes all the steps required to work with the following two modules provided by our distribution package:

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.

Please be aware that this documentation page is intended for Raspberry PiRaspi.pngonly.

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 its dependencies on a new virgin Raspbian.


Manual setup on a virgin Raspbian image

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

If you downloaded our pre-configured Raspbian image, you don't have to follow this guide since Node-RED is already installed and set up to auto-start on boot.


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 LLSymbols_Node-RED-raspberry.zip from our website.

After that, move the .zip file 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 these steps:

cd /home/pi
unzip LLSymbols_Node-RED-raspberry.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.


Start Node-RED manually

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.


Enable the projects feature

It is highly recommended to enable the projects feature. In order to do this, you have to edit the settings.js file 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 already existing) the following option within the module.exports block:

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

Finally, you have to restart Node-RED.


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.zip file, you also got an Example folder; please move it to the following path:

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

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

Now restart Node-RED and open up a browser. Change the URL to your device address at port 1880 in order to open a Node-RED page.

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 work with them.


Use the pre-configured Raspbian image

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.


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 with

sudo reboot

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 package is RabbitMQ.

What is it

RabbitMQ is an open source message broker written in Erlang that implements the most used queue-based message protocols such as AMQP or MQTT.


Node-red.png