Set up the Raspberry Pi as a wireless router using the Raspbian OS. The internet connection will be provided by a Huawei E303 USB 3g dongle on the safaricom network in Kenya, though the setup should be similar on most Huawei dongles and 3g networks. The wireless access point will be provided by an Edimax Nano USB Wifi adapter.

Power Source -------->RPI ----> Powered USB HUB -----> 3g Dongle

The USB ports of the Pi seem to struggle to provide the power for a 3g dongle, so a powered USB hub is necessary.

After a lot of reading and messing around, I've come up with a step by step guide for setting up my Pi as a wireless internet router. I use this every time I make a fresh setup of Raspbian, which is a fairly regular event. Stumbling round my latest install like a drunken elephant, it never takes me long to screw something up so badly that it's easier just to start from scratch.

As such, this guide assumes that the Raspbian operating system is 'fresh'. It has been tested with the 2012-12-16 release - as soon as I have the time free, I'll update the guide for the newest release. So, the steps I use to set up the 'Pifi' Router are as follows:

This guide and more like it can be found on my blog.

Step 1: Make sure the Pi can see the 3g Dongle

Gather Information

To get more information about the USB devices connected to the Pi, we use the command 'lsusb'. Open a terminal window and type:


should give an output similar to this:

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 008: ID 050d:0234 Belkin Components F5U234 USB 2.0 4-Port Hub
Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 010: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard

lsusb lists the usb devices connected to the Pi, either directly or through the hub. I've highlighted the parts of the output that indicates the 3g dongle can be seen by the Pi. Yours should look similar to this, although it will vary from model to model - most 3g dongles on the market seem to be a Huawei of one flavour of another at the moment. So long as there is a mention of 'modem' or 'UMTS', you should be laughing. What you don't want to see is this:

Bus 001 Device 010: ID 12d1:14d1 Huawei Technologies Co., Ltd.

This is an issue that arises because your 3g dongle has a small partition on it containing the 'dashboard' software for windows. Your Pi has detected this partition, and labeled the dongle as a storage device before it had chance to notice the 3g modem waving its arms frantically in the background.

This happened occasionally with my 3g dongle - I would suggest following the next step even if you are feeling smug about your lsusb output at the moment. The next time you reboot your Pi it could detect your dongle as a storage device, throwing you into a fit of depression. Dangerous times

This can all be overcome with the use of usb_modeswitch. To install, in the terminal window type:

sudo apt-get install usb-modeswitch

The clue is in the name - its going to switch the mode of the usb device from 'storage' to 'modem. Yaaaaay. You need to give it some direction though, which will require some googling. The hexidecimal values highlighted here:

Good:   Bus 001 Device 010: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard

Bad:     Bus 001 Device 010: ID 12d1:14d1 Huawei Technologies Co., Ltd.

tell the operating system the vendor ID and device ID. More information on USB identification can be found on the debian wiki. Notice that the first 4 characters of the device ID (vendor ID) are the same in both examples, but the last 4 (device ID) have changed. Usb-modeswitch forces the operating system to use the combination that corresponds to the 3g modem.
usb-modeswitch usage

After usb-modeswitch has installed, an entry for your 3g dongle has to be made in /etc/usb_modeswitch.conf. If your device has already been detected, you can find the Device ID in the output from 'lsusb' - the portion highlighted in the examples above. If, however, you have the 'bad' example in your output, you need to find the correct Device ID (second part) for your 3g dongle - a good bet is a google search for '3g dongle model number usb_modeswitch'. Failing that, the search function of the usb-modeswitch forums. Your model number can normally be found somewhere on the device - try popping the cover off and looking for a sticker near where you insert the sim if you cant find it on the outside. We can assume the first part (vendor ID) is correct in both situations.

After a bit of research, the information I had to amend to the config file amounted to this:

DefaultVendor = 0x12d1
DefaultProduct = 0x1506
MessageEndPoint = "0x01"
MessageContent = "55534243000000000000000000000011060000000000000000 000000000000"

Once you have found the correct device ID, copy and paste the information above into a text editor. Amend the information to suit your own setup, deleting the bottom two lines if they are not needed - I'm not going to claim to understand the MessageEndPoint or MessageContent fields: They were part of the solution I found here - credit goes to krishnamohan of the fedoraforum.org site. Your device may or may not require them. Make sure to include the '0x' before the vendor and device IDs - this lets the Pi know that they are hexidecimal values.

To add this information to the usb-modeswitch config file, open the file for editing by issuing the following command in the terminal window:

sudo nano /etc/usb_modeswitch.conf

Paste the Device ID information from the text editor to the bottom of the config file you just opened in the terminal window. Hit Ctrl+X, y, Enter to exit and save changes.

Reboot your Pi and run 'lsusb', observing the output - if you found the right Device ID, you should see something to the 'good' output example shown above.

About This Instructable


100 favorites

More by BigCowPi: Raspbery Pi Wireless Auto-Sorting NAS/Media Server using MiniDLNA and Samba Raspberry Pi as a 3g (Huawei E303) wireless (Edimax EW-7811Un) router
Add instructable to: