RPi 3G Mobile connection with Huawei E173

From EnigmaGuy Wiki
Jump to navigation Jump to search

Preface

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

Download

You can get all mentioned configuration files from My GitHub

Notice

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
TargetProductList="1001,1406,140b,140c,1412,141b,1432,1433,1436,14ac,1506,1511"

MessageContent="55534243123456780000000000000011062000000100000000000000000000"

PPP

For dialing I use ppp with these files:

/etc/ppp/peers/huawei

/dev/serial/by-id/usb-HUAWEI_Technology_HUAWEI_Mobile-if00-port0
115200

nodetach
connect '/usr/sbin/chat -v -f /etc/ppp/peers/huawei-on'
disconnect '/usr/sbin/chat -v -f /etc/ppp/peers/huawei-off'
noauth
usepeerdns
local
defaultroute
replacedefaultroute
noipdefault

/etc/ppp/peers/huawei-on

ABORT BUSY ABORT 'NO CARRIER' ABORT ERROR
'' AT
AT ""
OK ATZ
OK AT+CGDCONT=1,"IP","internet"
OK "AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
OK ATX3
OK "ATDT*99#"
CONNECT \d\c

/etc/ppp/peers/huawei-off

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

/etc/ppp/peers/provider

# 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 myusername@realm 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 "myusername@realm"

# 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.
/dev/modem

# Speed of the serial line.
115200

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

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

# Do not ask the remote to authenticate.
noauth

Controlling connection

Connect pppd call huawei &

Disconnect pkill pppd