Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:network:wan:wwan:at_commands [2020/06/20 12:59] – Rework article, add section on how to send AT commands from OpenWrt axxdocs:guide-user:network:wan:wwan:at_commands [2024/03/22 01:05] – [echo] andrewz
Line 1: Line 1:
-====== How To send AT commands to device ======+====== 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 ===== ===== From OpenWrt =====
-To send AT commands directly from OpenWrt, you can use ''socat''.+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.
  
-This will open prompt where you can enter AT commands (see examples in the section below).+A better solution is using proper terminal application like ''picocom'', which can both send commands and print the modem's answers. There are other alternatives available like ''socat''.
  
-To test things are working, you can issue ''ATI'' which should return basic information such as brandmodel and firmware revision.+Once the appropriate //serial// driver is loaded (typically - ''kmod-usb-serial-option'')the modem will expose a number of ''/dev/ttyUSBx'' interfaces. Usually only one or two of them will respond to AT commands.
  
-For instanceto access a Quectel EP06 LTE modem, which creates 4 devices (''/dev/ttyUSB0'' through to ''/dev/ttyUSB3''):+As an examplepopular Quectel EP06 LTE modem will create serial devices''/dev/ttyUSB0'' through to ''/dev/ttyUSB3''
 + 
 +To find the serial devices added to the system, try looking through ''logread'' and/or ''dmesg'' output. Something like the following may help:
 <code> <code>
-socat /dev/ttyUSB2,crnl+dmesg | grep -A 1 -B 12 ttyUSB
 </code> </code>
  
-(Here, socat sends a carriage return (cr) and a new line (nl) after each command, which seems to be needed for this modem.)+For some modems ''ttyACM'' devices will be created instead of ''ttyUSB''.
  
-To find the device on which to run ''socat'', try looking through ''dmesg''Something like the following may help:+==== picocom ==== 
 + 
 +''picocom'' is a simple terminal program that is installed in a standard way with ''opkg install picocom'' or through the web interface. 
 + 
 +Sample command line:
 <code> <code>
-dmesg | grep -A 1 -B 12 ttyUSB+picocom /dev/ttyUSB2
 </code> </code>
 +Adding ''--q'' on the command line will suppress extra output with some help and other information.
  
-Some modems also show up as a ''ttyACM'' device.+ 
 +==== socat ==== 
 + 
 +''socat'' will open prompt where you can enter AT commands (see examples in the [[docs:guide-user:network:wan:wwan:at_commands#examples_of_at_commands|section below]]). 
 + 
 +Here is a command line example: 
 +<code> 
 +socat - /dev/ttyUSB2,crnl 
 +</code> 
 + 
 +In this example ''socat'' will send a //carriage return// (cr) and a //new line// (nl) after each command.
  
 To quit ''socat'', use ''ctrl+C''. To quit ''socat'', use ''ctrl+C''.
 +
 +==== echo ====
 +
 +See examples below. ''echo -e'' is used to send //escaped// characters such as quotation marks.
 +
 +Alternative solution - use ''echo'' with ''socat'': ''echo -e ATI | socat - /dev/ttyUSB2,crnl''
  
 ===== From a computer ===== ===== From a computer =====
Line 39: Line 63:
 ===== Examples of AT commands ===== ===== Examples of AT commands =====
  
-Here is example for the Huawei E392 LTE/3G dongle:+To test things are working, you can issue a standard ''ATI'' command 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) 
 + 
 + 
 +===== Huawei E392 =====
  
 <code> <code>
Line 86: Line 115:
 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. 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.+:!: **Warning: Never turn Off the AT Command interface! ("PCUIin Huawei terms)** 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: You can add more interfaces to be active i.e. SD card:
Line 93: Line 122:
 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: 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:
 <code> <code>
-AT^SETPORT="A1,A2;2,7, A2"+AT^SETPORT="A1,A2;2,7,A2"
 </code> </code>
  
 Or with multiple modes: Or with multiple modes:
 <code> <code>
-AT^SETPORT="A1,A2;2,7, A1,A2"+AT^SETPORT="A1,A2;2,7,A1,A2"
 </code> </code>
  
-===== How to force LTE connection =====+===== Quectel modems =====
  
-Using telnet / SSH command line.+==== How to force LTE connection ====
  
 **Format:** **Format:**
 <code> <code>
-AT+QCFG=nwscanmode[,<scanmode>[,<effect>]]+AT+QCFG="nwscanmode"[,<scanmode>[,<effect>]]
 </code> </code>
  
Line 137: Line 166:
 ===== Further references ===== ===== Further references =====
  
-https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-3g+  * [[https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-3g|Chromium project page]] on debugging cellular modems 
 +  * [[https://en.wikipedia.org/wiki/Hayes_command_set|Wikipedia article]] on AT commands and their history
  
  • Last modified: 2024/11/10 11:22
  • by andrewz