Wednesday, November 07, 2012

My Raspberry Pi has gone wireless

A few days ago I found a Dynamode Wifi USB adapter on ebay for a very nice price and since Adafruit's wifi adapter was not in stock, I decided to get it. I was worried it may not work with my Pi but I risked it. For some reason, I thought it uses a Realtek 8188CU chip so I figured it will be easy to configure it, given all the info I found at elinux.org and other websites. I plugged it in my powered hub and the first problem showed up: a bunch of errors at boot time, like smsc95xx ... kevent 4 may have been dropped - the only way to get the Pi to boot was to unplug the dongle. This happened on both SD cards I have, one with Raspbian Wheezy and the other with Adafruit's Occidentalis.

After a bit of digging, I found that this is a common problem that is addressed by Hexxeh's rpi-update. It took a while for the firmware to be updated but it worked, next time I booted there were no more errors.

Now I had to configure it. After a lot of frustrating time trying to make it work, I had the idea of using lsusb (I know, should've done this from the beginning!) and to my surprise, lsusb reported a Ralink RT5370 chip. Again elinux.org helped a lot, this page has all the info (I will not mention the time I wasted thinking the router was setup with WPA when instead it was WEP and not being able to understand why I was not getting an IP address and all the DHCP requests were not successful). Finally, got it to work! This was an awesome moment!

After that, I gave up on the old router and used the main one we have setup with WPA. It took a little more setup but again, all the info was on the same elinux.org page and it worked from the first try. This was on Raspbian. Next I tried the same on Occidentalis and after a bit of hickup, got it to work here as well (on Occidentalis for some reason the adapter is wlan1 instead of wlan0, not sure why this is the case but after realizing this, all was well). The steps are:

1) sudo apt-get install wpasupplicant
2) sudo apt-get install firmware-ralink
3) sudo wpa_passphrase NetworkEssid password
4) sudo nano /etc/wpa_supplicant.conf - paste text from step 3, remove the passkey line:
network={
       ssid="NetworkEssid"
       psk=945609a382413e64d57daef00eb5fab3ae228716e1e440981c004bc61dccc98c
 }
5) sudo wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf - ctrl+c to stop
6) sudo nano /etc/network/interfaces - add:
auto wlan0
     iface wlan0 inet dhcp
     wpa-driver wext
     wpa-conf /etc/wpa_supplicant.conf
7) sudo ifup wlan0

After a few messages like "DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6" the wifi adapter should get an IP. If not, something is wrong, start over with the steps above.

So now I have a wireless connection for my Pi. I love it!

There are 2 things I still need to figure it out:
  1. For some reason, the Adafruit's WebIDE doesn't want to connect when I use the wireless adapter. It works great when using the wired connection but not on wireless. SSH works fine using raspberrypi.local so probably this is not the problem - I logged an issue on github and hopefully I will hear back. If not, no problem, I can use the wired connection for WebIDE and wireless for other projects I plan.
  2. I am not sure how to connect to different wireless networks automatically - I want to do this in case I take my Pi with me at work for example. From what I gather at this time, I need to change the /etc/wpa_supplicant.conf config file and run the config command sudo wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf every time but there has to be a simpler way. I'll try and see if I can come up with something.

In any case, this was a lot of work for me being a Linux newbie but getting connected was a real breakthrough. I'm really happy to have one less wire to connect when I run my Pi headless.

A huge thanks to everyone posting information and help on the web, particularly to Hexxeh and the guys contributing to elinux.org Raspberry Pi pages!

No comments:

Post a Comment