pipi getting a headless raspberry pi on the wifi network

Sat, Nov 24, 2012

The Raspberry Pi Model B has arrived at last but at least the long wait has been worth it. It’s the new 512Mb version. So let’s get it up and running on wifi without a monitor, keyboard or mouse.

Raspberry Pi Model B 512Mb

This is my ‘parts list’ to get this lovely little thing onto the wifi network:

  • Raspberry Pi (of course!)
  • TP-LINK TL-WN722N wifi dongle (works out of the box just about on the latest OS). Check for more here.
  • Powered USB hub. The TP-LINK needs a powered one. I used a D-LINK DUB-H4.
  • 5V power source, case, ethernet cable, OS SD Card (I ordered these from RS Components when I ordered the pi)
  • Another computer. I used OS X to shell into the pi.

First step is to insert the SD card into its slot on the other side from the power connector. Don’t forget this or you’ll just get a steady red light when you power it up! Then plug one end of the ethernet cable into the pi and the other into your wireless router. Bung in the power cable and the LEDs will start going yellow and green. On the other computer load up your router’s admin interface, usually http://192.168.1.1 and look for the connected pi.

Host Name    IP Address   MAC Address
raspberrypi  192.168.1.6  F8-D1-11-17-6E-39

You can use the MAC address later to get your router to assign a static IP to it to make it easier to shell into from the other computer. SSH is enabled by default these days on the pi but first, let’s be really cool and create a host definition on the Mac first:

sudo vi / etc/hosts
…
192.168.1.6     pi
fe80::1%lo0     localhost

and now we can shell into it:

ssh pi@pi
…
password is raspberry

Now that we’re in, we need to free it from its wired bonds. So shut it down for the moment:

sudo shutdown -h now

remove the pi’s power lead, plug in the powered USB hub’s power source, plug the TP-LINK into the hub and plug the hub into the pi. Then power up the pi again and shell into it:

ssh pi@pi

Now add a source from which to pull down packages:

sudo vi / etc/apt/sources.list

add this line to the end of the file:

deb http://ftp.us.debian.org/debian squeeze non-free

update everything:

sudo aptitude update

you may need to install the TP-LINK’s firmware:

sudo aptitude install firmware-atheros

but when I did it nothing was installed but you can verify it exists. I think the latest OS comes with it installed:

sudo aptitude search firmware-atheros
…
i   firmware-atheros  - Binary firmware for Atheros wireless cards

That should be the wifi dongle supported so now scan for your wifi network:

sudo iwlist wlan0 scan | grep ESSID
…
  ESSID:“Groovy”

add the network to the pi’s config:

sudo vi /etc/network/interfaces

auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wireless-essid Groovy

and start up the wifi interface:

sudo ifup wlan0

Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/f8:d1:11:17:6e:39 Sending on LPF/wlan0/f8:d1:11:17:6e:39 Sending on Socket/fallback DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 3 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 18 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPOFFER from 192.168.1.1 DHCPACK from 192.168.1.1 bound to 192.168.1.7 – renewal in 101934 seconds.

You should now have a new client on the wifi network. Check it’s enabled on the pi:

pi@raspberrypi ~ $ ifconfig
…
wlan0     Link encap:Ethernet  HWaddr f8:d1:11:17:6e:39
          inet addr:192.168.1.7  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:998 (998.0 B)  TX bytes:1086 (1.0 KiB)

If you look in your router admin page again you’ll see the new client with a new IP address. Note that IP address and change your / etc/hosts definition so ‘pi’ points to that one instead of the ethernet one, which we don’t need any more. The last bit is to boot the wifi at startup. Add this to / etc/rc.local just before the ‘exit 0’ line:

echo “Starting WiFi…”
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
sleep .5s
dhclient wlan0
echo “WiFi should be started”

then install something with an odd sounding name that will load up your wifi interface at boot:

sudo apt-get install wpasupplicant

create its config file:

sudo vi /etc/wpa_supplicant.conf

network={ ssid=“Groovy” }

and then shutdown the pi again but this time pull the ethernet cable out of the router. When you power the pi back up it’ll come onto the wifi network all by itself and you’re ready to pi@pi.

References:

comments powered by Disqus