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

From bering-uClibc
Jump to: navigation, search
Line 4: Line 4:
  
  
This setup describes how to make any device serial communication port accessible through an SSH network session. The 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 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 communication programs. There is a USB to RS-232C cable, that connects the raspberry PI to the serial port.
+
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 Raspberry PI with the LEAF distribution transforms it into a very stable and dependable platform, since everything runs in rams. It is a well known fact that, it is only a matter of time for the Raspberry PI to corrupt it's SD card and make it fail to boot or run. This is mainly caused by random power fails occuring when the PI is writing to the SD card (further readings: https://hackaday.com/2016/08/03/single-board-revolution-preventing-flash-memory-corruption/).  
+
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 occurs 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: https://hackaday.com/2016/08/03/single-board-revolution-preventing-flash-memory-corruption/).  
  
 
==You will need==
 
==You will need==
Line 25: Line 25:
  
 
#- Download the tarball and unpack it in a suitably named directory
 
#- Download the tarball and unpack it in a suitably named directory
#- Put the SD card in the programmer, and make a single Fat32 partition, format it to Fat32
+
#- Put the SD card in the programmer, then make a single Fat32 partition, and format it to Fat32
#- Copy all the files from the tarball to the SD
+
#- Copy all the files from the unpacked tarball to the SD
 
#- Looking at the SD contain:  
 
#- Looking at the SD contain:  
 
  1- find the package dropbear.lrp
 
  1- find the package dropbear.lrp
 
  2- rename it to dropbear.tgz
 
  2- rename it to dropbear.tgz
 
  3- doubleclick it
 
  3- doubleclick it
  4- add -B in /etc/network/interfaces DB_OPTIONS=" -B "
+
  4- add DB_OPTIONS=" -B " at the end of /etc/network/interfaces  
  5- save files and update archive dropbear.tgz
+
  5- save file and update archive dropbear.tgz
 
  6- rename dropbear.tgz back to dropbear.lrp
 
  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==
 
==Starting the Raspberry PI==
  
 
#- Put the SD card in the Raspberry PI, and power it up
 
#- Put the SD card in the Raspberry PI, and power it up
#- After ~ 30 seconds, find out the PI's Ip address, and ssh in it
+
#- After ~ 30 seconds, find out the PI's Ip address, and ssh in it. On Android, the fing app does marvels ...
#- Set the new passwords for the OS and webmin
+
#- Set the new passwords for the OS and webconf
#- Open webmin from a browser http://raspberry_pi_IP_address
+
#- Open webconf from a browser http://raspberry_pi_IP_address
#- Edit LEAF.CFG to your liking: add ....local... remove ...shorewall and dnsmasq...
+
#- It would be a good idea to comment-out eth1 in /etc/network/interfaces, look in Networking...
#- do your ssh-copy-id for ssh keys in /.ssh/authorized_keys (see https://bering-uclibc.zetam.org/wiki/Bering-uClibc_6.x_-_User_Guide_-_Advanced_Topics_-_Setting_Up_SSH_password-less_login_and_Port_Knocking )
+
#- A good time also to do your "ssh-copy-id" to write ssh keys in /.ssh/authorized_keys (see https://bering-uclibc.zetam.org/wiki/Bering-uClibc_6.x_-_User_Guide_-_Advanced_Topics_-_Setting_Up_SSH_password-less_login_and_Port_Knocking )
  
 
==Correcting some bugs...==
 
==Correcting some bugs...==
  
 +
*- open an ssh session on your PI: ssh root@raspberry_pi_IP_address...
 
*- fix xterm go to /etc/terminfo/x and "cp xterm xterm-256color"
 
*- fix xterm go to /etc/terminfo/x and "cp xterm xterm-256color"
*- fix reboot: simple reboot by connecting GPIO4 to the PI reset connector P6 pin 1 (the square one)
+
*- 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.
  script /root/rebootJR.sh
+
  script /root/GPIO4reboot.sh
 
   
 
   
 
  #!/bin/sh
 
  #!/bin/sh
Line 60: Line 67:
 
   
 
   
 
  mv reboot old_reboot
 
  mv reboot old_reboot
  ln -s /root/rebootJR.sh reboot
+
  ln -s /root/GPIO4reboot.sh reboot
  
*- set local.local:  
+
*- set the local.local:  
 
  lrcfg > 3) local > 1) list of files that should be saved >  
 
  lrcfg > 3) local > 1) list of files that should be saved >  
 
   
 
   
Line 68: Line 75:
 
  etc/terminfo/x/xterm-256color
 
  etc/terminfo/x/xterm-256color
 
  root/.ssh/authorized_keys
 
  root/.ssh/authorized_keys
  root/rebootJR.sh
+
  root/GPIO4reboot.sh
 
  sbin/reboot
 
  sbin/reboot
 
  sbin/old_reboot
 
  sbin/old_reboot
Line 78: Line 85:
 
==Using the gateway==
 
==Using the gateway==
  
#- Open an ssh session to the PI
+
#- now connect the RS-232C to USB cable with the null modem between your PI and your device serial port
 +
#- open an ssh session to the PI
 
#- start picocom: picocom -b115200 /dev/ttyUSB0
 
#- start picocom: picocom -b115200 /dev/ttyUSB0
#- hit return:... you should have the prompt to login in your router !
+
#- hit return:... you should have the prompt to login in your router or whatever !
 
#- exit picocom with Cntl-a Cntl-x, help is Cntl-a Cntl-h  
 
#- exit picocom with Cntl-a Cntl-x, help is Cntl-a Cntl-h  
  
 
==Have fun==
 
==Have fun==

Revision as of 01:38, 30 August 2018

This is a work in progress

Goal

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 occurs 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: https://hackaday.com/2016/08/03/single-board-revolution-preventing-flash-memory-corruption/).

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 https://sourceforge.net/projects/leaf/files/Bering-uClibc/6.1.4/Bering-uClibc_6.1.4_raspberry-rpi.tar.gz/download
  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/network/interfaces 
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. 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
  5. - 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 https://bering-uclibc.zetam.org/wiki/Bering-uClibc_6.x_-_User_Guide_-_Advanced_Topics_-_Setting_Up_SSH_password-less_login_and_Port_Knocking )

Correcting some bugs...

  • - open an ssh session on your PI: ssh root@raspberry_pi_IP_address...
  • - 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.
script /root/GPIO4reboot.sh

#!/bin/sh
#
# reset avec gpio4 connecte sur reset du PI, P6 pin 1 square.
#
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction
cd /sbin

mv reboot old_reboot
ln -s /root/GPIO4reboot.sh reboot
  • - set the local.local:
lrcfg > 3) local > 1) list of files that should be saved > 

var/lib/lrpkg/local.local
etc/terminfo/x/xterm-256color
root/.ssh/authorized_keys
root/GPIO4reboot.sh
sbin/reboot
sbin/old_reboot
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

Have fun