I’m doing the network prototyping for my Product Development group project and the plan is to establish 3G connectivity on the RaspberryPi. I’m using a 3G USB Dongle from TDC, the primary ISP in Denmark. The model for the USB is E3131-s2 from Huwaei. Apparently all E3131 models are the same, with a small difference in supported operating frequencies. For the S2 model, it’s limited to 2100/900MHz, as we can see on the producers page.
Everything started with a google search on the topic – it seems that everybody is hyped about the Sakis3G script. Too bad it didn’t work for me. I settled for Wvdial (point-to-point dialer), a utility that is used for several years to establish internet connectivity with modems/3G dongles. Wvdial also required the ppp package and the USB dongle required usb-modeswitch to change which functionality should be used (the E3131 USB dongle also has a microSD slot – when plugged into a linux box, it is usually recognized as a storage device and not as a modem).
Before starting, make sure you:
- have a internet connection on the raspberry
- have raspbian installed on the raspberry
- you have access to the raspberry (the default authentication credentials for raspbian wheezy are pi/raspberry)
- know the APN settings for your carrier
Let’s install the packages
sudo apt-get update
sudo apt-get install ppp usb-modeswitch wvdial
I got this error, but don’t get scared, the wvdial will be created later.
sorry – you can retry autodetection at any time by running “wvdialconf” (or you can create /etc/wvdial.conf yourself.)
Plug in the USB dongle and get the identification codes with the lsusb command. You should see the default ids like below:
12d1:14fe Huawei Technologies Co., Ltd.
The numbers in the front are the identification codes. The first 4 stand for the VendorID and the last 4 stand for the ProductID. You can also check the vendor and product like i did here. Now reboot so that usb-modeswitch can do it’s job. After the reboot, run lsusb again to see the difference. As you can see below, the dongle is now identified as a GSM Modem and it’s ProductID has changed.
12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
Create a configuration file for usb-modeswitch. Replace the IDs with the default IDs on your device. (the output from the first lsusb)
tar -xzvf /usr/share/usb_modeswitch/configPack.tar.gz 12d1\:14fe
Copy the contents of the extracted file to the configuration file.
cat 12d1\:14fe >> /etc/usb_modeswitch.conf
The configuration file should contain the following, each being attributed with the values from your device. Those below are from mine. If you’re not sure about the content, just check my usb_modeswitch.conf file, right here.
Creating or generating a configuration file wvdial. I had a big issue when i used an example of the wvdial configuration file. It simply didn’t work. My solution to this was to generate it by issuing the wvdialconf command. The default location and name is:
After generating it, you still have to modify it with your APN settings. You can also take a look at my wvdial configuration file, and just modify with your settings.
APN name – its usually “internet”
Init3 = AT+CGDCONT=1,”IP”,”internet“
User – it’s usually blank
Password – it’s usually blank
Username = ” ”
Password = ” “
Phone – the number that the SIM card “calls” to initiate a connection. In my case it was *99#
Phone = *99#
Make sure the dongle is in modem mode by running usb_modswitch with the earlier created configuration file:
sudo usb_modeswitch -c /etc/usb_modeswitch.conf
Then you should be able to connect to the internet by issuing the command:
Now you should have internet connectivity. If not, no problem; it didn’t work for me either on the first attempt. Or the second.
Error message : Cannot open /dev/gsmmodem: no such file or directory
Solution : change the “Modem=” line in /etc/wvdial.conf , with the appropiate device. You can find that out by unpluging and pluging in the USB and checking dmesg.
dmesg | tail -n 20 | grep tty
[ 7874.507010] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0
[ 7874.515774] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1
[ 7874.518941] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2
Error message : +cme error: 11
Reason : the PIN for the SIM card is required to unlock it.
Solution : add the following line to your wvdial.conf file, and replace 7889 with your PIN
Init1 = AT+CPIN=7889
Error message :
don’t know what to do! starting ppd and hoping for the best.
unable to run /usr/sbin/pppdcheck permisions, or specify a PPPD Path option in wvdial.conf
Solution : you need to run wvdial as root – so instead of wvdial 3gconnect use sudo wvdial 3gconnect
Error : you finally have it working, you get an IP address but you don’t have any internet connectivity
Solution : uplug the dongle, plug it in and run wvdial again
Error message : ATDT*99# no carrier
Reason : either the phone number the sim is trying to “call” is not the one that your ISP has, or it’s something else that i have no idea.
Solution : verify that you have the correct number and try again. I had the correct number, but apparently there was something else. I created the /etc/ppp/peers/wvdial file with the following: