Serial to Ethernet or WiFi bridge with Linux socat

Socat allows to read/write data from a serial port and forward it through TCP/IP. With this feature you can implement serial to Ethernet or WiFi bridge on a Linux enabled embedded device.

Example for a Digi Connect (Wi-)ME 9210:

Building from source code under Digi Embedded Linux DEL-5.7.2:

# cd ${HOME}

# wget

# tar xjf socat-2.0.0-b9.tar.bz2
# cd socat-2.0.0-b9
# export PATH=/usr/local/DigiEL-5.7/x-tools/arm-unknown-linux-uclibcgnueabi/bin:$PATH # CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr # make

In a DEL-5.7 project for ConnectME 9210 with rootfs, enable openssl and application pthread example to have the needed libraries installed.
In project/configs/ add:

cp "${HOME}/socat-2.0.0-b9/socat" "${ROOTFS_DIR}/usr/bin" cp "${HOME}/socat-2.0.0-b9/filan" "${ROOTFS_DIR}/usr/bin" cp "${HOME}/socat-2.0.0-b9/procan" "${ROOTFS_DIR}/usr/bin"

build and install, to create a rootfs with the needed binaries included.
Socat requires libraries:
librt, libssl, libpthread. libcrypt.
Make sure to have those libraries into your rootfs.

How to test it: program the rootfs to a standard build kernel (with JFFS2 rootfs support) to the modules partitions. On the Linux console enter:

socat tcp-l:54321,reuseaddr,fork file:/dev/ttyS0,nonblock,waitlock=/var/run/ttyS0.lock

according to instructions:
On the remote PC start telnet to port 54321 with the IP address of the module. Now you can enter something on telnet
and will see it on the serial port of the Connect ME 9210, you also can enter something on the serial port and will see it on telnet.

Or you start a TCP server on your PC and let socat connect to it:

socat /dev/ttyS0,b115200,raw,echo=0 TCP:yourpc.ip:port

For a final solution you should disable the Linux console on this serial port, or use a second serial port e.g. FIM.
For a final solution you should start socat from some of the /etc/init.d/rc scripts and maybe implement a web interface to configure TCP-port number, serial port speed, or security features like encryption.


Note: socat is GPL2

See binary rootfs for Digi Connect ME 9210 attached, as well as for Digi Connect Wi-ME 9210. in addition you need to make the WiFi connection first, before starting socat and before starting telnet. If it doesn't load the kernel modules of above rootfs, use kernel attached.

Last updated: Jun 11, 2019

Filed Under


Recently Viewed

No recently viewed articles

Did you find this article helpful?