SSH Back to Raspberry Pi from an Android Hotspot / Tether.

Configuring, managing or simply debugging a headless Raspberry Pi is a common problem - compared to the diminutive size of the Pi, the monitor, keyboard (though good wireless pocket-size units exist) take up a disproportionate amount of space. Nonetheless, most of us carry mobile phones, that could easily work as a remote control device.

HotSpot or Tether

While the ability to create HotSpots on the fly have certainly eliminated most of the need for wired tethers, the tether has numerous advantages

  1. Automatic Connection - most systems would automatically connect to the tethered phone (which, in itself, is a security concern, but that's subject for another post), while a WiFi hotspot needs to be pre-configured.
  2. Route to WiFi - HotSpots cannot be deployed while the mobile device is connected to a wireless LAN itself. This can not only waste data (for those on limited plans, but even unlimited are often throttled), but also is likely slower than a wireless connection.
  3. One at a time - One can only tether to a single device - which means, figuring out which of the connected devices is our embedded system can be tricky.

On the other hand, HotSpot can be useful because it is wireless. One can leave the device configured to connect to a specific wireless network, if it comes in range. This can simplify diagnostics and debugging, to simply configuring the HotSpot to match.

Finding the device

Unfortunately, Android phones assign random IP addresses to the devices they share network access with, and do not persist these assignments - which means, next time, they are likely to assign a completely random address instead

This means, before connecting, one needs to scan to find the device in the HotSpot network range. In addition, the hotspot network ranges are usually unknown to the user (however, 192.168.42.0/24 is commonly used for wired (USB) tethers, and 192.168.43.0/24 for wireless access point ranges).

Manual Method

Classically, as documented on Instructables or on eLinux, one needed to combine a range of generic tools to first scan the network environment, then to connect to appropriate device. This is cumbersome, especially if done dozens of times a day as one develops the embedded firmware.

SSH Back

Out of this motivation, I created a very simple (literally ~100 lines of code) Android application that scans all tethering (or tethering-like) network interfaces of the phone, and issues an Android Intent to SSH to the first match.

As a result, the entire process is much faster and more streamlined. Enjoy!

HTTP Back

This app also has an HTTP sibling (HTTP Back) - it's very similar, but it connects back to the HTTP port using the default browser. It can be handy for Raspberry-Pi based kiosks, configuration servers etc.