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.

The background to this project

Companies are increasingly being urged to become more digital and smarter in the workplace. However, data and information are usually generated locally in the work process (on trains, buses, or production machines). In addition, the components (sensors or controls) were not developed for a network. We already use a Netmodule router for this task of collecting local data from various components and sending it to a central server via a mobile connection. The second point that I see as an obstacle to digitization is that many components also have their own protocols. The access programs supplied are not very smart, and you end up with a whole bunch of programs that need to be maintained. I have implemented a solution for this using the open source tool Node-RED. Access to components is standardized, making it less complex. Protocols that are not widely used are also supported.


Project setup


Interaction


Prerequisites

  • NetModule Wireless Router with wireless connection
  • NetModule Software 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 5.0.0.100 and the LXC container with Debian armhf bookworn.

1. 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.



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.

USER
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:/#

USER
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 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) 

USER
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

USER
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

USER
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

USER
✔ 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

USER
✔ Do you want to setup user security? · Yes ✔ Username · admin ✔ Password · * ? User permissions … ▸ full access ▸ read-only access

? Add another user? … ▸ Yes ▸ No

USER
✔ 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

USER
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

USER
✔ 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”.

USER
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”.

USER
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.


2. Installing further app-nodes via palette management

For Node-RED, further “app nodes” need to be installed.

On the right side of the web interface, you can install additional nodes for Node-RED. A tab opens under point 1. You can install the nodes under point 2.

A separate window will open for the installation, where you can carry out the installation. The “Installation” item is responsible for installation. You can search for existing nodes and install them under the search field in item 2.

Two additional nodes are required for implementation.

Node: „siemens-sentron“

Node: „influxdb“

After installation, the new nodes are available on the left side of the web interface.


3. Importing a Modbus flow into Node-RED

The .json file can be inserted using the import function. The tab is located on the right side of the web interface.

A separate window will open again. You can import a file or copy the code directly into the field.

Under this item, you can download Modbus flow for Node-RED.

show code

After execution, these objects are stored in the flow.

When this flow is executed, the two pieces of information L-N voltage and mains frequency are displayed in the Debug tab.


4. Install and set up InfluxDB 2.0 on a Raspberry Pi

The database(Influx) and data virtualization program(Grafana) can be located centrally in a data center. The Netmodule router can transfer data to the server via a mobile connection and additionally via an IPsec or OpenVPN tunnel. The router is the gateway between local data and the network level.

The auxiliary tool “wget” is required to install InfluxDB. In the second step, the KEYS for package management can be added to the system. Once this has been done, InfluxDB can be installed.

USER
:~ $ sudo apt install wget Reading package lists… Done … wget is already the newest version (1.21.3-1+deb12u1). :~ $

To add the KEYS, these three program lines must be executed. In the last step, the software database update and influxdb2 are installed.

wget -q https://repos.influxdata.com/influxdata-archive_compat.key
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list

sudo apt-get update && sudo apt-get install influxdb2

If you want the database to start as a background service when the system starts up, please execute this command.

sudo service influxdb start

The whole thing can be checked using this command to see whether InfluxDB is running correctly on the Raspberry Pi.

USER
:~ $ sudo service influxdb status ● influxdb.service - InfluxDB is an open-source, distributed, time series database

   Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; preset: enabled)
   Active: active (running) since Wed 2025-07-09 17:21:36 CEST; 1 day 22h ago
     Docs: https://docs.influxdata.com/influxdb/
 Main PID: 1310 (influxd)
    Tasks: 19 (limit: 9564)
      CPU: 1min 2.918s
   CGroup: /system.slice/influxdb.service
           ├─1310 /usr/bin/influxd
           ├─1353 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session
           ├─1354 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session
           ├─1387 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session
           └─1412 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session

The influxdb can be further configured via a web browser. To access the interface, you need the IP address of the Raspberry Pi and the port number 8086.

Example: 192.168.1.110:8086

When you log in for the first time, you will be asked to choose a username and password.

For the first point, select the “BUCKETS” option in the menu and create a new one with “+ CREATE BUCKET”.

To access the database, you must first set up an API token. You can use the custom token to restrict access to individual buckets. A separate token can be created for each program that can access the database.

The token in this project is required for Node-Red to access the database.

Once the connection between Node-RED and InfluxDB is established, the data is stored in a structured format in the database and can be viewed using the Influx Data Explorer.


5. Install and set up Grafana on a Raspberry Pi

As with the database, KEYS must be added for the installation of Grafana. After this step, the program can be installed again.

sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

sudo apt-get update
sudo apt-get install -y grafana

To ensure that Grafana starts as a background service when the system boots, you must enable the Grafana Systemctl service.

sudo /bin/systemctl enable grafana-server

With the second command, you start the Grafana server.

sudo /bin/systemctl start grafana-server

Grafana is then further configured via a web browser. To access the interface, you need the IP address of the Raspberry Pi and port number 3000.

Example: 192.168.1.110:3000

When logging in for the first time, the user name is “admin” and the password is “admin”. After logging in, you must change the password first.

First, the data source from which the data(InfluxDB) originates is integrated into Grafana.

The URL address is important for accessing the InfluxDB.

Under the “InfluxDB Details” option, you must specify an organization for Grafana for access and the “bucket” that was previously set up in InfluxDB. In InfluxDB 2.0, access is always via a token and no longer with a user name and password. For Grafana, you can either create your own under the database or use the token you have already created here.

Once all settings have been made, you can test access to the database from Grafana to check that the settings are correct.

Next, you can set up dashboards in Grafana and visualize the data from the database for further processing within the company.


6. Additional information

Further documentation on the data transceiver and the sensor.