Serial ports over TCP/IP with socat

This article illustrates how to realize a lan to serial gateway

Remote unit

On the remote unit install ser2net then add this line in /etc/ser2net.conf configuration file

2000:raw:600:/dev/ttyS1:115200 8DATABITS NONE 1STOPBIT

Launch ser2net:

# ser2net

Local unit

Install the socat utility.

Create a directory called $HOME/dev

Launch socat:

$ socat pty,link=$HOME/dev/ttyV0,waitslave tcp:remoteip:remoteport

Open minicom on /dev/ttyV0 and send chars to your remote port.

Examples

Serial port on stdin

socat /dev/ttyUSB0,b115200,raw,echo=0,crnl -

Remote console

Board

socat /dev/ttyS2,b115200,raw,echo=0 TCP:terzo.acmesystems.it:2002
socat /dev/ttyS4,b115200,raw,echo=0 TCP:terzo.acmesystems.it:2004

Server web

socat TCP-LISTEN:2002 PTY,link=ttyV2,raw,crnl
socat TCP-LISTEN:2004 PTY,link=ttyV2,raw,crnl

Design tips

Using the RoadRunner SOM it is possible to manage up to 10 serial ports over a network link.

Related links

Products related

H10

Features Index Buy

Single Board Computer based on RoadRunner Linux SOM (Included)
  • Low power consumption
  • Two USB Host 2.0 ports (one configurable as USB client on the USB-C connector)
  • One 10/100 Mbit/s Lan port
  • 2 Acme Sensor ports
  • Huge set of GPIOS, SPI, I2C and serial lines

Features Index Buy

Battery-free energy harvesting solar powered LoRa sensor
  • Low power consumption:
    Stand-by mode 4.29 µW
    Transmit mode 66 mW
  • Energy harvesting from in-door ambient light (Just 50 lux)
  • Energy storage based on hybrid supercap
  • Open source RIOT OS
  • Ready for LoRa and LoRaWan
H10

Features Buy

A collection of sensors ready to be connected to the FOX Board D27 and Berta-H10 fast prototiping board.
  • High-accuracy
  • Small footprint
  • High reliability
  • Low-power
  • Cost effective
  • Pluggable by FPC cable