At команды через консоль linux

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.

Читайте также:  Посмотреть какие порты слушаются linux

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.

Источник

Выполнение AT/USSD команд к /dev/ttyUSB* модему из консоли Linux

Утилиты и скрипты для коммуникации с /dev/ttyUSB* устройством из shell консоли (bash скриптов).

Теория

Отправить в /dev/ttyUSB* терминал AT команду не составляет проблем. Но результат вывода мы не увидим!

echo ATI > /dev/ttyUSB2 # или echo ATI | sudo tee /dev/ttyUSB2

Мы можем читать поток stdout c /dev/ttyUSB2 (результат выполнения команд):

  1. Нужно получить только результат выполнения конкретной AT команды, а не весь поток вывода.
  2. Нужно использовать gsm7bit кодировку для кодирования параметров и получения ответа при выполнении USSD запросов:
echo AT+CUSD=1,AA182C3602,15 | sudo tee /dev/ttyUSB2

Выполнение AT/USSD команд

bash

Скрипт at.sh для отправки AT команды и получения ответа в переменную:

at.sh "AT+COPS=3,0\nAT+COPS?" /dev/ttyUSB2
#!/bin/bash AT="$1" TTY="$2" SLEEP=0 RESULT=$(cat $TTY & echo -e "$AT" > $TTY; sleep $SLEEP; kill %cat) echo $RESULT

Но вы получите ответ вида:

AT+COPS? +COPS: 0,0,"lifecell",2 OK ^BOOT:36507742,0,0,0,87 ^RSSI:3 ^RSSI:3 ^RSSI:3

minicom

Можно отправить AT команду и перенаправить весь вывод в файл:

sudo minicom -D /dev/ttyUSB2 -S ./at/carrier-name.txt -C output.txt

После этого нужно закрыть терминал и разобрать/декодировать весь вывод из файла output.txt. Не круто..

ussd.py

В сети нашел python скрипт для отправки USSD запросов (немного поправил):

122 SMS po Ukraine. 3G: 1024 MB Nomer do 01.05.18.
#!/usr/bin/python #coding: utf8 import base64, io, tty, sys import time ussd = sys.argv[1] modem = '/dev/ttyUSB5' if len(sys.argv) > 2: modem = sys.argv[2] else: modem = '/dev/ttyUSB2' def write2p(a): #sp.write(bytes(a + '\r\n', 'utf8')) sp.write(a + '\r\n') def gsm7bitencode(src): """ Encode ASCII text to 7-bit encoding """ result, count, last = [], 0, 0 for c in src: this = ord(c) > 8) | (this & 0xFF))) count = (count + 1) % 8 last = this result.append('%02x' % (last >> 8)) return ''.join(result) def gsm7bitdecode(f): f = ''.join(["".format(int(f[i:i+2], 16)) for i in range(0, len(f), 2)][::-1]) return ''.join([chr(int(f[::-1][i:i+7][::-1], 2)) for i in range(0, len(f), 7)]) ### sp = io.open(modem, 'w+b', 0) tty.setraw(sp) write2p('AT+CUSD=1,' + gsm7bitencode(ussd) + ',15') ### start = time.time() while (time.time() - start < 10): l = sp.readline() #print(l) if l.startswith('+CUSD'): ussd_response = l[10:l.rfind('"')] response_decoded = gsm7bitdecode(ussd_response) print(response_decoded) break # @note Реализация без таймаута # @todo Нужен таймаут для прерывания ридера потока, если ничего #for l in sp: ##print(l) #if l.startswith('+CUSD'): #ussd_response = l[10:l.rfind('"')] ##print(ussd_response) #response_decoded = gsm7bitdecode(ussd_response) #print(response_decoded) #break sp.close() 

Кодировка GSM 7bit в USSD запросах

Кодирование в gsm7bit

При отправке USSD запросов нужно кодировать USSD-код в кодировку GSM 7bit (как я понял из-за того, что модем не поддерживает текстовый режим).

Следующие запросы вернут ERROR:

AT+CUSD=1,"*111#","15" AT+CUSD=1,"*121#",15

Python функция gsm7bitencode для кодирования utf8 строки в gsm7bit:

def gsm7bitencode(src): """ Encode ASCII text to 7-bit encoding """ result, count, last = [], 0, 0 for c in src: this = ord(c) > 8) | (this & 0xFF))) count = (count + 1) % 8 last = this result.append('%02x' % (last >> 8)) return ''.join(result)
Примечание

Смотрите онлайн-сервис для работы с кодировками: http://smstools3.kekekasvi.com/topic.php?id=288

Пример USSD команд в кодировке 7bit gsm проверки баланса:

AT+CUSD=1,"AA582C3602",15 # *111# AT+CUSD=1,"AA182C3602",15 # *121#

Кодированные ответы (ответ всегда приходит на устройство /dev/ttyUSB2):

+CUSD: 0,"C2303BEC9E83662E98ED2C77B340E2B7BB3E07C15C30D859EE762914",15 +CUSD: 0,"C2303BEC9E83662E98ED2C77B340E2B7BB3E07C15C30D859EE7629542A9502442CD3C3ECB40EA48AC9622317E8299687E9697A196477A7DB6177BACC02B9DFEDB21C4466E7C320B8FC6D2FCBD7699038CC0EBBE761103B6D2E8FCB6C3648158BC5460A05",15

Декодирование из gsm7bit

Python функция gsm7bitdecode для декодирования gsm7bit в utf8:

def gsm7bitdecode(f): f = ''.join(["".format(int(f[i:i+2], 16)) for i in range(0, len(f), 2)][::-1]) return ''.join([chr(int(f[::-1][i:i+7][::-1], 2)) for i in range(0, len(f), 7)])

Источник

How to send AT commands to device

AT commands (“attention commands” formally, the Hayes command set), are used to communicate directly with a modem device and configure it.

From OpenWrt

To send AT commands directly from OpenWrt, you can simply use echo to send them to the right device. However, you will not get any errors, confirmation or any other answer from the modem.

A better solution is to use socat , which can both send commands and print the modem's answers.

socat

socat will open a prompt where you can enter AT commands (see examples in the section below).

For instance, to access a Quectel EP06 LTE modem, which creates 4 devices ( /dev/ttyUSB0 through to /dev/ttyUSB3 ):

(Here, socat sends a carriage return (cr) and a new line (nl) after each command, which seems to be needed for this modem.)

To find the device on which to run socat , try looking through dmesg . Something like the following may help:

dmesg | grep -A 1 -B 12 ttyUSB

Some modems also show up as a ttyACM device.

echo

Use echo -e so as to be able to escape characters such as “ .

From a computer

To send AT commands to a LTE modem, you need to first connect the device/modem to the computer, most likely using an adapter (built-in modem slots are very rare these days) and access it with a COM terminal.

If you are not familiar with using COM terminals, you might want to use a graphical tool like: CuteCom or minicom . Installation of these are beyond the scope of this page.

These settings should work fine:

Device: /dev/ttyUSB0 Connection: 115200 @ 8-N-1 Line end: CR

Examples of AT commands

To test things are working, you can issue ATI which should return basic information such as brand, model and firmware revision.

AT+CSQ can be used to get signal strength. The values returned are the RSSI (received signal strength indication,higher is better) and BER (bit error rate, lower is better)

Here is example for the Huawei E392 LTE/3G dongle:

Send: AT OK Send: AT^SETPORT=? Recieve: 1:MODEM Recieve: 2:PCUI Recieve: 3:DIAG Recieve: 4:PCSC Recieve: 5:GPS Recieve: 6:GPS CONTROL Recieve: 7:NDIS Recieve: A:BLUE TOOTH Recieve: B:FINGER PRINT Recieve: D:MMS Recieve: E:PC VOICE Recieve: A1:CDROM Recieve: A2:SD Recieve: OK Send: AT^SETPORT? Recieve: A1,A2;1,2,3,A1,A2 Recieve: OK Send: AT^SETPORT="A1;2,7,A2" Recieve: OK Send: AT^SETPORT? Recieve: A1;2,7,A2 Recieve: OK
AT^SETPORT=? - Lists the Available interfaces and their numbers AT^SETPORT? - Show current configuration AT^SETPORT="A1;2,7 - Sets configuration.

Modem configuration is split into 2 parts: before ; and after.

Once a modem is plugged-in, it should declare itself in first configuration (normally with at least: A1 - virtual CD drive with Drivers and application). If the drivers are installed, they will see the modem and issue a special command to switch to a “working” configuration - this is 2,7 interfaces in this example.

Warning: Never turn Off PC interface! (2:PCUI in this example) You will lose the ability to access modem with terminal and change the configuration.

You can add more interfaces to be active i.e. SD card:

If you get an ERROR, maybe the numerical mode is not sorted (16,2,7)→(2,7,16). If your device answers to set command with OK but AT^SETPORT? doesn't show your desired settings, you can try using space in between numerical modes(2,7) and alphabetical modes(A2) like so:

How to force LTE connection

Using telnet / SSH command line.

 Number format, network search mode 0 AUTO 1 GSM only 2 UMTS only 3 LTE only Number format, when to take effect 0 Take effect after UE reboots 1 Take effect immediately
echo -e "AT+QCFG=\"nwscanmode\",3,1" > /dev/ttyUSB2
echo -e "AT+QCFG=\"nwscanmode\",0,1" > /dev/ttyUSB2

Further references

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website. OK More information about cookies

Self-registration in the wiki has been disabled.
If you want to contribute to the OpenWrt wiki, please post HERE in the forum or ask on IRC for access.

Except where otherwise noted, content on this wiki is licensed under the following license:
CC Attribution-Share Alike 4.0 International

Источник

Оцените статью
Adblock
detector