Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvaz/771bb5f028cacede71f4 to your computer and use it in GitHub Desktop.
Save mvaz/771bb5f028cacede71f4 to your computer and use it in GitHub Desktop.
My notes on setting up a Raspberry Pi with an Edimax EW-7811UN WiFi Dongle and motion sensors

Raspberry Pi, WiFi and motion sensors

My notes on setting up a Raspberry Pi with an Edimax EW-7811UN WiFi Dongle and motion sensors.

We intend to use a few Raspberry Pis around the office, in order to find out if certain rooms are beeing used or not. For this, we need to get WiFi and a motion sensor working.

WiFi (Edimax EW-7811UN)

The 2012-08-01 raspbian-wheeze (verify this) which I'm running, supports the WiFi dongle outh of the box. Configuring it and keeping it from crashing can be a little tricky though.

First off don't use an ethernet cable to connect to the RBP, as this will draw too much power and you're gonna have a bad time.

For DHCP, edit /etc/network/interfaces (2)

iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

If you'd like to configure a static IP (2):

iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
address 10.1.2.20
netmask 255.255.255.0
network 10.1.2.0
gateway 10.1.2.1

Since we will be connecting to a WPA2 WLAN, we need to configure wpa_supplicant.

Edit /etc/wpa_supplicant/wpa_supplicant.conf (2)

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="Your SSID Here"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk="YourPresharedKeyHere"
}

You should be able to start the wireless interface like this:

sudo ifdown wlan0 && sudo ifup wlan0

If you get errors like this, you can apparently ignore them (2):

ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument

Checking the status of your connection can be usefull. The command iwconfig will yield this:

lo        no wireless extensions.

eth1      no wireless extensions.

wlan0     IEEE 802.11bg  ESSID:"Your SSID Here"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:2.442 GHz  Access Point: NN:NN:NN:NN:NN:NN
          Bit Rate:54 Mb/s   Sensitivity:0/0
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=100/100  Signal level=95/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

eth0      no wireless extensions.

Add a startupscript, to make sure wpa_supplicant is beeing used (1):

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

exit 0

I was still having a few power issues, and disabling powermanagement helped (1):

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

If your RBP still looses it's connection after a while, you might need to ping a network node every minute or so (1).

The WiFi dongle logs it's errors to /var/log/syslog. That's how I found out about the ethernet problem.

Motion sensors

Sources

Power management and startup script

(1) http://svay.com/blog/setting-up-a-wifi-connection-on-the-raspberrypi/

Network configuration

(2) http://kerneldriver.wordpress.com/2012/10/21/configuring-wpa2-using-wpa_supplicant-on-the-raspberry-pi/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment