Difference between revisions of "How to use an Android tablet as a Raspberry Pi console terminal and internet router"

From eLinux.org
Jump to: navigation, search
(Connect Raspberry to Android tablet)
 
(External links)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
Use an Android tablet as console and internet router for your Raspberry Pi.
+
Use a tethered [[Android tablet]] as [[console]] and [[internet router]] for your [[Raspberry Pi]].
This even works with a Raspberry Pi model 1A having no ethernet port...
 
  
 
==What you need==
 
==What you need==
*A [[Raspberry Pi]]
+
*Any Raspberry Pi — it even works with a Raspberry Pi model 1A having '''no''' ethernet port...
*A micro-USB power supply
+
*A [[micro-USB power supply]]
*A micro-USB cable
+
*A [[micro-USB data cable]]
*An Android tablet (of smartphone if you insist)
+
*An Android tablet (or on a smartphone if you insist)
*The ConnectBot App (available from Google Play)
+
*The [[ConnectBot]] App (available from [[Google Play]])
  
 
==Advantages==
 
==Advantages==
*The Raspberry Pi uses very low power (no ethernet)
+
Very universal solution:
*Your Android tablet can be powered via the Raspberry Pi
+
*The Raspberry Pi uses very low power (no or inactive ethernet port)
*You have a virtual keyboard, mouse, and video display for your Raspberry Pi
+
*Your Android tablet can be powered via the Raspberry Pi USB port
*Both devices have easily access to internet
+
*You have a virtual keyboard, mouse, and video display (KVM) for your Raspberry Pi
 +
*Only 1 single Raspberry Pi USB port is required to deliver ethernet, and [[KVM access]]
 +
*Both devices can easily share an internet connection
 +
*The Raspberry Pi can have Wi-Fi or mobile network access through tablet tethering
 +
*You do not need any special hardware; except for a few standard micro-USB cables
 +
*It also works e.g. in a car using a 12V outlet
 +
*Only standard software needed
 +
*[[Autoconfiguration]] ([[plug and play]])
  
==Install ConnectBot==
+
==How to==
Install ConnectBot on your tablet which is an Android terminal emulator available from Google Play.
+
===Install ConnectBot===
It allows to SSH into the [[Raspberry Pi]].
+
Install ConnectBot on your tablet which is an [[Android terminal emulator]] available from Google Play.
 +
It allows to SSH into the Raspberry Pi.
  
==Configure the Raspberry Pi==
+
===Configure the Raspberry Pi===
Add the following lines:
+
You can perform those changes when connected via any method to your Raspberry Pi.
 +
 
 +
Add the following lines into your network configuration:
 
  [[vi]] /etc/network/interfaces
 
  [[vi]] /etc/network/interfaces
 +
 
  allow-hotplug usb0
 
  allow-hotplug usb0
 
  iface usb0 inet dhcp
 
  iface usb0 inet dhcp
  
==Connect your devices==
+
When you would have already connected all devices, and you do not want to reboot, just restart the network:
 +
/etc/init.d/networking restart
 +
 
 +
===Connect your devices===
 
Connect your Android Tablet to a Raspberry Pi USB port via a micro-USB cable.
 
Connect your Android Tablet to a Raspberry Pi USB port via a micro-USB cable.
 
Power your Raspberry Pi with a standard USB power supply.
 
Power your Raspberry Pi with a standard USB power supply.
 +
You can use any DC USB power supply.
  
==Enable Android USB tethering==
+
===Enable Android USB tethering===
 
Enable USB tethering on your Android tablet.
 
Enable USB tethering on your Android tablet.
 +
Settings → Connections → Tethering and Wi-Fi hotspot → USB tethering
  
Now the Raspberry gets an IP address via its USB0 port;
+
Now the Raspberry automatically gets an IP address via its USB0 port.
the Android tablet behaves like a NAT router.
+
The Android tablet behaves like a NAT router.
 
This should work both when your tablet is connected to Wi-Fi
 
This should work both when your tablet is connected to Wi-Fi
 
or to a mobile 3G/4G network.
 
or to a mobile 3G/4G network.
  
==Initiate an SSH login on the Raspberry Pi==
+
===Initiate an SSH login to the Raspberry Pi===
*Start the ConnectBot App
+
*Start the ConnectBot App on Android
 
*Login to the Raspberry Pi via SSH
 
*Login to the Raspberry Pi via SSH
 
The only problem is that you have to know the IP address of the Raspberry Pi;
 
The only problem is that you have to know the IP address of the Raspberry Pi;
at my device it was 192.168.42.159... but till now I do not have an easy way to see this...
+
it seems to be (always?) 192.168.42.159...
 +
 
 +
==Network setup==
 +
[[ifconfig]]
 +
 
 +
eth0    Link encap:Ethernet  HWaddr b8:27:eb:b5:d4:ba
 +
          inet addr:192.168.31.36  Bcast:192.168.31.255  Mask:255.255.255.0
 +
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 +
          RX packets:10538 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:7235 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:1000
 +
          RX bytes:1039975 (1015.6 KiB)  TX bytes:929333 (907.5 KiB)
 +
 
 +
lo      Link encap:Local Loopback
 +
          inet addr:127.0.0.1  Mask:255.0.0.0
 +
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
 +
          RX packets:4010 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:4010 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:0
 +
          RX bytes:168456 (164.5 KiB)  TX bytes:168456 (164.5 KiB)
 +
 
 +
usb0    Link encap:Ethernet  HWaddr 02:07:00:01:62:31
 +
          inet addr:'''192.168.42.159'''  Bcast:192.168.42.255  Mask:255.255.255.0
 +
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 +
          RX packets:19830 errors:0 dropped:1 overruns:0 frame:0
 +
          TX packets:10412 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:1000
 +
          RX bytes:21499431 (20.5 MiB)  TX bytes:2806515 (2.6 MiB)
 +
 
 +
[[route]] -n
 +
 
 +
Kernel IP routing table
 +
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
 +
0.0.0.0        '''192.168.42.129'''  0.0.0.0        UG    0      0        0 usb0
 +
192.168.31.0    0.0.0.0        255.255.255.0  U    0      0        0 eth0
 +
192.168.42.0    0.0.0.0        255.255.255.0  U    0      0        0 usb0
 +
 
 +
==Tips==
 +
You could as well connect an UTP network cable as well;
 +
then you have a dual-homed network connection
 +
with the advantage that you can:
 +
*issue simple (configuration) commands from your tablet
 +
*use a laptop to perform more complicated command via the other SSH connection
 +
 
 +
==Other ideas==
 +
*This could work as well with other USB devices having no built-in network connection...
 +
*[[Display a Raspbian desktop on Android using VNC]]
 +
*You could run [[X Window System]] applications from your Raspberry Pi
 +
 
 +
==Known problems==
 +
===Tethering not started===
 +
ssh pi@192.168.42.159
 +
 
 +
ssh: exited: Error connecting: No route to host
 +
*Did your [[Raspberry Pi]] [[reboot]]?
 +
*Power failure?
 +
*Start [[USB tethering]] on [[Android tablet]]/[[smartphone]]
 +
 
 +
===Not enough power===
 +
Make sure that you have a decent [[power supply]];
 +
the [[Android tablet]] will suck current from the Raspberry Pi [[USB port]].
 +
 
 +
==External links==
 +
*[https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=90728 Accessing Internet from Pi using USB Tethering of Android]

Latest revision as of 01:43, 12 October 2015

Use a tethered Android tablet as console and internet router for your Raspberry Pi.

What you need

Advantages

Very universal solution:

  • The Raspberry Pi uses very low power (no or inactive ethernet port)
  • Your Android tablet can be powered via the Raspberry Pi USB port
  • You have a virtual keyboard, mouse, and video display (KVM) for your Raspberry Pi
  • Only 1 single Raspberry Pi USB port is required to deliver ethernet, and KVM access
  • Both devices can easily share an internet connection
  • The Raspberry Pi can have Wi-Fi or mobile network access through tablet tethering
  • You do not need any special hardware; except for a few standard micro-USB cables
  • It also works e.g. in a car using a 12V outlet
  • Only standard software needed
  • Autoconfiguration (plug and play)

How to

Install ConnectBot

Install ConnectBot on your tablet which is an Android terminal emulator available from Google Play. It allows to SSH into the Raspberry Pi.

Configure the Raspberry Pi

You can perform those changes when connected via any method to your Raspberry Pi.

Add the following lines into your network configuration:

vi /etc/network/interfaces
allow-hotplug usb0
iface usb0 inet dhcp

When you would have already connected all devices, and you do not want to reboot, just restart the network:

/etc/init.d/networking restart

Connect your devices

Connect your Android Tablet to a Raspberry Pi USB port via a micro-USB cable. Power your Raspberry Pi with a standard USB power supply. You can use any DC USB power supply.

Enable Android USB tethering

Enable USB tethering on your Android tablet.

Settings → Connections → Tethering and Wi-Fi hotspot → USB tethering

Now the Raspberry automatically gets an IP address via its USB0 port. The Android tablet behaves like a NAT router. This should work both when your tablet is connected to Wi-Fi or to a mobile 3G/4G network.

Initiate an SSH login to the Raspberry Pi

  • Start the ConnectBot App on Android
  • Login to the Raspberry Pi via SSH

The only problem is that you have to know the IP address of the Raspberry Pi; it seems to be (always?) 192.168.42.159...

Network setup

ifconfig
eth0     Link encap:Ethernet  HWaddr b8:27:eb:b5:d4:ba
         inet addr:192.168.31.36  Bcast:192.168.31.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:10538 errors:0 dropped:0 overruns:0 frame:0
         TX packets:7235 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:1039975 (1015.6 KiB)  TX bytes:929333 (907.5 KiB)
lo       Link encap:Local Loopback
         inet addr:127.0.0.1  Mask:255.0.0.0
         UP LOOPBACK RUNNING  MTU:65536  Metric:1
         RX packets:4010 errors:0 dropped:0 overruns:0 frame:0
         TX packets:4010 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:168456 (164.5 KiB)  TX bytes:168456 (164.5 KiB)
usb0     Link encap:Ethernet  HWaddr 02:07:00:01:62:31
         inet addr:192.168.42.159  Bcast:192.168.42.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:19830 errors:0 dropped:1 overruns:0 frame:0
         TX packets:10412 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:21499431 (20.5 MiB)  TX bytes:2806515 (2.6 MiB)
route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.42.129  0.0.0.0         UG    0      0        0 usb0
192.168.31.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.42.0    0.0.0.0         255.255.255.0   U     0      0        0 usb0

Tips

You could as well connect an UTP network cable as well; then you have a dual-homed network connection with the advantage that you can:

  • issue simple (configuration) commands from your tablet
  • use a laptop to perform more complicated command via the other SSH connection

Other ideas

Known problems

Tethering not started

ssh pi@192.168.42.159
ssh: exited: Error connecting: No route to host

Not enough power

Make sure that you have a decent power supply; the Android tablet will suck current from the Raspberry Pi USB port.

External links