Skip to content

Commit

Permalink
Read sms in unsynchronized mode (#33)
Browse files Browse the repository at this point in the history
* Update arduino-cli binary filename

The arduino-cli binary filename was recently changed, which broke CI builds:

mv: cannot stat ‘arduino-cli-*-linux64’: No such file or directory

* Enable SMS read in unsynch mode

* Fix typo

* Fix name change of binary

* Ensure initialization of sms data end index

* Handle sender number correctly

* Keep track of start of SMS AT response

* Clear buffer

* Clarify header comment

* Adjust _smsDataEndIndex to point at end of SMS

* Revert smscharset additions

* Rewrite to save memory

* Let the available() method advance to next sms as before

* Simplify by removing smsIndexStart

Co-authored-by: per1234 <accounts@perglass.com>
  • Loading branch information
janakelarsson and per1234 authored Dec 2, 2020
1 parent 86b4d24 commit 6bcf2de
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/NB_SMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ int NB_SMS::endSMS()

int NB_SMS::available()
{
if (_incomingBuffer.length() != 0) {
int nextMessageIndex = _incomingBuffer.indexOf("\r\n+CMGL: ");
int nextMessageIndex = _incomingBuffer.indexOf("+CMGL: ");

if (nextMessageIndex != -1) {
_incomingBuffer.remove(0, nextMessageIndex + 2);
} else {
_incomingBuffer = "";
}
if (nextMessageIndex != -1) {
_incomingBuffer.remove(0, nextMessageIndex);
} else {
_incomingBuffer = "";
}

if (_incomingBuffer.length() == 0) {
Expand All @@ -141,9 +139,12 @@ int NB_SMS::available()
}

if (_incomingBuffer.startsWith("+CMGL: ")) {

_incomingBuffer.remove(0, 7);

_smsDataIndex = _incomingBuffer.indexOf('\n') + 1;

_smsDataEndIndex = _incomingBuffer.indexOf("\r\n+CMGL: ");
_smsDataEndIndex = _incomingBuffer.indexOf("\r\n+CMGL: ",_smsDataIndex);
if (_smsDataEndIndex == -1) {
_smsDataEndIndex = _incomingBuffer.length() - 1;
}
Expand Down Expand Up @@ -207,13 +208,12 @@ int NB_SMS::peek()

void NB_SMS::flush()
{
int smsIndexStart = _incomingBuffer.indexOf(' ');
int smsIndexEnd = _incomingBuffer.indexOf(',');

if (smsIndexStart != -1 && smsIndexEnd != -1) {
if (smsIndexEnd != -1) {
while (MODEM.ready() == 0);

MODEM.sendf("AT+CMGD=%s", _incomingBuffer.substring(smsIndexStart + 1, smsIndexEnd).c_str());
MODEM.sendf("AT+CMGD=%s", _incomingBuffer.substring(0, smsIndexEnd).c_str());

if (_synch) {
MODEM.waitForResponse(55000);
Expand Down

0 comments on commit 6bcf2de

Please sign in to comment.