4G
1. 4G Module Usage OverviewA 4G module must be used with a SIM card (either a 【regular SIM card】 or an 【IoT SIM card】), so dial-up internet access via AT commands is required. In the Linux system, it is used as a network card device, so network configuration management for it is also necessary.
Since AT commands are only used during network card initialization, this document will focus on the network configuration related to the 4G module.
1.1 netplan and YAML Files1.1.1 BackgroundThe runtime environment of this analysis system is Ubuntu 22.04. Since Ubuntu 18.04, the system no longer uses ifupdown for network configuration and has switched to netplan instead. Therefore, configuring a static IP in /etc/network/interfaces is ineffective; network configurations must be implemented using YAML files in the /etc/netplan/ directory. This means we need to understand the basic syntax of YAML files.
The following syntax does not cover all YAML syntax, but only the parts required for network configuration. For more detailed syntax, please refer to the official YAML website: https://yaml.org/
- Data structures use key-value pairs in the format
Key Name: Value(note: there must be a space after the colon). - Arrays have two expression methods: for example, when configuring dual IP addresses, each element is on a separate line starting with
-; when configuring DNS, square brackets[]are used, with elements separated by commas. As shown in the figure below.
- Indentation is used to indicate hierarchical relationships. Spaces (instead of tabs) are recommended for indentation, as tab lengths may vary across different systems.
- All letters are case-sensitive.
AT Commands: A 4G module requires AT commands to set its working status and certain parameters. AT commands are essentially serial port communications, all starting with "AT" and ending with a carriage return (\r). After the module is running, the default serial port settings are: 8 data bits, 1 stop bit, no parity bit, and hardware flow control (CTS/RTS). Note that to send an AT command, a newline character (\n) must be added at the end (a requirement of the serial terminal). In the Linux system, data is sent and received through /dev/ttyUSB* device nodes. For AT command transmission, except for the two characters "AT", a maximum of 1056 characters (including the final null character) can be received. Their classification and command format are shown in the figure below.
- Regular SIM card: The mobile phone card we use daily, which has no binding relationship with the 4G module.
- IoT SIM card: Must be bound to a 4G module. One IoT SIM card can only be bound to one 4G module, while a single 4G module can be bound to multiple IoT SIM cards simultaneously.
Use the following command to view the storage path of the development board's network configurations; you will find 4 configuration files. Among them, 61-mobile0-init.yaml is the netplan configuration for the 【4G network card】.
ls /etc/netplan/If it does not exist, you need to create it manually. Below is an example of configuring mobile0 to use DHCP:
network:
version: 2
renderer: networkd
ethernets:
mobile0:
optional: true
dhcp4: true
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
dhcp4-overrides:
route-metric: 250If modifications are made to the YAML file, execute the following commands to update the configuration:
sudo netplan generate
sudo netplan apply2.2 Verify 4G Network Card RecognitionExecute the lsusb command. If recognized correctly, Quectel Wireless will appear as shown in the figure below.
Then execute the ifconfig command. If recognized correctly, mobile0 will appear as shown in the figure below:
ifconfigThe control interaction between the system and the 4G module is usually implemented through a USB serial port, specifically by transmitting AT commands via the USB serial port. First, check the available USB serial port resources:
Consult the module manufacturer to obtain the USB Driver Development Guide, and find the USB serial port of the corresponding module used as a 【Modem】—dial-up operations are performed through this serial port. As shown in the figure below.
The dial-up command is one of the AT commands: AT+QNETDEVCTL=3,1,1. For the EC200N-CN (CAT1) module, the dial-up command is transmitted via /dev/ttyUSB2.
The command executed on the development board is as follows:
echo -ne "AT+QNETDEVCTL=3,1,1\n" > /dev/ttyUSB2- Auto dial-up:
"AT+QNETDEVCTL=3,1,1\n" - Manual dial-up (requires re-dialing after restart):
"AT+QNETDEVCTL=1,1,1\n"
If logged in as a non-root user, send the AT command to /dev/ttyUSB2 using the following command:
echo -ne "AT+QNETDEVCTL=3,1,1\n" | sudo tee /dev/ttyUSB23. Network Connectivity TestExecute the ifconfig command to check if the 4G network card has been assigned an IP address correctly:
ifconfigIf an IP address is assigned correctly, execute the following command to check external network access:
ping 8.8.8.8 -I mobile0If data is returned from the server, the access is successful.
Note: If external network access fails, check the following:
- Whether the antenna is properly connected.
- Whether the 4G signal at the device location is strong.
- Whether a SIM card is inserted.
- If it is an IoT SIM card: whether the card has expired, or if it was previously bound to another device.
- Whether there is sufficient data traffic and balance in the card.


Comments