Guide How to use Raspberry Pi with 3G USB Stick

Hardware Devices: Raspberry Pi (with Raspbian OS), Huawei LTE USB Modem

 

STEP 1: Install Needed Packages

sudo apt-get install ppp usb-modeswitch usb-modeswitch-data

STEP 2: Configure the 3G USB Modem as a Modem
a. Plugin the 3G USB Modem and verify the device details.

sudo lsusb

Bus 003 Device 003: ID 12d1:1436 Huawei Technologies Co., Ltd. Broadband stick
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

b. Update /etc/usb_modeswitch.conf based from the device details you obtained from above

sudo vi /etc/usb_modeswitch.conf

DefaultVendor=0x12d1
DefaultProduct=0x1436
MessageEndpoint=”0x01″
MessageContent=”55534243123456780000000000000011062000000101000100000000000000″

NOTE: The Message Content value is standard for HUAWEI Device

c. Reboot the Raspberry Pi device (Do note remove the 3G Stick). And verify that the 3G Modem is now detected properly from /var/log/syslog

 

August 03 21:56:36 sn-box usb_modeswitch: switching device 12d1:1446 on 001/007
August 03 21:56:36 sn-box kernel: [  533.141948] ehci_irq: port change detect
August 03 21:56:36 sn-box kernel: [  533.145965] usb 1-1: USB disconnect, device number 7
August 03 21:56:39 sn-box kernel: [  536.982223] ehci_irq: port change detect
August 03 21:56:40 sn-box kernel: [  537.261862] usb 1-1: new high-speed USB device number 8 using sw-ehci
August 03 21:56:40 sn-box kernel: [  537.424772] usb 1-1: New USB device found, idVendor=12d1, idProduct=1436
August 03 21:56:40 sn-box kernel: [  537.444195] usb 1-1: New USB device strings: Mfr=4, Product=3, SerialNumber=0
August 03 21:56:40 sn-box kernel: [  537.461071] usb 1-1: Product: HUAWEI Mobile
August 03 21:56:40 sn-box kernel: [  537.475642] usb 1-1: Manufacturer: HUAWEI Technology
August 03 21:56:40 sn-box kernel: [  537.496180] option 1-1:1.0: GSM modem (1-port) converter detected
August 03 21:56:40 sn-box kernel: [  537.515557] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
August 03 21:56:40 sn-box kernel: [  537.542851] cdc_ether 1-1:1.1: wwan0: register ‘cdc_ether’ at usb-sw-ehci-1, Mobile Broadband Network Device, 02:50:f3:00:00:00
August 03 21:56:41 sn-box logger: usb_modeswitch: switched to 12d1:1436 on 001/008

STEP 3: Add and Enable PPP Interface Configuration (We will call the interface as gprs)
a. Add the following lines on /etc/network/interfaces file

sudo vi /etc/network/interfaces

auto gprs
iface gprs inet ppp
provider gprs

b. add a corresponding peer configuration file ‘gprs’ in /etc/ppp/peers

sudo vi /etc/ppp/peers

user “anyname”
connect “/usr/sbin/chat -v -f /etc/chatscripts/gprs -T apn-name-of-your-provider
/dev/ttyUSB0
noipdefault
defaultroute
replacedefaultroute
hide-password
noauth
persist
usepeerdns

NOTE: In most cases the default apn name of your provider is ,,internet“. Otherwise you have to verify the setting by using the SIM card on your mobile phone first and go to data settings.

c. Enable the gprs interface

sudo ifup gprs

The pppd will initialize the modem and start the ppp connection, if everything is fine you will see a ppp0 interface with IP address assigned and corresponding entries in the routing table:

sudo ifconfig ppp0

ppp0      Link encap:Point-to-Point Protocol
             inet addr:XX.XXX.X.XX  P-t-P:YY.YY.YY.YY  Mask:255.255.255.255
             UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
             RX packets:499 errors:0 dropped:0 overruns:0 frame:0
             TX packets:591 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3
             RX bytes:66122 (64.5 KiB)  TX bytes:99537 (97.2 KiB)

sudo route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
YY.YY.YY.YY     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0

STEP 4: Verify Internet Connectivity

ping google.com

PING google.com (74.125.136.139) 56(84) bytes of data.
64 bytes from ea-in-f139.1e100.net (74.125.136.139): icmp_seq=1 ttl=51 time=4.87 ms
64 bytes from ea-in-f139.1e100.net (74.125.136.139): icmp_seq=2 ttl=51 time=5.01 ms
64 bytes from ea-in-f139.1e100.net (74.125.136.139): icmp_seq=3 ttl=51 time=5.16 ms

From now on the Raspberry Pi will automatically connect on start up and also retry to connect in case the connection is lost or interrupted.

Author’s Note: If you need a Global SIM best suited for such usage. I have been using SIM Cards from a company called Emnify (Goolge It!). They sell simcards over Amazon and has an easy to activate guide.

FacebookTwitterGoogle+Share

Leave a Comment

Your email address will not be published. Required fields are marked *