Connect IRIV PiControl to The Internet Through 4G with EC25

Connect IRIV PiControl to The Internet Through 4G with EC25

In today's world, the use of IoT devices often relies on a continuous internet connection. This connection is essential for transmitting various data between users and their devices, enabling remote monitoring and control. However, in reality, not all installation areas have a constant and reliable internet connection. Therefore, wireless internet through networks such as 4G or 5G plays a crucial role in ensuring the functionality of IoT devices.

 

 

And the ability to communicate wirelessly via 4G or 5G signals is another feature that IRIV PiControl excels at.

In this tutorial, we will learn how to enable our IRIV PiControl to connect to the internet through 4G signals using the EC25 4G internet module. Additionally, we'll explore how to use PiTunnel, allowing us to remotely SSH into the IRIV PiControl board even when using 4G internet. Let's dive into the steps together.

 


*For the script's operational principles, you can find more information at the end of the tutorial.

Before we proceed with the installation of scripts and tools for using the internet via 4G with the EC25 module, we'll first create a tunnel for remote SSH access to the IRIV PiControl board. This tunnel will enable us to remotely access SSH, even when we are not within the same network as the board. For example, we can remotely SSH into the board while it's connected to the internet via 4G.

 

To create a tunnel for remote SSH access via 4G using PiTunnel, follow these steps:

 

1. Go to the website https://pitunnel.com and click on "Get Started."

 

 

2. Fill in the required information to register for an account with PiTunnel. Click "I agree to the Terms of Service..." and then click "Join."
 

 

3. After successfully creating a user account, you will be directed to the page for connecting IRIV PiControl to PiTunnel. Simply click "Next."
 

 

4. When you encounter this page, copy the command in the line, as shown in the image. Paste it into the terminal of your IRIV PiControl, then press Enter.

 

 

 

Once PiTunnel is successfully installed, a message similar to the one in the image will appear, indicating that you can now remotely SSH through PiTunnel.

 

 

If you return to the PiTunnel website after completing the installation on IRIV PiControl, you will find that the connection is successful. Click the "Done" button.

 

 

5. After that, you will be directed to the Dashboard page showing the devices connected to PiTunnel. Here, you will find your IRIV PiControl board listed as "Online." You can immediately access the terminal of your IRIV PiControl by clicking on "Open Remote Terminal.

 


Or explore various functions, including displaying running processes on the board, viewing screenshots of the current board status, or initiating a restart of the board.

 

 

Start using the Quectel EC25 module for connecting to the internet via 4G signals:

 

For the convenience of users to quickly start using the EC25 module with the IRIV PiControl board, we have prepared a script for the installation. Users can open the terminal of the IRIV PiControl and run the following command to execute the prepared script:

 

Note: Before running the script below, the IRIV PiControl board must be connected to the internet (either through LAN or WiFi) to download the necessary scripts and files from the internet.

 

curl -L https://bit.ly/3szbUs6 | sudo bash

 

Before we proceed with configuring the script to initiate internet usage through the EC25 module, let's install a SIM card into the IRIV PiControl board. The SIM card slot is located on the bottom side near the USB Type-C port, on the same side as the HDMI port. Make sure to use a micro SIM card.

 

 

After successfully installing the SIM card into the board, we will configure the script to activate the miniPCIe slot and initiate the internet connection through the EC25 module installed on the board every time it boots. We will achieve this by creating a cronjob. Open the terminal of the IRIV PiControl and use the following command:

 

crontab -e

 

After that, you will be presented with options to choose a text editor for editing the crontab file. Select nano by typing the number 1 and pressing Enter.

 

Once inside the nano text editor, scroll down to the bottom, and paste the following command.

 

@reboot sudo /usr/local/bin/ec25_cellular_module/connect_internet_ec25.sh


 

Afterward, reboot the board using the command:

 

sudo reboot now

 

After the IRIV PiControl board boots up again, check the current internet connection interface by going to the terminal and using the command:

 

ifconfig


If the Quectel EC25 module is operational, you will find interfaces named "wwan0" and "ppp0."

 

 

This means that now our IRIV PiControl board can use the internet through the 4G signal with the Quectel EC25 module we've installed. We can disconnect the LAN cable connected to the IRIV PiControl board, leaving the board with internet connectivity solely through the 4G signal.

 

After that, go back to the PiTunnel website dashboard and test by clicking "Open Remote Terminal" to access the IRIV PiControl board that we have linked to PiTunnel. If the IRIV PiControl board can use the internet via the 4G signal, we will be able to remote into the board as usual.

 


Operating principle of the script:

 

1. The script responsible for downloading necessary files for using the Quectel EC25 module with the IRIV PiControl board includes git and linux-ppp-scripts. This script is executed using the command:

 

curl -L https://bit.ly/3szbUs6 | sudo bash

 

The script in this section has details as follows:

 


#!/bin/bash

# Make sure the script is run as root.
if [ $(id -u) -ne 0 ]; then
  echo
  echo
  echo "Please run as root."
  exit 1
fi
#Check if the system has Git installed and ready to use.
if ! command -v git &> /dev/null; then
  echo "Git is not installed. Installing Git..."
  sudo apt update
  sudo apt install git -y

  # Check installation success
  if ! command -v git &> /dev/null; then
    echo "Git installation failed. Please check your internet connection or install Git manually."
    exit 1
  else
    echo "Git has been installed successfully!"
  fi
else
  echo "Git is already installed."
fi

cd /
# create folder for scripts.
cd /usr/local/bin
sudo mkdir ec25_cellular_module
cd ec25_cellular_module

#Download script for EC25 dialing process
git clone https://github.com/turmary/linux-ppp-scripts.git
echo
echo "Prepare linux-ppp-scripts files complete!"

#Download script for enable miniPCIe slot and start dialing process
wget https://raw.githubusercontent.com/CytronTH/IRIV_cellular/main/connect_internet_ec25.sh
sudo chmod +x connect_internet_ec25.sh
echo
echo "Enable mPCIe and prepare dialing scripts files complete!"


2. The script in this section is responsible for enabling the miniPCIe slot on the IRIV PiControl board every time the board boots up. It then performs dialing to establish an internet connection through the 4G signal using the Quectel EC25 module.

 


#!/bin/bash
# Run the commands with root privileges using sudo

# Function to check if interface is available
sudo -i < cd /sys/class/gpio || exit

#Start enable power for miniPCIe slot#
# Export GPIO pins 6 and 5
echo 6 > export
echo 5 > export

# Configure GPIO pin 6
cd gpio6 || exit
echo out > direction
echo 1 > value

# Configure GPIO pin 5
cd ..
cd gpio5 || exit
echo out > direction
echo 1 > value

#Enable power for miniPCIe slot end#

#Check WWAN0 interface to be ready before start dialing process#
interface="wwan0"

#Checking WWAN0 interface function#
check_interface() {
  if [[ "$(ip link show $interface 2>/dev/null)" ]]; then
    return 0 # Interface is available
  else
    return 1 # Interface is not available
  fi
}

#Call checking WWAN0 interface function#
while :
do
  if check_interface; then
    echo "Interface $interface is available. Continuing with the script." #If wwan0 interface is ready. Go to next step
    break
  else
    echo "Interface $interface is not available. Waiting..." #If wwan0 interface is not ready. Waiting for ... seconds before try again
    sleep 5 # Adjust the interval between checks (in seconds)
  fi
done

#Waiting for 20 seconds for ec25 cellular module initialization#
echo
echo
echo Waiting for 20 seconds before start dialing
sleep 20

#Go to dialing script location#
cd /
cd /usr/local/bin/ec25_cellular_module/linux-ppp-scripts

#Start dialing#
echo
echo
echo "Start dialing..."
echo
echo
# Run the script in the background to capture its output  
sudo ./quectel-pppd.sh > output.log &

# Monitor the output for a specific message using grep
while :
do
  if grep -q "IPV6CP: timeout sending Config-Requests" output.log; then
    echo
    echo "Dialing completed. Process next step"
    echo
    pkill -INT -f "quectel-pppd.sh"
    sleep 2 #Wait for 2 seconds before running the next command
    #Add new default gateway route for internet connection from ec25 4g module
    sudo route add default gw 10.64.64.64
    echo
    echo "Cellular connection is now ready to use"
    break # Exit the loop
  fi
  sleep 1 # Check debug message from dialing script every second
done

exit
EOF

 

 

Hardware Components


Related Posts

Create Datalogger for Sending Data to Google Sheets with IRIV

Create Datalogger for Sending Data to Google Sheets with IRIV

In today's industrial sector, there is a growing need for devices capable of recording various system data, whether it's the operation of machinery or environmental conditions such as temperature and..