Using AT commands with an Android phone

2019-08-07 11:22发布

问题:

I'm writing a program that is able to send and receive data from the GSM modem in my Android phone with AT commands.

I execute the following shell script:

su
echo -e "AT+CSQ?\r" > /dev/smd0
cat /dev/smd0 > /dev/asd.txt

The asd.txt file is created, however there is nothing in it (it should write out the signal strength). It looks like it hangs at the cat command, I think because it doesn't get any output. I've tried some other commands, but I had no luck so far. Can you recommend anything?

回答1:

You can try to use the atinout program, it should behave like the following:

$ echo AT+CSQ | atinout - /dev/smd0 -
AT+CSQ
+CSQ: <rssi>,<ber>

OK
$

Run as ... - /dev/smd0 /dev/asd.txt if you want to capture the results like in your code. Notice that you should run AT+CSQ, not AT+CSQ?.

(the Makefile in atinout-0.9.tar.gz needs a small change to compile, the git source is fine).