SocatOptions

Useful socat options and recipies (to connect to device remotely, possibly behind restrictive firewall)

Traditional way to make a serial relay that TCP LISTENS on port 9001 is via ser2net :\n

echo '9001:raw:600:/dev/ttyUSB0:19200 8DATABITS NONE 1STOPBIT'>>/etc/ser2net.conf

For some reason the ser2net + socat at the ECU side seem more reliable than just socat (maybe we have not fully mastered socat yet ?)

TODO: socat equivalent (the order of descriptors might matter; tcp-l or the serial device should be first ? So that socat only opens the serial device when accepting incoming connectiong from TCP remote peer).

See OverTCPWireless


Poor man's "turn-server"\n

# On a public IP:
export SOCAT_DEFAULT_LISTEN_IP=.... (may or may not be needed)
socat tcp4-listen:9907,reuseaddr tcp4-listen:9906

# And on ser2net (assuming ser2net listens on 9001):
socat tcp:localhost:9001 tcp:public-ip.net:9907,forever,interval=10,fork


ser2net is very useful when connecting over LAN (or via WAN when one has firewall administration passwd and knowledge ).

However, very often people do NOT have firewall administration passwd => they cannot connect to their devices over WAN.

In that case the devices can be set up to CONNECT to some relay (similar to a "turn server") that listens on some known public address.

Since socat can open the serial device (without ser2net), perhaps ser2net is not needed AT ALL. Socat might be just enough on orangepi/raspi

[socat example]

Socat

So an example of running socat to tcp-connect (not listen!):\n

while [ ! -e /dev/shm/STOP ]; do socat file:/dev/ttyUSB0,b19200,raw,echo=0  tcp:svn.x-dsl.hu:8809,mss=1444,forever,interval=10,fork ; sleep 1; done

(run from terminal, socat -v option is your friend; only run from rc.local after it works as expected - even in case of network disconnects).

Point your VemsTune to svn.x-dsl.hu:8808 and it will connect to the serial port opened by socat if all goes well