Monday, August 12, 2013

Setting up a truly portable Raspberry Pi system



One of the salient features of Raspberry Pi is its portability. Being credit card sized, it is as portable as a smartphone. But it doesn’t have a built-in display, input mechanism, wifi connectivity or battery like a smartphone. After you plug in a monitor, keyboard, mouse, network cable and a power cable to the Pi, you lose most of the portability benefits. You can regain most of the portability benefits by setting up your Pi as a headless unit. In a headless setup, you do not have to plug in a monitor, keyboard or mouse. If you attach a wifi dongle you don’t even need the network cable. Just plug in the power cable and you are good to go. If you want complete portability you can even attach a small battery pack to Raspberry Pi case.


So how do you operate the Raspberry Pi computer without attaching any of the peripherals. The solution is remote access. You access the Pi through the network and make all changes through a shell or a remote desktop. You will have to connect all the peripherals like the monitor, keyboard, mouse and network cable for initial setup. But after you have setup your Pi correctly, you can connect your Pi to any network and control your Pi from any computer in the network.


Steps to setup Raspberry Pi for shell connectivity

1) Open a terminal and type

sudo raspi-config

It will open a nice config tool that allows you to configure various aspects of your Raspberry Pi system.

2) Enable SSH server
3) Connect to Raspberry using an SSH client.

There are various articles on the internet that describe how to connect to a linux system using an ssh client. Mac and Linux systems have built-in ssh clients. So it is as simple opening a terminal on your Mac and typing the command 

ssh <username>@<ip-address>

where username is the name of the account on Pi you are trying to connect to and ip-address is local IP address of your Pi. On windows systems, you can use the Putty tool as your ssh client.

You can find the local IP address of your Pi system using the command ifconfig. After you have tested ssh connectivity, you need to establish a mechanism to find the IP address of your Pi without a monitor attached. One solution would be to assign a static IP address to the Pi as described in Step 2 of this guide. But as the guide explains, this method is suitable only if you keep your Pi plugged into the same network all the time. But since our goal is a truly portable system, we need to keep the DHCP mechanism to obtain IP address and connect to the network. A flexible way to find the IP address of Pi system is to lookup the IP address by hostname.

IP Address lookup by Hostname

You can find the hostname of your Pi using the command

hostname

It would be a good idea to assign a unique hostname to your Pi to avoid hostname conflicts when you connect your Pi to different networks. This guide describes how to change the hostname of your Pi.

After you have assigned a unique hostname, install the samba server on your Pi. The samba server may be installed using the command

sudo apt-get install samba

Installing samba server allows windows clients to lookup the IP address by hostname.

To find the IP address of your Pi from windows or linux system, type the command

ping <hostname>

From a Mac system, type the command

ping <hostname>.local

The IP address will be returned in the response.


Connecting to Raspberry Pi Remote Desktop


While shell connectivity is sufficient to get most things done on the Pi, sometimes it is nice to have a GUI. You can achieve this by setting up remote desktop server on your Pi. Here is a guide to setup remote desktop on your Pi. In summary all you need to do is install the xrdp sofware using the command

sudo apt-get install xrdp

You may then use the IP address of Pi to connect to the remote desktop of Pi. On Windows systems you may use the built-in windows remote desktop connection tool to connect to remote desktop. On Mac systems you can install the remote desktop client for Windows. On Linux systems you may use any of the rdp clients such as Remmina or the Vinagre RDP client.

2 comments: