Skip to content

Instantly share code, notes, and snippets.

@rena2019
Last active November 7, 2024 23:24
Show Gist options
  • Save rena2019/9ae031dc354daa29d16e7f583556ba76 to your computer and use it in GitHub Desktop.
Save rena2019/9ae031dc354daa29d16e7f583556ba76 to your computer and use it in GitHub Desktop.
serial port via SSH
#1. ESP32 @ /dev/ttyS7 <-> /dev/ttyV1
# baudrate auf 115200 setzen (ist erforderlich)!
stty -F /dev/ttyS7
# virtuellen port /tmp/ttyV1 erstellen und mit /dev/ttyS7 verbinden mit -x => verbose hexadecimal dump of data traffic
socat -x PTY,link=/tmp/ttyV1,raw,echo=0,crnl /dev/ttyS7,b115200,raw,echo=0
#per tio output anschauen
tio /tmp/ttyV1
#2. dasselbe mit Umweg über IP/Port: /dev/ttyS7 <-> localhost:54321 <-> /tmp/ttyV1
socat -dd /dev/ttyS7,b115200,raw,echo=0 tcp-listen:54321
socat tcp:localhost:54321 pty,link=/tmp/ttyV1,raw,echo=0,crnl
tio /dev/ttyV1
#3. /dev/ttyS7 <-> tcp:54321 <- SSH -> tcp:54321 <-> /tmp/ttyV1
#@local
socat -dd /dev/ttyS7,b115200,raw,echo=0 tcp-listen:54321
ssh -R 54321:localhost:54321 pi@192.168.178.38
#@ remote
socat -dd pty,link=/tmp/ttyV1,raw,echo=0 tcp:localhost:54321
#oder auch direkt in 1 Zeile:
ssh -R 54321:localhost:54321 pi@192.168.178.38 socat -dd pty,link=/tmp/ttyV1,raw,echo=0 tcp:localhost:54321
tio /dev/ttyV1
#besser mit ser2net????????????????
Connecting to a Remote Serial Port over TCP/IP https://techtinkering.com/2013/04/02/connecting-to-a-remote-serial-port-over-tcpip/
# @ pc with HW
nano /etc/ser2net.conf
3333:raw:0:/dev/ttyS7:115200 8DATABITS NONE 1STOPBIT
#starten
ser2net
#bzw
/etc/init.d/ser2net restart
#unter MinGW/MSYS2 gibts das Package wohl nicht -> erstmal bauen
# D:\tools\msys64.202401\msys2_shell.cmd
wget https://sourceforge.net/projects/ser2net/files/ser2net-4.3.6.tar.gz/download -O ser2net-4.3.6.tar.gz
tar -xvzf ser2net-4.3.6.tar.gz
cd ser2net-4.3.6
./configure
...
checking for GENSIO... no
checking gensio/gensio.h usability... no
checking gensio/gensio.h presence... no
checking for gensio/gensio.h... no
configure: error: gensio.h not found, please install gensio dev package
=> benötigt wohl gensio https://github.com/cminyard/gensio
https://www.complete.org/using-gensio-and-ser2net/
=> muss auch erste gebaut werden !!! Building on Windows https://github.com/cminyard/gensio
# next test: ESP32 @ RPi -----------------------------------------------------------------------------
#1.everything @rpi
dmesg
...
[16674831.379974] usb 1-1.2: new full-speed USB device number 7 using dwc_otg
[16674831.515095] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=55d3, bcdDevice= 4.43
[16674831.515149] usb 1-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=3
[16674831.515171] usb 1-1.2: Product: USB Single Serial
[16674831.515190] usb 1-1.2: SerialNumber: 542A034643
[16674831.865271] cdc_acm 1-1.2:1.0: ttyACM0: USB ACM device
[16674831.870183] usbcore: registered new interface driver cdc_acm
[16674831.870214] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
#test (mit Reset button): OK
tio -b 115200 /dev/ttyACM0
#2. via /dev/ttyACM0 <-> ser2net <-> port 3333 <-> socat /tmp/ttyV0 : OK
sudo apt-get install ser2net
sudo nano /etc/ser2net.conf
3333:raw:0:/dev/ttyACM0:115200 8DATABITS NONE 1STOPBIT
$ sudo systemctl stop ser2net
$ sudo systemctl start ser2net
$ sudo systemctl status ser2net
sudo apt-get install socat
socat pty,link=/tmp/ttyV0,waitslave tcp:localhost:3333
tio -b 115200 /tmp/ttyV0
#3. via /dev/ttyACM0 <-> ser2net <-> port 3333 <-> SSH <-> socat /tmp/ttyV0
#erst port forwarding
ssh -L 3333:locahost:3333 pi@192.168.178.38
#dann
#und @ PC
socat pty,link=/tmp/ttyV0,waitslave tcp:localhost:3333
#xxxxx geht auch nicht !!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment