Tuesday, July 4, 2017

How to setup a USB 3G Modem on Raspberry PI using usb_modeswitch and wvdial

  • Raspberry PI computer
  • Raspbian OS installed
  • USB 3G Modem
  • 5V 1A power supply for the Raspberry PI 

1. Install required software

  • Connect your Raspberry PI to the internet via LAN or Wifi
  • Open a terminal window and enter:
sudo apt-get update
sudo apt-get install ppp usb-modeswitch wvdial

2. Get the USB switching codes

  • We need to get the codes of the USB device in USB storage mode and USB modem mode. 
  • Connect your USB modem and reboot the Raspberry PI without LAN or Wifi connection
  • Once rebooted open a terminal window and enter:
  • The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices. Note the numbers underlined. These are the device vendor and product codes.
  • Make a note of these numbers. In this case it is 19d2:2000
  • This value will later be used in the DefaultProduct value 
  • Then we need to soft reboot the Rapberry PI with the modem connected.
  • Open a terminal window and enter:
sudo reboot
  • Once rebooted open a terminal window and enter:
  • The output will look similar to the screenshot below. Your modem should be listed and if you are lucky the second set of numbers would have changed. This is usb_modeswitch doing it's job and switching the device to USB modem mode.
  • Make a note of the new numbers. In this case it is 19d2:2002
  • This value will be used later in the TargetProduct value 

3. Create custom usb_modeswitch config file

  • We need to create a custom config file for usb_modeswitch on the Raspberry PI because on a cold boot the device is not always active yet when usb_modeswitch runs on startup and the device is left in USB storage mode.
  • We will extract some more information for our usb_modeswitch config file so that we can do the switching manually.
  • Open a terminal window and enter the following replacing the codes 19d2 and 2000 with the codes you noted in step 2. Also note the added backslash.
cd /tmp
tar -xzvf /usr/share/usb_modeswitch/configPack.tar.gz 19d2\:2000
  • Now open the extracted file with a text editor like leafpad replacing the codes noted in step 2.
leafpad 19d2:2000
  • The content of the file should look something similar to the screenshot below.
  • The parts we are interested in are shown in blue.
  • Now open the /etc/usb_modeswitch.conf file and add the information obtained above to the file.
  • Open a terminal window and enter:
sudo leafpad /etc/usb_modeswitch.conf
  • Then add the following replacing the codes and MessageContent values with those of your device and save.



4. Create the wvdial config file

  • The next step is to create a config file for wvdial so you can connect to your service provider.
  • Open a terminal window and enter:
sudo leafpad /etc/wvdial.conf
  • Replace the content of the file with the following. 
[Dialer 3gconnect]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","internet"
Stupid Mode = 1
Modem Type = Analog Modem
ISDN = 0
Phone = *99#
Modem = /dev/gsmmodem
Username = { }
Password = { }
Baud = 460800
  • Replace internet with your service provider's APN
  • Replace the Phone number if you need to dial a different code to connect.
  • Replace Username and Password if needed. To leave the username and password as blank use { }

5. Connect to the internet

  • To connect we need to make sure the device is in modem mode. 
  • Open a terminal and enter:
sudo usb_modeswitch -c /etc/usb_modeswitch.conf
  • Then connect to the internet with:
wvdial 3gconnect

No comments:

My 20m band Dxing Report : 18 Jan 2019

Callsign : 9M2ZAK Country : West Malaysia Locator : OJ11TP Sunrise : UTC 23:14 Sunset : UTC 11:17 ---------------------------...