RPi 3G Mobile connection with Huawei E173

From EnigmaGuy Wiki
Jump to: navigation, search


There are many Raspberry Pi usages where you need to connect to internet using 3G connection. Unfortunately I did not found any special devices for it or shields so best solutions (and also cheapest) is to use 3G USB stick. Because Raspberry Pi uses linux distribution many sticks are supported but generally older is better. For my purposes I bought Huawei E173 because it is one of few sticks which also supports voice with Asterisk Chan Dongle if you unlock it with DC Unlocker (paid but cheap app - apprx. 4 EUR for unlock). I did not used it anyway but if you are thinking about 3G USB stick you can buy this one old or new from Aliexpress for apprx. 20 USD with free worldwide shipping.

Basic usage is for rescue internet connection (e.g. if you use your RPi for home automation and security you should have plan for your cable modem go down) or for some remote location (e.g. residency in forrest etc...).

E173 USB Dongle from Huawei


You can get all mentioned configuration files from My GitHub


The main reason I wrote this article in spite of many similar articles on internet is because this one is concrete. It is with concrete provider, concrete modem with real solution. Not some general manual where half of it won't work because there are so many variables. This article is also usefull for me as my documentation for headaches I had. This one was tested with Huawei E173 CZ O2 edition

Setting up your Raspberry Pi

Problem with virtual CD-ROM

Majority of 3G USB Sticks (and Huawei E173 is no exception) has build-in flash drive which looks in operating system as virtual cd-rom with drivers for Windows OS. Unfortunately when virtual cd-rom is active, Linux OS could not use integrated modem in dongle. So this is a main reason why we need to use utility USB ModeSwitch to disable virtual cd-rom with drivers we do not even need.

USB ModeSwitch Installation

We will install USB ModeSwitch with few utilities at beginning...

sudo apt-get update
sudo apt-get install ppp usb-modeswitch wvdial

etc... You can find some more information about installation on this page How to setup a USB 3G Modem on Raspberry PI

Potential issues

Unfortunately not every guide on internet will write you about all issues. Basically Linux distributions use UDEV rules to perform action when hardware device is connected. On Raspberry Pi there are two directories with UDEV rules.

  • /etc/udev/rules.d/ - these do not works correctly
  • /lib/udev/rules.d - use these!

In udev rules after following linked tutorial you should find 40-usb_modeswitch.rules, it is possible that your Huawei modem won't work with predefined rules so I use specifically this rule:

# Huawei E173
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1446", RUN+="usb_modeswitch '%b/%k'"

And there is also catch in newer Huawei E173 modems - file /etc/usb_modeswitch.d/12d1:1446 should looks like this (minimally for Czech O2 3G USB stick this worked perfectly)

# Huawei, newer modems

TargetVendor=  0x12d1



For dialing I use ppp with these files:



connect '/usr/sbin/chat -v -f /etc/ppp/peers/huawei-on'
disconnect '/usr/sbin/chat -v -f /etc/ppp/peers/huawei-off'


'' AT
AT ""
OK AT+CGDCONT=1,"IP","internet"
OK "AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
OK "ATDT*99#"


"" "\K"
"" "+++ath"


# example configuration for a dialup connection authenticated with PAP or CHAP
# This is the default configuration used by pon(1) and poff(1).
# See the manual page pppd(8) for information on all the options.

# MUST CHANGE: replace [email protected] with the PPP login name given to
# your by your provider.
# There should be a matching entry with the password in /etc/ppp/pap-secrets
# and/or /etc/ppp/chap-secrets.
user "[email protected]"

# MUST CHANGE: replace ******** with the phone number of your provider.
# The /etc/chatscripts/pap chat script may be modified to change the
# modem initialization string.
connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T ********"

# Serial device to which the modem is connected.

# Speed of the serial line.

# Assumes that your IP address is allocated dynamically by the ISP.
# Try to get the name server addresses from the ISP.
# Use this connection as the default route.

# Makes pppd "dial again" when the connection is lost.

# Do not ask the remote to authenticate.

Controlling connection

Connect pppd call huawei &

Disconnect pkill pppd

Share your opinion