Skip to Content

TCP client on a TouchBerry Pi or Raspberry PLC, part 1: static IP address

Plan the addresses of the TCP client and server and give the client a fixed IP before you write the code
December 10, 2018 by
TCP client on a TouchBerry Pi or Raspberry PLC, part 1: static IP address
Alejandro Jabalquinto

Before you write a TCP client, give the device a fixed IP address, so that the server and the client always find each other. On Raspberry Pi OS Bookworm and Trixie, you do it with nmcli and check it with ip a. The complete method, also for older systems and Wi-Fi, is in the static IP guide.

This is part 1 of a two-part tutorial. Here you plan the network and give a fixed address to a TouchBerry Pi Panel PC or a Raspberry PLC. In part 2 you write the TCP client in Node.js.

The first version of this tutorial used a TouchBerry Pi 3, now discontinued. The steps are the same on the current TouchBerry Pi (Raspberry Pi 4) and on any Raspberry PLC, because both run Raspberry Pi OS (Debian).

TouchBerry Pi Panel PC 10.1 inch with a dashboard on the touch screen
TouchBerry Pi Panel PC 10.1": the TCP client of this tutorial can run on it.
  1. Step 1Plan the networkAddress of the client and of the server
  2. Step 2Fix the addressnmcli on Bookworm and Trixie
  3. Step 3Check itip a and ping
  4. Step 4Write the clientPart 2, with Node.js

Why a TCP client needs a static IP address

By default, the Raspberry Pi gets its address from the router by DHCP, and it can change after a reboot. A server that only accepts known clients, a firewall rule or a SCADA that reads the device by IP stops working when the address changes.

It is like a phone number that changes every day: nobody can call you. A fixed address on each device avoids it.

Step 1: plan the network of the tutorial

The two parts of this tutorial and the Node.js TCP server use these addresses. Change them to match your network:

DeviceRoleAddress
TouchBerry Pi or Raspberry PLCTCP client192.168.1.25/24
TouchBerry Pi, Raspberry PLC or PCTCP server, port 5566192.168.1.30/24
RouterGateway and DNS192.168.1.1

Both devices must be in the same subnet. Choose addresses outside the DHCP range of the router, so that no other device receives them.

Step 2: give the client a fixed address

On Bookworm and Trixie, NetworkManager manages the network. The Ethernet connection of eth0 is usually called Wired connection 1; check it with nmcli connection show. Then set the address and activate the connection:

sudo nmcli connection modify "Wired connection 1" ipv4.method manual ipv4.addresses 192.168.1.25/24 ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1
sudo nmcli connection up "Wired connection 1"

Other cases. The nmtui menu, Wi-Fi, dhcpcd.conf on Bullseye and older, going back to DHCP and common errors are in the complete guide: how to set a static IP on an industrial Raspberry Pi.

A Raspberry PLC or a TouchBerry Pi also answers at the factory address 10.10.10.20 on eth0. To change it, see how to change the static IP of a Raspberry PLC.

Step 3: check the address

ip a show eth0
ip route
ping -c 3 192.168.1.1

Look for inet 192.168.1.25/24 in the output of ip a show eth0. ip route must show default via 192.168.1.1, and the ping to the router must get replies. Do the same on the server with its own address.

Next step: the TCP client

The TouchBerry Pi Panel PC comes in 7", 10.1" and 18.5" with Gigabit Ethernet. The Raspberry PLC family has two Ethernet ports and Debian Bookworm 64-bit preinstalled.

Take it further

A fixed address is the first step to connect a panel or a PLC with the rest of the machine. These pages show it in a real project.

​Search in our Blog

TCP client on a TouchBerry Pi or Raspberry PLC, part 1: static IP address
Alejandro Jabalquinto December 10, 2018
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

PLC Comparison