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


Setting up an LXC container with Alpine Linux and a ready-to-run Node-RED implementation


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.

… … … …

… … … … MB MB …

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) 

https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered–

“”“” yes

y

yes y

no n

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

Further settings for the Node-Red interface

The script command for this:

root@LXCNAME:~# node-red admin init

“”

If you want to test the whole thing first, you can start the Node-RED server manually by entering the command “node-red-start”.

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

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.

… …

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.

   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.

AI Agent for an Energy Management