====== Set up and use Modbus TCP on the router ======
===== Goal =====
Set up an LXC container with a Node-RED function. A 7KN Powercenter 1000 data transceiver is integrated into Node-RED, which can be queried via Modbus TCP. Additional end devices can transmit data to the Powercenter via the energy monitoring system and be queried via Modbus. The data is stored in a structured format in an Influx database and can then be virtualized using Grafana.
{{:app-notes:modbus_aufbau.jpg?700|}}
===== Prerequisites =====
* NetModule Wireless Router with wireless connection
* NetModule Software [[https://share.netmodule.com/public/system-software/4.9/|5.0.0.100]] or newer
* A license is required for the LXC container
* Not available for legacy products NB1600, NB2700, NB3700, NB3710
**
The wiki was tested with router software 0.0.0.0 and the LXC container with Debian armhf bookworn.
**
===== - Setting up an LXC container and then implementing Node RED =====
The link below takes you to a wiki that describes how to install and set up an LXC container on a NetModule router.
----
* Set up an LXC container / [[app-notes:set-up-lxc]]
----
Once the LXC container has been installed, we can install Node-RED.
For further installation, we need the ''curl'' program and the ''npm'' package on the container. We will then deploy Node-RED on the router using a script.
root@LXCNAME:/# apt-get install curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
ca-certificates libbrotli1 libcurl4 libldap-2.5-0 libldap-common
libnghttp2-14 libpsl5 librtmp1 libsasl2-2 libsasl2-modules
libsasl2-modules-db libssh2-1 openssl publicsuffix
...
done.
root@LXCNAME:/#
root@LXCNAME:/# apt install npm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
binutils binutils-arm-linux-gnueabihf binutils-common build-essential
...
x11-utils x11-xserver-utils xdg-user-dirs xdg-utils xz-utils zutty
0 upgraded, 614 newly installed, 0 to remove and 0 not upgraded.
Need to get 169 MB of archives.
After this operation, 684 MB of additional disk space will be used.
...
done.
root@LXCNAME:/#
Next, the Node-RED program is installed via a script file.
Further information on the installation script can be found at this link.
* Node-RED script information [[https://github.com/node-red/linux-installers| github link]]
**
Node-RED core is installed in version 4.0.9 and Node.js in version 18.19.0.
**
The script command for this:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/
master/deb/update-nodejs-and-nodered)
root@LXCNAME:/# bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node18
The first question is whether the installation should be carried out under
the "root" user. We only have the "root" user in the container, so
the answer is ''yes''.
Are you really sure you want to install as root ? (y/N) ? ''y''
If I want to see the installation steps, please also say ''yes'' here
Are you really sure you want to do this ? [y/N] ? ''y''
I don't have a Pi where I install Node-RED on it, so ''no'' here
Would you like to install the Pi-specific nodes ? [y/N] ? ''n''
Running Node-RED update for user root at /root on debian
Stop Node-RED \u2714
Remove old version of Node-RED \u2714
Remove old version of Node.js \u2714 18.19.0+dfsg-6~deb12u2
Install Node 18.20.6-1nodesource1 \u2714 v18.20.8 Npm 10.8.2
Clean npm cache \u2714
Install Node-RED core \u2714 4.0.9
Move global nodes to local -
Npm rebuild existing nodes \u2714
Install extra Pi nodes -
Add shortcut commands \u2714
Update systemd script \u2714
Any errors will be logged to /var/log/nodered-install.log
All done.
Further settings for the Node-Red interface
The script command for this:
root@LXCNAME:~# node-red admin init
✔ Settings file · /root/.node-red/settings.js
? That file already exists. Are you sure you want to overwrite it? …
▸ Yes
▸ No
User Security
=============
? Do you want to setup user security? …
▸ Yes
▸ No
✔ Do you want to setup user security? · Yes
✔ Username · admin
✔ Password · *********
? User permissions …
▸ full access
▸ read-only access
? Add another user? …
▸ Yes
▸ No
✔ Do you want to enable the Projects feature? …
▸ Yes
▸ No
✔ Do you want to enable the Projects feature? · Yes
? What project workflow do you want to use? …
▸ manual - you must manually commit changes
▸ auto - changes are automatically committed
Editor settings
===============
? Select a theme for the editor. To use any theme other than "default", you will need to install @node-red-contrib-themes/theme-collection in your Node-RED user directory. …
▸ default
* aurora
* cobalt2
* dark
* dracula
* espresso-libre
* midnight-red
* monoindustrial
* monokai
* oceanic-next
* oled
* solarized-dark
* solarized-light
* tokyo-night
* zenburn
✔ Select the text editor component to use in the Node-RED Editor …
▸ monaco (default)
▸ ace
Node settings
=============
? Allow Function nodes to load external modules? (functionExternalModules) …
▸ Yes
▸ No
If you want to test the whole thing first, you can start the Node-RED server manually by entering the command ''"node-red-start"''.
root@LXCNAME:/# node-red-start
Start Node-RED
23 Jan 14:41:17 - [info]
Welcome to Node-RED
===================
If you want this to happen automatically when you start the LXC container, you have to set it up with the command ''"systemctl enable nodered.service"''.
root@LXCNAME:/# systemctl enable nodered.service
Created symlink /etc/systemd/system/multi-user.target.wants/nodered.service → /lib/systemd/system/nodered.service.
root@LXCNAME:/#
Once you have stored the systemctl for Node-RED, you still have to restart the container for the service to start.
You can access the Node-RED interface via a web browser. Simply enter the IP address of the container and port 1880.
The Node-RED interface will then be displayed.
{{:pictures:node-red.png?800|}}
----