Skip to content

Serial to Socket - Proxy and multiplex a serial port over TCP/IP. Minimal footprint. Docker image and DEB/RPM/APK packages included.

Notifications You must be signed in to change notification settings

tamcore/ser2sock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ser2sock

ser2sock is a lightweight application written in Go to expose a serial device over TCP/IP. It enables bidirectional communication between a serial device and a TCP client, with options for verbose logging and decoding traffic.

Features

  • Forward data between a serial port and a TCP connection.
  • Configurable serial device, baud rate, and TCP listening address.
  • Filter connections by allowed IP addresses.
  • Optional verbose logging of incoming and outgoing data.
  • Decode data into human-readable text (UTF-8) or display raw hexadecimal.

Installation

Pre-built packages

Debian / Ubuntu

arch=$(uname -m | sed -e "s/aarch64/arm64/" -e "s/x86_64/amd64/")
wget -O ser2sock.deb https://github.com/tamcore/ser2sock/releases/latest/download/ser2sock_linux_${arch}.deb
dpkg -i ser2sock.deb

RockyLinux / AlmaLinux / CentOS / RHEL

arch=$(uname -m | sed -e "s/aarch64/arm64/" -e "s/x86_64/amd64/")
rpm -Uvh https://github.com/tamcore/ser2sock/releases/latest/download/ser2sock_linux_${arch}.rpm

Alpine

arch=$(uname -m | sed -e "s/aarch64/arm64/" -e "s/x86_64/amd64/")
wget -O ser2sock.apk https://github.com/tamcore/ser2sock/releases/latest/download/ser2sock_linux_${arch}.apk
apk add --allow-untrusted ser2sock.apk

Build from Source

Prerequisites

  • Go version 1.16 or later installed on your system.

Build

  1. Clone
    git clone https://github.com/tamcore/ser2sock.git
    cd ser2sock
  2. Build
    go build -o ser2sock

Usage

./ser2sock -device <serial_device> -listen <address:port> -baud <baud_rate> [options]

Options

Option Description Example
-device Path to the serial device. Required. /dev/ttyUSB0, COM3, /dev/zigbee1
-listen TCP address and port to listen on. 0.0.0.0:5000
-baud Baud rate for the serial device. Default: 9600. 115200
-allowed Comma-separated list of allowed client IPs. Leave empty to allow all IPs. 192.168.1.100,192.168.1.101
-verbose Enable verbose logging for incoming and outgoing data. (no value, just add the flag)
-decode Attempt to decode data into human-readable UTF-8 text. Defaults to raw hexadecimal format. (no value, just add the flag)

Example Commands

Basic Usage

Expose the serial device /dev/ttyUSB0 on TCP port 5000 with a baud rate of 9600:

./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600

Restricting Access

Allow only clients from specific IPs:

./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600 -allowed "192.168.1.100,192.168.1.101"

Verbose Logging

Enable detailed logging of IN/OUT traffic:

./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600 -verbose

Decoding Data

Attempt to decode data into human-readable text when possible:

./ser2sock -device /dev/ttyUSB0 -listen 0.0.0.0:5000 -baud 9600 -verbose -decode

Example Output

Without Decoding (`-decode not used):

Accepted connection from 192.168.1.100:54832
IN  (TCP->Serial): 48656c6c6f
OUT (Serial->TCP): fe00

With Decoding (`-decode enabled):


Accepted connection from 192.168.1.100:54832
IN  (TCP->Serial): "Hello"
OUT (Serial->TCP): (binary: fe00)

Development

Dependencies

  • go-serial: For interacting with the serial device.

Install dependencies:

go get ./...

Testing

Run the application locally and connect using a TCP client like telnet or netcat:

telnet <server_ip> <port>

About

Serial to Socket - Proxy and multiplex a serial port over TCP/IP. Minimal footprint. Docker image and DEB/RPM/APK packages included.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages