User Tools

Site Tools


docu:csheet:net:misc:rpi_pc_serial

Connect a Computer with Raspberry Pi over IP using a USB serial line


Ever wandered you can connect 2 computers over a simple serial line to use the IP protocol?
This is how the whole internet works, basically, but in your small setup :)

In our example, the Raspberry Pi is our router (the one with routing to internet, and any other services), and the other computer is just a slave who wants access to this.

So, the sample code snippets do as follow:

# on the rpi
slattach -p cslip -s 115200 /dev/ttyS0 &
ifconfig sl0 192.168.60.1 pointtopoint 192.168.60.2 up
 
# on the pc
ps aux | grep [s]lattach | grep -i ttyusb | awk '{print $2}' | \
    xargs -r --replace=PID kill -9 PID >/dev/null 2>&1
ifconfig sl0 down >/dev/null 2>&1
(slattach -p cslip -s 115200 /dev/ttyUSB* &) >/dev/null 2>&1
sleep 2 && ifconfig sl0 192.168.60.2 pointtopoint 192.168.60.1 up
ip route del default >/dev/null 2>&1
ip route add default via 192.168.60.1


Where 192.168.60.1 is the IP of our gateway (in this case the rpi), and 192.168.60.2 is just our serial line client in the other side (the pc)

Source: https://www.linuxjournal.com/article/2820

docu/csheet/net/misc/rpi_pc_serial.txt · Last modified: 2020/05/18 20:51 by admin