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"
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"
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 ("
"
), and process the resulting line string in one single operation. So you really should go and implement the read_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 use strcmp(line, "OK
")
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 "
"
2.
Now there are more final result codes than just OK
and ERROR
, 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.
1
The "
> "
prefix for AT+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
and S4
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.