Creating a 3G hotspot with the Raspberry Pi

Installation

To get started, you should install a standard version of Raspbian. As usual, you should burn this to an SD card and install it on first boot. The Rasp Pi should access the Internet via a cable that is connected to the home router. Using the commands in Listing 1, you can quickly install all of the necessary packages.

Listing 1

Installing Programs

$ sudo apt-get update
$ sudo apt-get install usb-modeswitch usb-modeswitch-data bridge-utils ppp wvdial hostapd iw dnsmasq vnstat lighttpd php5-cgi phpsysinfo php-apc

Now it is time to pay attention to router functions. The first step is to install the UMTS stick. These sticks typically emulate other devices, as well as a UMTS modem, so you might encounter your first obstacle here. For example, the stick I used had a storage drive for an optional internal microSDHC card and a mini-CD drive with an "inserted CD." The manufacturer delivered the drivers required for Windows, as well.

At first, you will only see the storage and the CD drive after plugging in the stick; you have to send a command to the stick to activate the UMTS modem function. Typically, the Windows driver performs this mode switch. Under Linux, the software from the usb-modeswitch package performs this task when the device is plugged in. It is here that the chaff is separated from the wheat. If the Linux kernel supports the stick, you will find a device file such as /dev/ttyUSB0 and possibly also other files with suffixes like USB1 and USB2. Other messages should also appear in the /var/log/messages logfile that indicate that the stick has now made a modem available.

However, be careful, because Raspbian sometimes misbehaves when a stick is connected. See the box entitled "UMTS Sticks and the Rasp Pi." If the stick you have chosen does not work right away with Linux, it is a good idea to do a little research over the Internet, where you will find instructions for getting many UMTS dongles to work on Linux. It is beyond the scope of this article to describe all problems that a stick can potentially cause.

UMTS Sticks and the Rasp Pi

In general, many UMTS sticks are compatible with Linux, but issues arise when a Rasp Pi is added to the mix. If the stick is inserted after booting, the mode switch works without problem. The outcome is different if the stick is inserted before the system boots. In short, nothing will happen. The culprit here is the udev daemon, which is responsible for switching too late. The hardware on the stick is already initialized and udev is unaware of this. A workaround here is to add the instruction

udevadm trigger

to the /etc/rc.local file before the last line containing the exit command. This causes all cold boot events to be re-executed so that the mode switch functions.

Dial-In

In the days before DSL, a dial-in program provided an Internet connection. The connection was made via PPP (point-to-point protocol). Contemporary UMTS modems are based on this protocol as well. The modem that has been embedded in the stick dials in and creates a connection to a remote station. The pppd daemon holds the line and makes the Internet connection available. In the Rasp Pi router, this complex task is performed by the WvDial dial-in program.

After installing to and plugging in the stick, you should call

sudo wvdialconf

once. If the stick has already been plugged in during the installation process, the call occurs automatically. The configuration program communicates a few basic values for the initialization and communication with the modem and then writes the results in the /etc/wvdial.conf file, to which you need to add some service provider-specific information. Listing 2 shows an example for Tchibo Mobile in Germany.

Listing 2

/etc/wvdial.conf

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
ISDN = 0
Modem = /dev/ttyUSB0
Baud = 9600
[Dialer pin]
Init3 = AT+CPIN=1234
[Dialer pinstatus]
Init3 = AT+CPIN?
[Dialer umts]
Init3 = AT+CGDCONT=1,"IP","webmobil1"
Stupid Mode = 1
Phone = *99***1#
Username = random
Password = random
Dial Attempts = 3

The best way to find out what you need to add is to google wvdial and your provider's name. Information about the APN settings for various mobile phone service providers in various countries can be found online [3]. You can enter more than one provider in the file if you always begin the corresponding sections with [Dialer <provider>].

Afterward, you should save the file, terminate all standard Internet connections, and call the commands:

$ sudo wvdial pin
$ sudo wvdial umts

If all goes well, WvDial will start the pppd daemon. Using ifconfig, you can check in a second window to see whether the ppp0 Internet interface is available. If no connection has been established, the output from WvDial can help you find the error. It is sufficient to disconnect WvDial and pppd with Ctrl+C, because you started the dial-in program from a terminal window. If you restart the connection, you will not have to re-enter the PIN. The second WvDial command can be used instead. To avoid always having to do a manual start of the connection, Linux applications can arrange for the connection to be established automatically.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content