socat - the guide to remote serial, PanelDue and Telnet(ish)



  • Disclaimer; I just know enough to be dangerous ... and went down this rabbit hole trying to use a PanelDue with an unsupported Duet3 prototype. Anyways, I'll list a few commands below that may or may not be useful to others trying to solve interesting problems in interesting ways..

    The first scenario was having the PanelDue attached to a USB to TTL adapter on the Raspberry Pi that was connected to the Duet. The Pi has both the SPI connection, and the (USB) serial connection. The easy solution would be to glue the two serial ports together. After realizing socat didn't care I had beforehand set baud rates with stty it worked just fine.

    /dev/USB0 is the (FTDI) USB to TTL, and /dev/ACM0 is the Duet (USB) serial port:
    socat /dev/ttyUSB0,raw,echo=0,b57600 /dev/ttyACM0,raw,echo=0,b115200
    or
    pi@duet3:~ $ socat -lm /dev/ttyUSB0,raw,echo=0,b57600 EXEC:/opt/dsf/bin/CodeConsole,su=root,pty,stderr

    This got me thinking, we could forward the Duet's serial port to a TCP port, this should give access to the console even if DSF is not runnng.
    pi@duet3:~ $ socat /dev/ttyACM0,raw,echo=0,b115200 tcp-listen:23,reuseaddr
    or
    pi@duet3:~ $ socat -lm -d -d TCP-LISTEN:23,fork EXEC:/opt/dsf/bin/CodeConsole,su=root,pty,stderr

    Having done that I realize I could then move the FTDI USB to TTL adapter and PanelDue to any machine on my network and bridge the serial port over TCP.
    pi@duet3:~ $ socat /dev/ttyACM0,raw,echo=0,b115200 tcp-listen:2323,reuseaddr
    bearer@remotemachine:~$ socat -d -d /dev/ttyUSB1,raw,echo=0,b57600 tcp:duet3.local:2323
    or
    pi@duet3:~ $ socat -lm -d -d TCP-LISTEN:2323,fork EXEC:/opt/dsf/bin/CodeConsole,su=root,pty,stderr
    bearer@remotemachine:~$ socat -d -d /dev/ttyUSB1,raw,echo=0,b57600 tcp:duet3.local:2323

    The above was all tested and found working. There are probably some of you that have improvements to suggest and I welcome those. Especially on error handling and such. I've never been known to leave a rabbit hole untill all the rabbits have been "dealt" with, so in a future post I'll try to add some systemd stuff and try to have socat execute CodeConsole instead using the serial connection, as well as trying to have socat execute ssh to setup the far side all in one command (maybe).



  • @bearer socat is one of those hidden gems that you can find all sorts of uses for. You can even use it to monitor the unix socket the DuetControlServer creates...

    With the DuetControlServer running...

    mv /var/run/dsf/dcs.sock /var/run/dsf/dcs.sock.original
    socat -t100 -x -v UNIX-LISTEN:/var/run/dsf/dcs.sock,mode=777,reuseaddr,fork UNIX-CONNECT:/var/run/dsf/dcs.sock.original
    


  • The force is strong in this one! ☝


Log in to reply