- 5 Modem At Command Examples in Linux (How to Configure Minicom)
- Task which can be done by using AT commands
- Installing minicom
- Configuring minicom to interface with the modem
- 1. Answer an Incoming call – ATA
- 2. Dialing out and hanging up a voice call – ATD – ATH
- 3. Getting the Manufacture/IMEI/IMSI information
- 4. Getting Signal quality and battery charge status
- 5. Sending SMS using AT commands
- Minicom — подключение к USB модему Huawei E1550 по /dev/ttyUSB*
- Установка minicom
- Подключение к модему
- minicom
- picocom
- Конфигурация
- Выполнение AT команд и USSD запросов
- Using Your 4G LTE Modem From The Terminal
5 Modem At Command Examples in Linux (How to Configure Minicom)
Basic commands are AT commands that do not start with “+”. Extended commands are AT commands that start with a “+”. All GSM/GPRS uses the extended commands for SMS/DATA services.
Task which can be done by using AT commands
Here are few list of tasks which can be done by using the AT commands.
- Get basic information about the subscriber
- Get the information about signal strength and battery strength
- Establish a data/voice connection
- Send and receive fax
- Send and receive SMS
- Read/Search phonebook entries
Note that not all modems will support all the AT commands.
In this tutorial, I’m going to show examples using my “Nokia 2700” mobile phone which has a inbuilt GSM/GPRS modem.
Installing minicom
In-order to send AT commands to modems, we need an interface. Minicom is a tool which provides an interface for communicating with devices that are connected to serial ports. Minicom is a linux equivalent to the HyperTerminal utility in Microsoft Operating Systems.
Using minicom we can send AT commands to the modem to get information about its features.
Configuring minicom to interface with the modem
Before configuring minicom, we need to connect the modem to the linux system. In my case, I’ve connected my “Nokia 2700” via data cable to my linux PC. Once the device is connected, you will see output similar to the following using dmesg. In my case the modem got detected as /dev/ttyACM0.
[ 1071.120084] cdc_acm 1-1.3:1.1: ttyACM0: USB ACM device [ 1071.120916] usbcore: registered new interface driver cdc_acm [ 1071.120917] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
To configure minicom to access modem, do the following:
# minicom -s +-----[configuration]------+ | Filenames and paths | | File transfer protocols | | Serial port setup | | Modem and dialing | | Screen and keyboard | | Save setup as dfl | | Save setup as.. | | Exit | | Exit from Minicom | +--------------------------+
Choose the “Serial port setup” and press “Enter”. It will display a screen similar to the following.
+-----------------------------------------------------------------------+ | A - Serial Device : /dev/tty0 | | B - Lockfile Location : /var/lock | | C - Callin Program : | | D - Callout Program : | | E - Bps/Par/Bits : 115200 8N1 | | F - Hardware Flow Control : No | | G - Software Flow Control : No | | | | Change which setting? | +-----------------------------------------------------------------------+
Press ‘A’ to change the serial device from /dev/tty0 to /dev/ttyACM0.
Press ‘E’ to change the Baud rate at which the modem communicates. In my case, it is “460800”. You can also used wvdialconf to identify the baud rate supported by your modem.
Once you change these settings, press “Enter”.
Choose “Save setup as dfl” and choose “Exit”.
Now we have configured the minicom successfully and you will see a screen like the following.
Welcome to minicom 2.6.1 OPTIONS: I18n Compiled on Feb 11 2012, 18:12:55. Port /dev/ttyACM0 Press CTRL-A Z for help on special keys
To test whether we have configured minicom successfully to communicate with modem, type “AT” in the minicom. You should get a “OK” response as follows.
Welcome to minicom 2.6.1 OPTIONS: I18n Compiled on Feb 11 2012, 18:12:55. Port /dev/ttyACM0 Press CTRL-A Z for help on special keys AT OK
1. Answer an Incoming call – ATA
To answer an Incoming call via modem, issue the “ATA” command in the minicom.
When there is an incoming call, you can see a ‘RING’ message in the minicom. You can press “ATA” to answer the incoming call.
2. Dialing out and hanging up a voice call – ATD – ATH
You can also dial out a voice call from the modem using ATD command.
Now the phone will dial out to the number 99769XXXXX.
To hangup the call, use ATH command.
3. Getting the Manufacture/IMEI/IMSI information
Extended AT commands are used to provide information about the manufacturer, International Mobile Equipment Identity, International Mobile Subscriber Identity etc…
AT+CGMI Nokia OK AT+CGSN xxxxxxxxxxxxxxx OK AT+CIMI xxxxxxxxxxxxxxx OK
4. Getting Signal quality and battery charge status
You can also get the signal quality and the battery charge status using AT extended commands.
AT+CSQ +CSQ: 29,99 OK AT+CBC +CBC: 1,96 OK
The output format +CBC: 1,96 represents ,
5. Sending SMS using AT commands
You can also send SMS via AT commands.
AT+CMGF=1 OK AT+CMGS="99xxxxxxxx" > This is a test message > OK
The command AT+CMGF=1 sets the “Message format” to “text mode”. The command AT+CMGS, send the SMS to the specified number. < ctrl +z >is used to terminate the message input.
Minicom — подключение к USB модему Huawei E1550 по /dev/ttyUSB*
Для коммуникации с USB 3G модемом есть несколько консольных и графических утилит:
- minicom — мне приглянулась больше остальных
- picocom
- cutecom (графическая программа для работы с терминалами).
Установка minicom
sudo apt install minicom -y
Примечание
Рекомендуют также устанавливать следующие пакеты:
sudo apt install libusb++-0.1-4v5 libusb++-dev
Подключение к модему
Примечание
Обычно USB модемы предоставляют 3 ttyUSB* интерфейса:
- /dev/ttyUSB0 — интернет/данные
- /dev/ttyUSB1
- /dev/ttyUSB2 — командный интерфейс/устройство
На модеме Huawei E1550 ответ на USSD запросы всегда приходит на интерфейс /dev/ttyUSB2! Даже отправляя USSD запросы в /dev/ttyUSB0 все равно слушайте 2 порт.
minicom
sudo minicom -D /dev/ttyUSB2 -b 9600
Подключение в режиме настройки:
sudo minicom -D /dev/ttyUSB2 -s
- Переходим в «Настройка последовательного порта«, далее «А — Последовательный порт» и указываем /dev/ttyUSB0 или /dev/ttyUSB2.. Enter.
- Выбираем «Сохранить настройки как dfl«.
- Выход.
И мы подключимся к модему с выбранными настройками.
Примечание
Для выхода из терминала minicom (отключения от устройства) используются комбинации клавиш Ctrl + A — X (без сохранения) или Ctrl + A — Q (с сохранением).
Выполнение набора команд и вывод в файл:
sudo minicom -D /dev/ttyUSB2 --capturefile=/path/minicom.log --script=/path/minicom-script.txt
Содержимое файла minicom-script.txt (не знаю как завершить процесс после выполнения AT команды):
picocom
Подключаемся к устройству /dev/ttyUSB2:
Подключаемся к устройству /dev/ttyUSB2 с отображением команд в терминал:
sudo picocom --echo -b 38400 /dev/ttyUSB2
Конфигурация
Использование /dev/tty* без sudo
Для использования /dev/tty* устройств без прав супер-юзера (sudo) необходимо добавить пользователя в группу dialout:
sudo apt remove modemmanager sudo usermod -a -G dialout $USER
Внимание!
Если не отображается результат выполняемых AT команд и USSD запросов — проверьте, не перенаправляется ли вывод на другое ttyUSB* устройство или в файл. Попробуйте сменить устройство с ttyUSB0 на ttyUSB2.
Выполнение AT команд и USSD запросов
Показать информацию о модеме:
Manufacturer: huawei Model: E1550 Revision: 11.608.13.02.00 IMEI: 353443043787139 +GCAP: +CGSM,+FCLASS,+DS
AT команды для получения оператора связи (carrier):
Выполнение USSD запроса для просмотра баланса:
#tty, #terminal, #minicom, #modem, #at, #ussd, #serial
Using Your 4G LTE Modem From The Terminal
* These directions have been tested on Rocky Linux 8.4, Fedora 32, Raspbian Buster (10) / Raspberry Pi OS and Trisquel 8 (EM7455 & LT4120), but should work on most Debian, Ubuntu, Trisquel, Fedora, Red Hat Enterprise Linux, and CentOS based distributions as well. They are probably also applicable to hundreds if not thousands of distributions as well, although some may require a few tweaks to these directions.
Note: These directions assume that your modem is in mbim mode. Switching between mbim and qmi modes while possible is not recommended.
Having trouble? Check out the video demonstration of these directions.
Install libmbim from your distribution’s official repositories (this may not be needed on some distributions, like Fedora). To bring up the modem you can use mbim-network which is a wrapper for mmcli calls. First create a profile for mbim-network.
0. Make sure universe is enabled if on Ubuntu or otherwise apt-get command below will fail to find the package that needs to be installed
1. On Debian/Ubuntu/Raspbian/Raspberry Pi OS/Trisquel based distributions open a terminal and become admin: sudo su
* Some distributions you may need to run «su -» or similar to become an admin
2. On Debian/Ubuntu/Raspbian/Raspberry Pi OS/Trisquel based distributions run the following commands (you will need a temporary internet connection to install the modem software, which may also be done by copying the packages from another machine, or contact support about obtaining this software/packages on CD/flash drive):
apt-get install libmbim-utils
3. Run (replace Broadband in the command below with your cellular providers APN, see provider specific documentation for APN info) the following commands:
echo APN=Broadband > /etc/mbim-network.conf
echo PROXY=yes >> /etc/mbim-network.conf
4. Insert your SIM card, connect the antennas, and plug your modem in and run the below command to find out your modem’s device name (you may have to wait a minute for the modem’s blue light to come on and the system to initialize the modem, otherwise you’ll have to try running the command below again):
Or the following should also show a cdc-wdmX modem as well, if you say have an internal card in your laptop from us:
5. Take note of the cdc-wdmX device and replace X below with what is shown. Then run:
mbim-network /dev/cdc-wdmX start
Note 1: If you see «error: operation failed: Transaction timed out» just be patient as it’ll automatically attempt to reconnect.
Note 2: If you don’t see a blue light on the modem the radio is probably off. To turn it on run the command below and replace X with your /dev/cdc-wdmX device and then run the mbim-network command above again:
mbimcli —device=/dev/cdc-wdmX —device-open-proxy —set-radio-state=on
6.Once you get «Network started successfully» or «Successfully connected» the next step is to find out what your modems network interface shows up as by running:
Either ip a will show something like wwanX or if it’s something else run:
In the output you should be able to spot a line like below where wwp0s24e1u4i13 is you modems network interface:
[ 13.043613] cdc_mbim 1-1:3.12 wwp0s24e1u4i13: renamed from wwan0
7. We need to grab ip information from the mobile broadband provider. That isn’t a typical DHCP request though so make sure to follow the instructions below. Replace /dev/cdc-wdm1 below with your modem’s device as discovered in step 4.
Note: Before running the below command make sure your wifi is disconnected and off or you may get «error: couldn’t get IP configuration response message: ContextNotActivated»
mbimcli -d /dev/cdc-wdm1 -p —query-ip-configuration
8. Run the commands below after replacing wwan0 with the network interface of your modem as discovered in step 6.
ip addr flush dev wwan0
ip -6 addr flush dev wwan0
ip link set wwan0 up
9. Replace 10.51.14.130/28 with the IP line output from the query-ip-configuration IP line in step 7 and your wwan network interface found in step 6 and run the command:
ip addr add 10.51.14.130/28 dev wwan0 broadcast +
10. Replace 10.51.14.131 with the gateway address found in step 7 and your wwan network interface found in step 6 and run the command:
ip route add default via 10.51.14.131 dev wwan0
11. Run the command below, but replace wwan0 with your wwan network interface found in step 6 and mtu found in step 7:
ip link set mtu 1430 dev wwan0
12. One last thing. test the connection!
If you see 0% packet loss then you have an internet connection! Great! It works.
Also try seeing if you can resolve domains:
If you see a line with and Address: and an ip on it then you’ve successfully setup your connection, but if not you probably need to set a nameserver by running the following command:
echo nameserver 8.8.8.8 > /etc/resolv.conf
Note: There are different ways to set a nameserver depending on which distribution and release you are on, but the above typically works. The above may not be preserved however. Some distributions use /etc/network/interfaces, some use netplan, and some utilize the traditional /etc/resolv.conf and it can depending on whether or not you have a server or desktop version of your distribution at that. For more information on setting a DNS we will refer you to an outside article written on the subject: how to set DNS nameservers on Ubuntu 18.04.
If you have any problems we recommend looking at our troubleshooting documentation and/or contacting our support team for assistance.