Control Raspberry Pi via USB connected Android device
Asked Answered
J

2

12

I have a Raspberry Pi with running custom server not connected to the internet (offline system).

I would like to connect Android device via USB cable to rPi and communicate with it.

As Raspberry Pi is not connected to the internet, it doesn't have IP address (given via DHCP).

How can I communicate with rPi using Android device connected via USB?

Maybe local DHCP server?

Thanks

Janetjaneta answered 2/3, 2014 at 13:0 Comment(4)
Have you seen this article raspberrypi.org/forum/viewtopic.php?f=36&t=18916 ?Therine
Yes, one of assumptions: "Your Android device has internet connectivity via WiFi/3G and it is enabled.". My system is fully offline.Janetjaneta
OK, I assumed that it was just the RPi that was offline.Therine
Not having upstream network may not matter.Beograd
S
7

Follow this link. You just have to configure the RPi for it once and you are good to go.

What this does:

  1. Allows you to use your Android device as keyboard input and terminal display for your Raspberry Pi

  2. Allows you to tether your Raspberry PI to your Android device's WiFi (3G untested, but should work).

Background:

I love the idea of a truly portable Raspberry Pi box. I wanted to make one, but I don't have a compatible WiFi dongle, nor do I have a wireless keyboard and mouse. Even if I did all of these things, I'd like to save myself the extra USB port by having both my network and input go over the same port. I guess the next thing to do after this would be to set up some sort of VNC server and connect to the Pi's GUI via the Droid.

My Build:

  • Raspberry Pi v2 (Linux raspberrypi 3.1.9+ #125 PREEMPT)
  • Asus Transformer Prime (Android 4.1.1. Jelly Bean)
  • Yoobao "Long March" -11200mA 1A / 2A battery (good for 10+ hours!)
  • VX ConnectBot terminal emulator (Free in the Google Play store)
  • Hackers Keyboard - because I like tab complete (Free in the Google Play store)

Assumptions:

  • Your PI is configured to run SSHd on startup
  • You are using the default Pi username / password
  • Your Android device has internet connectivity via WiFi/3G and it is enabled

How to do it:

  1. Add the following to /etc/network/interfaces

    iface usb0 inet static
    address 192.168.42.42
    netmask 255.255.255.0
    network 192.168.42.0
    broadcast 192.168.42.255
    
  2. Power down your Pi

  3. Connect your Android device to your Pi via it's USB data cable

  4. Power up your Pi... wait about a minute.

  5. On your Android device, go to Settings / Wireless & Networks / More / Tethering & Portable Hotspot... click "USB tethering"

  6. Start up VX ConnectBot and SSH "[email protected]"

  7. Keep hitting return until it asks you for your password. Enter it.

    Congratulations - you should now have terminal access to your Pi with a software keyboard... kinda. Mine seems to disconnect the session every minute or so - very annoying.

    Now to set up routing so that your Pi can see the world via your Android device.

  8. Root yourself up

    sudo su -
    
  9. Check to see which IP address that your Android device is using

    arp -a
    

    Mine is 192.168.42.129

  10. Add a default route pointing all traffic from your Pi out to your Android device. It's worth noting that this static route is temporary and will not survive rebooting your Pi. I've left it like this because I don't know if Android likes to change it's tether gateway address very often. If you've gotten this far, I'll assume you can figure out how to make a static route permanent if need be :)

    route add default gw 192.168.42.129 usb0
    
  11. Test it!

    ping http://www.google.com
    
Splat answered 1/4, 2014 at 11:19 Comment(0)
L
1

Setting a static ip won't work (always the dhcp that sets one). On the phone, you can see how to retrieve the IP address here : How to get the system ip address after usb tethering of android phone?

Leavening answered 26/3, 2018 at 17:58 Comment(1)
why doesnt static addressing work? Every instruction I have seen uses static addresses. I cannot get it to work so I would like to understand why.Sosanna

© 2022 - 2024 — McMap. All rights reserved.