Bering-uClibc 6.x - User Guide - Advanced Topics - Setting Up a Raspberry PI as a net to serial gateway

From bering-uClibc
Revision as of 00:51, 2 September 2018 by Jeanrocco (Talk | contribs) (Correcting some bugs...)

Jump to: navigation, search


This setup describes how to make any "device serial communication port" accessible through an SSH network session. The initial motivation was to make the serial port of a distant APU2c2 accessible over distances longer than 200 feets. Knowing that RS-232C communication distances are short, why not use a wired network instead that can reach a lot farther.

This setup shows how to adapt the LEAF tarball distribution for the raspberry PI and make it act as an interface between your network and any device serial communication port. The Raspberry PI will run an ssh server and will accept an ssh session where one can access the serial port using minicom or picocom communications programs. There is a USB to RS-232C cable, that connects the raspberry PI to the serial port.

Using the LEAF distribution OS on the Raspberry PI really transforms it into a very stable and dependable production platform, since everything will then run in rams. No writing to the SD card will occur once in operation... It is a well known fact that, it is only a matter of time for the Raspberry PI to corrupt it's SD card, thus making it fail to boot or run. This is mainly caused by random power fails occurring at the same time the PI is writing to the SD card (further readings:

You will need

  1. - one raspberry pi 1 and power supply, (or PI2 or PI3 but it will be overkill...)
  2. - rs232c to USB cable
  3. - one db9 female to female null modem
  4. - LEAF tarball distribution for PI1, at
  5. - One SD card, 4 gig. is plenty
  6. - a pc running a modern Linux distribution
  7. - an SD card programmer

Setting up the SD

  1. - Download the tarball and unpack it in a suitably named directory
  2. - Put the SD card in the programmer, then make a single Fat32 partition, and format it to Fat32
  3. - Copy all the files from the unpacked tarball to the SD
  4. - Looking at the SD contain:
1- find the package dropbear.lrp
2- rename it to dropbear.tgz
3- doubleclick it
4- add DB_OPTIONS=" -B " at the end of /etc/default/dropbear 
5- save file and update archive dropbear.tgz
6- rename dropbear.tgz back to dropbear.lrp
7- again, in the archive, find the file LEAF.CFG, and in "LRP=" list remove shorewall and dnsmasq, and add local and picocom,
   you should now have:
   LRP="license root nano local dhcpcd keyboard dropbear lighttpd webconf picocom patch"... 
   it is important to remove shorewall here
8- unmount the SD card...

Starting the Raspberry PI

  1. - Put the SD card in the Raspberry PI, and power it up
  2. - After ~ 30 seconds, find out the PI's Ip address, and ssh in it: ssh root@raspberry_pi_IP_address. On Android, the fing app does marvels ...
  3. - Set the new passwords for the OS and webconf
  4. - Open webconf from a browser http://raspberry_pi_IP_address to try it out
  5. - While you're there, it would be a good idea to comment-out eth1 in /etc/network/interfaces, look in Networking...
  6. - A good time also to do your "ssh-copy-id" to write ssh keys in /.ssh/authorized_keys (see )

Correcting some bugs...

from your already opened ssh session:

  • - fix xterm go to /etc/terminfo/x and "cp xterm xterm-256color"
  • - fix reboot: The busybox reboot command does not work, here is a hardware alternative done by connecting GPIO4 to the PI reset connector P6 pin 1 (the square one). Solder a 2 pin header on P6 ( and place a jumper wire between P6 pin 1 (the square pin hole) and GPIO4, on P1 pin 7 (
  • - create a new reboot command: make the script /root/ and change the old reboot command in /sbin...
script /root/

# reset avec gpio4 connecte sur reset du PI, P6 pin 1 square.
echo "4" > /sys/class/gpio/export             # we will talk to gpio4
echo "out" > /sys/class/gpio/gpio4/direction  # gpio4 on boot is an high-z input, but defaults to low (0) as an output
cd /sbin

mv reboot old_reboot               # keep old command in case someone repairs busybox...
ln -s /root/ reboot  # reboot command now points to /root/
  • - set the local.local:
lrcfg > 3) local > 1) list of files that should be saved > 

lrcfg > s) save configuration

Using the gateway

  1. - now connect the RS-232C to USB cable with the null modem between your PI and your device serial port
  2. - open an ssh session to the PI
  3. - start picocom: picocom -b115200 /dev/ttyUSB0
  4. - hit return:... you should have the prompt to login in your router or whatever !
  5. - exit picocom with Cntl-a Cntl-x, help is Cntl-a Cntl-h

Final thoughts

It would be a good idea to configure eth0 with a static IP address in /etc/network/interface. This would allow a network communication between your workstation and the PI Serial gateway even if your firewall and consequently DHCP server are down.

You can also remove or comment out DB_OPTIONS=" -B " in /etc/default/dropbear, to bring the security level back.

Using the PI as a full blown firewall has not been tested here, the feeling is that it would be too slow... volunteers are welcome ...

Have fun

by: jrb with kapeka's idea to use leaf !