Installing 3G Modem

If you have 3G modem, you can easily connect it to your precious RPi and have internet everywhere you go. This can be first step to turn your RPi into wireless 3G router or you can just do it to make sure, that wherever you go, XBMC would be able to download subtitles for the movie :) So, here are step by step instructions… If you need to buy 3G modem, make sure that it is well supported by RPi – this article was tested using Huawei 220. Verified peripherals can be found here

Before we start, connect your modem to powered USB hub and connect the hub to your RPi. Now you can turn on RPi.

I always recommend running package update before we start installing anything:

sudo apt-get update

No we need to install ppp:

sudo apt-get install ppp

Now we need a client to connect to the internet – name of the program is sakis3G.

[14-June-2013] sakis3g stopped working for me in raspbmc. If you also have problems see bottom of the article where I use wvdial.

SAKIS3G version

Since at the time when this article was created, web site www.sakis3g.org was not working, you can download sakis3g from our server. From RPi shell you can download it like this:

wget "http://raspberry-at-home.com/files/sakis3g.tar.gz"

I suggest you copy the file to /usr/bin/modem3g directory and unpack it:

sudo mkdir /usr/bin/modem3g sudo chmod 777 /usr/bin/modem3g sudo cp sakis3g.tar.gz /usr/bin/modem3g cd /usr/bin/modem3g sudo tar -zxvf sakis3g.tar.gz sudo chmod +x sakis3g

Sakis3G is smart enough to read internet settings from your sim card – all you need to do is to point it to use the right connection setting.

Here is what we get without any further configuration (for now):

sudo ./sakis3g connect

Please select APN by using APN variable, or by enabling interactive mode.

$ /usr/bin/modem3g/sakis3g --interactive "connect"

Available options are:

Internet (Internet)

CUSTOM_APN Custom APN...

Example:

$ /usr/bin/modem3g/sakis3g APN="Internet"

Internet is a APN setting from my SIM card. In order to use it you can start sakis3g with the command as in example above and adding connect word, but personally I suggest creation of /etc/sakis3g.conf file with single line:

APN="Internet"

Please note that the line can be different for your operator/APN setting. In case (for some reason) sakis3G is not able to detect your internet APN setting you can enter in conf file all other necessary information. In this case follow instructions from ./sakis3g man sakis3g.conf

When you’re done with creation of /etc/sakis3g.conf you can now run:

sudo ./sakis3g connect

E220 connected to PLAY (26006).

To disconnect just run:

sudo ./sakis3g disconnect

Disconnected.

If you don’t want to play with conf file you can always start sakis3G in interactive mode (even in console):

/usr/bin/modem3g/sakis3g --interactive "menu" "console"

wvdial version

WVDIAL is less intuitive then sakis3g and I find it quite hardcore but so far I haven’t found more decent replacement.
First, we need to install wvdial:

sudo apt-get -y install wvdial

Once installed we need to create a config file for it (/etc/wvdial.conf). Content of this file may be a bit different for some of you (if it is, let me know) but here is mine:

pi@raspbmc:~$ cat /etc/wvdial.conf

[Dialer Defaults]

Init1 = ATZ

Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0

Modem Type = Analog Modem

Baud = 9600

New PPPD = yes

Modem = /dev/ttyUSB0

ISDN = 0

; Phone = <Target Phone Number>

; Password = <Your Password>

; Username = <Your Login Name>

[Dialer play]

Modem = /dev/ttyUSB0

Baud = 460800

Init1 = ATH

Init2 = ATE1

Init3 = AT+CGDCONT=1,"IP","internet"

Dial Command = ATD

Stupid mode = yes

Username = "blank"

Password = "blank"

Section [Dialer Defaults] is automatically created when wvdial is installed. I have added section [Dialer play], because my GSM operator is PLAY MOBILE :). [Dialer play] section overrides settings from [Dialer Defaults] if there are any conflicts. Let me try to explain what [Dialer play] config items mean:

[Dialer play]

Modem = /dev/ttyUSB0 #device you will be using to connect - you may need to change it in case your modem is not detected with that setting

Baud = 460800 #baud rate - I am not sure what the setting should be and how it can impact network throughput - it is speed at which wvdial will communicate with your modem

#InitX commands belowy are Hayes commands that will be sent to modem

Init1 = ATH #hangup

Init2 = ATE1 #echo commands so we see what is going on

Init3 = AT+CGDCONT=1,"IP","internet" #defines packet data protocol context

# 1 : PDP context ID, minimum value is 1, maximum value depends on device (to be honest no idea what that is :) )

# protocol name [IP|IPv6|PPP]

# internet - is my APN name - may be different for you - check with your operator if needed

Dial Command = ATD # command to dial the number; not really needed in my case

Phone = *99# # number to dial (can be different for you)

Stupid mode = yes # wvdial will not interpret any prompts from the server

Username = "blank" # put user name here if you ISP requires it. If not, put any username here

Password = "blank" # put user name here if you ISP requires it. If not, put any username here

Full list of options can be found here:

Now we can connect (I suggest starting it in a separate shell thus & at the end; “play” is a name from a config file):

pi@raspbmc:~$ sudo wvdial play &

pi@raspbmc:~$ --> WvDial: Internet dialer version 1.61

--> Initializing modem.

--> Sending: ATE1

ATE1

--> Sending: AT+CGDCONT=1,"IP","internet"

AT+CGDCONT=1,"IP","internet"

--> Modem initialized.

--> Waiting for carrier.

ATDT*99#

CONNECT

--> Carrier detected. Starting PPP immediately.

--> Starting pppd at Fri Jun 14 22:35:19 2013

--> Pid of pppd: 3145

--> Using interface ppp0

--> local IP address 10.133.163.246

--> remote IP address 10.64.64.64

--> primary DNS address 89.108.202.20

--> secondary DNS address 89.108.195.20

Now you’re connected!… but how do disconnect?

Please note the line “[1] 3143″ – 3143 is your connection process PID. You need it to disconnect properly by issuing the following command:

pi@raspbmc:~$ sudo kill -1 3143

Caught signal 1: Attempting to exit gracefully...

pi@raspbmc:~$ --> Terminating on signal 15

--> Connect time 0.4 minutes.

--> Disconnecting at Fri Jun 14 22:35:50 2013

When I was testing this I realized that you should not be connected to the internet (i.e. via eth0) when modem connection is initiated. For some reason RPi would not get proper DNS even if you disconnect eth0 after you connect with the modem, so: first disconnect your lan cable and then connect.

Let me know is something is not working for you (use Discuss below)

Configuration for PLAY was found here.

Continue reading here: Lightberry - Your RPi Ambi-Like ; System

Was this article helpful?

0 0