Connect a Raspberry Pi to a Huawei 3G Modem to allow Internet access
Motivation
As part of the project to create a stand-alone Twitter Appliance, I needed to connect a Raspberry Pi to a 3G network.
System Design
The design is simple: An existing 3G modem is connected to the Raspberry via a USB connection. I already own a Huawei E5756s mobile broadband modem connected to Three UK, and as this also has a USB connection, it was the obvious one to use for this.
Installing the modem
Installing the modem required that the Raspberry Pi recognise the modem as such. Unfortunately, out of the box, the E5756 is detected as a hard disk by Raspbian. This is because the modem has a hidden disk partition that contains the Windows driver.
- Plug the modem into one of the USB ports.
- In a terminal session, run the command
# lsusb
With a bit of luck, you’ll see something like:
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 005: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
The key line is the last, showing that Raspbian has recognised the modem. Unfortunately, you may well see:
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 12d1:14fe Huawei Technologies Co., Ltd.
This indicates that Raspbian sees the Huawei device as a disk drive. To get around this, we need to installthe usb-modeswitch package, but we need to do things in a specific order for this to work (or at least I did anyway).
Open a terminal prompt and, with the modem unplugged:
- install the usb-modeswitch package
# sudo apt-get install usb-modeswitch
-
After this completes, reboot the Pi and then log in again and open a terminal session.
-
Plug the modem in, leave it for a second or two for it to be recognised and then do
# lsusb
-
Hopefully, the output will now indicate the the modem has been recognised. Display the network interface list:
# ifconfig -a
Hopefully, you will see:
eth0 Link encap:Ethernet HWaddr b8:27:eb:04:64:df
inet addr:172.29.12.204 Bcast:172.29.12.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1191 errors:0 dropped:0 overruns:0 frame:0
TX packets:633 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:383489 (374.5 KiB) TX bytes:100065 (97.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wwan0 Link encap:Ethernet HWaddr 0c:5b:8f:27:9a:64
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5237 (5.1 KiB) TX bytes:0 (0.0 B)
Good news, we have a new interface. To get this to acquire an IP address, we need to edit the file /etc/network/interfaces
and add the lines:
allow-hotplug wwan0
iface wwan0 inet dhcp
If you now reboot, you should see that the new interface has been initialised and configured:
eth0 Link encap:Ethernet HWaddr b8:27:eb:04:64:df
inet addr:172.29.12.204 Bcast:172.29.12.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1191 errors:0 dropped:0 overruns:0 frame:0
TX packets:633 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:383489 (374.5 KiB) TX bytes:100065 (97.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wwan0 Link encap:Ethernet HWaddr 0c:5b:8f:27:9a:64
inet addr:192.168.1.101 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5237 (5.1 KiB) TX bytes:0 (0.0 B)
Hoorah, the modem is connected and working.
After this bit of jiggery-pockery, the modem should continue to be recognised if it is connected at boot time.