I am using an Arduino Uno with a sim900 gps/gprs module and I'm using at commands, how can I get the response of at command (i.e OK, ERROR) so that I can do something if response == "OK"
or response == "ERROR"
相关问题
- Listening to outgoing sms not working android
- ESP266 Timed out waiting for packet header
- Android app not synchronized with Arduino Serial c
- Serial Communication between Arduino and Python, i
- Can't remove SMS logs from call log on Samsung
相关文章
- Permission Denial: broadcasting Intent android.pro
- How to Receive SMS Only From One Specific Number (
- Send an SMS via Skype with PHP
- Arduino not able to send serial data back
- GSM encoding for SMS with special characters (Twil
- Calculate SMS Length/Parts C#
- XTEA encryption in PHP and decryption in C
- Twilio send and receive SMS through Google Apps Sc
If you have not yet read all of chapter 5 in V.250 specification stop reading here and do so immediately, it is an important basis for the rest of this answer, I'll wait until you'll come back. Some of the references to alphabets (short version: ignore this/treat it as ASCII) and S-registers might seem cryptic but don't give up, it will grow on you quickly.
The only correct way to process modem output is to divide the output into complete lines and iterate one full line at the time. This is universal and applies to absolutely all AT commands (with only one single exception that I can think of1).
Let me emphasis that: you should only split modem response text on strict end of line boundaries (
"\r\n"
), and process the resulting line string in one single operation. So you really should go and implement theread_line_from_modem
function I suggested in my previous answer.This means that whenever you want to check for the
OK
result code you should only usestrcmp(line, "OK\r\n")
and not strstr or similar because you know you are processing a complete, full line which should start with the final result code at the very beginning and it will always be followed by"\r\n"
2.Now there are more final result codes than just
OK
andERROR
, and instead of trying to figure out everything by yourself3 I suggest looking at is_final_result_code or isFinalResponseSuccess as listed in this answer.Summary
1 The
"\r\n> "
prefix forAT+CMGS
is the only place you do something a bit different, i.e. start processing modem response on something other than a strict line boundary.2 Unless you have misconfigured
S3
andS4
which you never should do.3 The list in V.250 is not complete, there exist a couple more defined in 27.005 and 27.007.
You need to read the response from the serial connection that you are talking to the module with something like:
(
mySerial
refers to the serial port that you are using with the module, if you are just using the normal serial port on pins 0 and 1 then you should replace it withSerial
)You will probably want to trim any whitespace characters from the beginning and the end using
response.trim()
before checking to see if it equals one of the responses you are looking for.I just wanted to add that K.H.A.J.A.S answer helped me but I had to modify it before it worked like so:
Whereas his answer had [i++] so it was incrementing i in the for loop and then incrementing i again when storing that char in response index i.
You can use following code to read response from SIM900 GSM Module just after issuing AT command.
After reading response you can use
strstr()
function to check whether it is 'OK' or 'ERROR', as given below: