How to send AT commands to a modem in Linux?
Solution 1
Try socat - /dev/ttyUSB2,crnl
This tells socat to send a carriage return as well as a line feed.
Clarification - this goes back to the dark days of electric typewriters, where you would have to tell it to roll the carriage back to position 0 on the page - ergo, a carriage return - as well as telling it to move the paper up one line.
Solution 2
The best way to send AT commands to a modem in Linux is to use the program atinout which is written with the sole purpose of sending AT commands to a modem from the command line.
You can use it to test if a modem is up and running, make a backup of the phone book:
$ atinout - /dev/ttyACM0 ten_first_phonebook_entries.txt <<EOF
at+cscs="UTF-8"
at+cpbs="SM"; +cpbr=1,10
at+cpbs="ME"; +cpbr=1,10
EOF
$
or any other things you make use of AT commands for.
Solution 3
I came across this Chromium project post that shows what you want. It's titled: Debugging a cellular modem.
excerpt from that page
Communicating directly with a modem with the AT command set
Most modems support AT commands which control the modem and query for information. On a Chromium OS device with the developer mode enabled, you can use the socat command to communicate with the modem. You need a Chromium OS device with a test image installed (or you can use gmerge socat if you are familiar with the dev server) . For example:
- Type CTRL+ALT+T to enter the crosh shell.
- Type shell to enter the bash shell.
- Figure you which USB device to use with: ls /dev/ttyACM* /dev/ttyUSB*
- Stop modem manager if it is running: sudo stop modemmanager
- Type sudo socat - /dev/ttyACM1,crnl or sudo socat - /dev/ttyUSB0 to communicate with the modem.
- Ensure that the modem is enabled with the command: "AT+CFUN=1"
For example:
crosh> shell chronos@localhost ~ $ sudo stop modemmanager chronos@localhost ~ $ ls /dev/ttyACM* /dev/ttyUSB* /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 chronos@localhost ~ $ socat - /dev/ttyUSB1 ATZ OK AT+CFUN=1 OK ATI Manufacturer: Qualcomm Incorporated Model: ...... Revision:.... ESN: 0x80d... +GCAP: +CIS707A, .... chronos@localhost ~ $
Depending on the modem, you can try different AT commands, e.g. "AT+CGMI", "AT+CGSN", etc.
Related videos on Youtube
user3185306
Updated on September 18, 2022Comments
-
user3185306 almost 2 years
In Linux (Ubuntu) I am trying to send AT commands to a modem at
/dev/ttyACM0
. I tried to do it as:sudo socat - /dev/ttyACM0
but when typing anything I just get a line repeating this command (I expect an
OK
).When I do
sudo minicom modem1
it seems to work. I type an
AT
and get anOK
. I type some crap, I get anERROR
.It seems that
modem1
for minicom is somehow configured to use the modem at/dev/ttyACM0
.How can I use socat to send AT commands? Do I need to configure something? Maybe I can use configurations for
modem1
of minicom (I do not know how to find/see this configuration)?Additional information
Is the given
socat
command correct? Should I play with some options? With the-v
option I see the following:AT > 2013/10/23 17:10:28.917413 length=3 from=0 to=2 AT < 2013/10/23 17:10:28.921598 length=3 from=0 to=2 AT AT ksjdhfjdgfhjkdfh > 2013/10/23 17:10:30.244923 length=17 from=3 to=19 ksjdhfjdgfhjkdfh < 2013/10/23 17:10:30.251383 length=29 from=3 to=31 ksjdhfjdgfhjk\b \bd\b \bf\b \bh\b \b ksjdhfjdgfhj
The device itself is found with the following dmesg output:
[5983726.808063] usb 2-1: USB disconnect, device number 3 [5983730.800021] usb 2-1: new full-speed USB device number 4 using uhci_hcd [5983730.920014] usb 2-1: device descriptor read/64, error -71 [5983733.629524] usb 2-1: New USB device found, idVendor=0572, idProduct=1329 [5983733.629533] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [5983733.629539] usb 2-1: Product: USB Modem [5983733.629544] usb 2-1: Manufacturer: Conexant [5983733.629549] usb 2-1: SerialNumber: 24680246 [5983733.632673] cdc_acm 2-1:1.0: ttyACM0: USB ACM device
And the tty is configured as follows:
speed 57600 baud; line = 0; eof = ^A; min = 1; time = 0; -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -echo -echoe
-
Alex over 10 yearsmaybe you can get it working playing with these TERMIOS options but I never checked.
-
slm over 10 yearsSearch through this website looking for "socat modem" there are 5 hits, see if any of them are helpful. I do not have a setup to try these out on so I can't really help beyond that. (unix.stackexchange.com/search?q=socat+modem)
-
user3185306 over 10 yearsThe hints are not useful. I seem to have a real basic problem, because socat should work. It worked before. But I do not know what the problem is. Is the above command correct is my first question.
-
WillShakes about 10 yearsThis may help Serial-port thermal printer communication
-
-
user3185306 over 10 yearsNo AT command at all is working! This is my problem! Do I need to configure something? Is the commmand line ok? Do I do some big mistake?
-
slm over 10 years@Alex - as I said I do not have any of this hardware so it's difficult to assist you beyond providing information like this. You'll have to debug it. I'd try power cycling the devices in question and see if they're in a hung state, look in the
dmesg
log for information. Sorry I can't assist you more than this. -
mikeserv over 10 yearsCan't you just echo "AT+DONTREMEMBERZMODEM" > /dev/modemtty?