Connect 3G Dongle in Raspberry Pi4

Overview
In this post, we will see how to connect a 3G Dongle in Raspberry Pi4 which has Ubuntu 20.4 LTS OS installed
Objectives
- What is Raspberry Pi
- What is Sakis3G
- What is SSH
- Connect Raspberry Pi in headless mode
- Install usb-modeswitch and PPP
- Copy Sakis3G and make it single executable
- Connect the 3G Dongle using Sakis3G
Prerequisites
- Raspberry Pi4 — (Ubuntu 20.4 LTS OS installed)
- 3G Dongle (The Dongle which i am having is Huawei 3533 Modem)
- Network connection
1. What is Raspberry Pi
The Raspberry Pi is a low cost, credit-card sized computer which enables people of all ages to explore computing, and to learn how to program in languages like Python.
Raspberry Pi is capable of doing everything you’d expect a desktop computer to do like browsing internet and playing high-definition video and games.
2. What is Sakis3G
Sakis3G is a tweaked shell script which is used for establishing a 3G connection with any combination of modem or operator.
3. What is SSH
Secure Shell (SSH) is a method for communicating with another computer securely. ‘Secure’ means the data sent via SSH connection is encrypted.
Example of SSH mechanism is User A sends a brief case to User B. User A locks the brief case and sends it to User B. User B receives the brief case but it cannot be opened since it doesn’t have the key. so User B puts another lock and sends it back to User A and then User A unlocks with the key and sends it back to the User B.Now User B can unlock the briefcase with the key.
This means if a third party tries to intercept the information being transferred it would appear scrambled and unreadable.
4. Connect to Raspberry Pi in headless mode
Now we will connect the Raspberry Pi in headless mode (Using SSH).Make sure your system and Raspberry Pi connects to the same network.
Now open the terminal in your system and type ifconfig
for ubuntu and get the inet address from Ethernet like below

Once you copy the inet address type the command sudo nmap 192.168.43.246/24 -sn
to see the list of devices connected to the network and copy the IP address of the RaspberryPi.
Once copied connect to the RaspberryPi using the SSH commnd
ssh ubuntu@192.168.43.125
where ubuntu is the name of the RaspberryPi device.Once connected you could see a screen like below

Now we have connected to RaspberryPi in headless mode.
5. Install the usb-modeswitch and PPP
Now we will install the usb-modeswitch and PPP in Raspberry Pi using the below command
sudo apt-get install usb-modeswitch
sudo apt-get install ppp

Now we have installed the usb-modeswitch and PPP in RaspberryPi.
6. Copy Sakis3G and make it single executable
Now we will copy the Sakis3G file from local machine to RaspberryPi using Secure copy (SCP).Create a new directory named dongle
in RaspberryPi
Use the below command to copy the Sakis3G to RaspberryPi.Makesure you have opened a new terminal in your local machine which has the sakis3G file else provide the path of where the sakis3g file is located
scp sakis3g.tar.gz ubuntu@192.168.43.125:~/dongle/

Once the file is copied to the dongle folder you can check it using the ls
command where you can see the sakis3g file like below

Now we will unpack the Sakis3G file and make it executable file using the below command in RaspberryPi.(Make sure you have navigated to the dongle directory in RaspberryPi)
sudo tar -xzvf sakis3g.tar.gz //unzip the file
sudo chmod +x sakis3g //making it executable
Once done we are ready to connect but before that check whether the dongle connected is in Modem mode or in Mass storage mode using the command lsusb

If you see in the above pic the dongle is in Mass storage mode which needs to be changed as Modem mode.
To make it in modem mode use the below command(Below command works for Huawei Modem)
sudo usb_modeswitch -v 12d1 -p 14fe -M '55534243123456780000000000000011062000000100000000000000000000'
Now if you run the command lsusb
you could see the dongle changed to Modem mode like below

7. Connect the 3G Dongle using Sakis3G
Now we will connect the 3G dongle using the below command
./sakis3g --interactive
which will open the sakis3g interactive tool like below

Select HUAWEI Mobile which will move to the next screen lik below

Select the Interface #0 and enter which will move to the APN screen like below

Select the APN and click enter

Now it will ask for the username and password.For BSNL there is no username and password.Instead we can pass empty space and click ok which will try to connect

Now we have connected in 3G Dongle successfully.To see which is the default connection we can check it in routetable
like below

The default connection in the route table is dongle (Iface is ppp0).If you want to connect the dongle automatically we can use the UMTS keepeer which we will cover in the next part.
Reference Links
https://askubuntu.com/questions/1145645/huawei-e3131-modem-shows-as-mass-storage
Congratulations!
You have learned how to connect a 3G dongle in RaspberryPi4
Happy Learning :)