echo -ne "ATZ\r\n" > /dev/ttyUSB0
echo -ne "AT+CMGF=1\r\n" > /dev/ttyUSB0
echo -ne "AT+CMGS=\"888XXXXXXX\"\rhello\x1a\n" > /dev/ttyUSB0
Since CMS ERROR-96 is for mandatory information missing.
echo -ne "ATZ\r\n" > /dev/ttyUSB0
echo -ne "AT+CMGF=1\r\n" > /dev/ttyUSB0
echo -ne "AT+CMGS=\"888XXXXXXX\"\rhello\x1a\n" > /dev/ttyUSB0
Since CMS ERROR-96 is for mandatory information missing.
No, you cannot send AT commands in this way. Start by reading the V.250 (all of chapter 5) and 27.005 specifications (the AT+CMGS command), links are in the tag info page. Those documents will teach you a lot with regards to AT command handling, syntax and behaviour.
The worst mistake is to send AT command lines without waiting for the final result code. In the same way you would not write a HTTP client that totally ignores responses from the HTTP server, you should not send AT commands and totally ignore responses from the modem.
And for the AT+CMGS
command you have to wait with sending the sms payload data until after you have received the "\r\n> "
prefix (see the first part of this answer for details).
Other things, AT command lines should be terminated with \r
only and not \r\n
. Opening and closing the modem device over and over again like multiple shell command redirects will cause might be an issue. That totally depends on the specific modem, and there is no guarantee that this will work reliably.
To address these last points I wrote the atinout program to make sending AT command from the command line simple and reliable. The first two AT commands can be sent as
$ echo ATZ | atinout - /dev/ttyUSB0 -
ATZ
OK
$ echo AT+CMGF=1 | atinout - /dev/ttyUSB0 -
AT+CMGF=1
OK
$
or alternatively
$ echo ATZ > commands.txt
$ echo AT+CMGF=1 >> commands.txt
$ atinout commands.txt /dev/ttyUSB0 output.txt
but for AT+CMGS I guess you have to use expect for the time being (in the future atinout will have a companion program specifically for sending AT+CMGS).