Skip to content

Commit

Permalink
Merge pull request #104 from janakelarsson/fixSMS
Browse files Browse the repository at this point in the history
Handle SMS responses
  • Loading branch information
aentinger committed Dec 17, 2020
2 parents fdd1157 + 4e73b61 commit 5cfc6a5
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Modem.cpp
Expand Up @@ -287,16 +287,31 @@ void ModemClass::poll()
if (c == '\n') {
_lastResponseOrUrcMillis = millis();

int endOfResponse = 0;
if (_buffer.startsWith("+CMGL: ")) {
// SMS responses can contain "OK\r\n"
for(int nextSMS = 0; nextSMS != -1; nextSMS = _buffer.indexOf("+CMGL: ",endOfResponse)) {
// First line is SMS info
nextSMS = _buffer.indexOf("\r\n",nextSMS);
// Second line is SMS content
endOfResponse = _buffer.indexOf("\r\n",nextSMS);
if (endOfResponse == -1) {
// Not yet complete SMS
break;
}
}
}

int responseResultIndex = _buffer.lastIndexOf("OK\r\n");
if (responseResultIndex != -1) {
if (responseResultIndex >= endOfResponse) {
_ready = 1;
} else {
responseResultIndex = _buffer.lastIndexOf("ERROR\r\n");
if (responseResultIndex != -1) {
if (responseResultIndex >= endOfResponse) {
_ready = 2;
} else {
responseResultIndex = _buffer.lastIndexOf("NO CARRIER\r\n");
if (responseResultIndex != -1) {
if (responseResultIndex >= endOfResponse) {
_ready = 3;
}
}
Expand Down

0 comments on commit 5cfc6a5

Please sign in to comment.