| Both sides previous revision Previous revision Next revision | Previous revisionLast revisionBoth sides next revision |
| docs:user-guide:wan:at_commands [2018/02/20 21:08] – ↷ Page moved from docs:user-guide:advanced:at_commands to docs:user-guide:wan:at_commands bobafetthotmail | docs:guide-user:network:wan:wwan:at_commands [2024/11/10 11:22] – [picocom] andrewz |
|---|
| ====== 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. |
| |
| You need to connect device/modem to PC and access it with any COM terminal. | |
| |
| If you are not familiar with using COM terminal, download some graphical tool like: **CuteCom** or **minicom**. | ===== 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. |
| |
| Usually these settings work fine: | A better solution is using a proper terminal application like ''picocom'', which can both send commands and print the modem's answers. There are other alternatives available like ''socat''. |
| | |
| | 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. |
| | |
| | As an example, popular Quectel EP06 LTE modem will create 4 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> |
| | root@OpenWrt:~# dmesg | grep -A 1 -B 12 ttyUSB |
| | </code> |
| | |
| | For some modems ''ttyACM'' devices will be created instead of ''ttyUSB''. |
| | |
| | ==== 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> |
| | root@OpenWrt:~# picocom /dev/ttyUSB2 |
| | </code> |
| | Adding ''--q'' on the command line will suppress extra output with some help and other information. |
| | |
| | |
| | ==== socat ==== |
| | |
| | ''socat'' will open a 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''. |
| | |
| | ==== 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 ===== |
| | 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: |
| <code> | <code> |
| Device: /dev/ttyUSB0 | Device: /dev/ttyUSB0 |
| </code> | </code> |
| |
| Here is Example for Huawei E392 LTE/3G dongle. | ===== Examples of AT commands ===== |
| | |
| | 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> |
| </code> | </code> |
| |
| AT^SETPORT=? - Lists the Available interfaces and their numbers | Explanations: |
| |
| AT^SETPORT? - Show current configuration | <code> |
| | AT^SETPORT=? - Lists the Available interfaces and their numbers |
| AT^SETPORT="A1;2,7" - Sets configuration. | AT^SETPORT? - Show current configuration |
| | AT^SETPORT="A1;2,7 - Sets configuration. |
| | </code> |
| |
| Modem configuration is splitted into 2 parts: before ";" and after. | Modem configuration is split into 2 parts: before '';'' and after. |
| |
| Once modem is plugged-In - it declares itself in first configuration (normally with at least: A1 - virtual CD drive with Drivers and application). | 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 see the modem and issue a special command to switch to "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. |
| |
| :!: **Never turn Off PC interface (2:PCUI in this example)!!!** Otherwise you'd not have ability to access modem with terminal and change the config. | :!: **Warning: Never turn Off the AT Command interface! ("PCUI" in 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: |
| <code>AT^SETPORT="A1,A2;2,7,A2"</code> | <code>AT^SETPORT="A1,A2;2,7,A2"</code> |
| |
| If you get **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 this: | 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> |
| | AT^SETPORT="A1,A2;2,7,A2" |
| | </code> |
| |
| | Or with multiple modes: |
| <code> | <code> |
| AT^SETPORT="A1,A2;2,7, A2" | AT^SETPORT="A1,A2;2,7,A1,A2" |
| or with multiple modes: | |
| AT^SETPORT="A1,A2;2,7, A1,A2" | |
| </code> | </code> |
| | |
| | ===== Quectel modems ===== |
| | |
| | ==== How to force LTE connection ==== |
| | |
| | **Format:** |
| | <code> |
| | AT+QCFG="nwscanmode"[,<scanmode>[,<effect>]] |
| | </code> |
| | |
| | **Parameters**: |
| | <code> |
| | <scanmode> Number format, network search mode |
| | 0 AUTO |
| | 1 GSM only |
| | 2 UMTS only |
| | 3 LTE only |
| | |
| | <effect> Number format, when to take effect |
| | 0 Take effect after UE reboots |
| | 1 Take effect immediately |
| | </code> |
| | |
| | **Examples:** |
| | |
| | Set modem to LTE only: |
| | <code> |
| | echo -e "AT+QCFG=\"nwscanmode\",3,1" > /dev/ttyUSB2 |
| | </code> |
| | |
| | Set it back to "auto": |
| | <code> |
| | echo -e "AT+QCFG=\"nwscanmode\",0,1" > /dev/ttyUSB2 |
| | </code> |
| | |
| | ===== Further references ===== |
| | |
| | * [[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 |
| |