@@ -493,6 +493,30 @@ bool Sim800L::sendSms(char* number,char* text)
493
493
}
494
494
495
495
496
+ void Sim800L::prepareForSmsReceive ()
497
+ {
498
+ // Configure SMS in text mode
499
+ this ->SoftwareSerial ::print (F (" AT+CMGF=1\r " ));
500
+ this ->SoftwareSerial ::print (F (" AT+CNMI=2,1,0,0,0\r " ));
501
+ }
502
+
503
+ const uint8_t Sim800L::checkForSMS ()
504
+ {
505
+ _buffer = _readSerial (100 );
506
+ if (_buffer.length () == 0 )
507
+ {
508
+ return 0 ;
509
+ }
510
+ // Serial.println(_buffer);
511
+ // +CMTI: "SM",1
512
+ if (_buffer.indexOf (" CMTI" ) == -1 )
513
+ {
514
+ return 0 ;
515
+ }
516
+ return _buffer.substring (_buffer.indexOf (' ,' )+1 ).toInt ();
517
+ }
518
+
519
+
496
520
String Sim800L::getNumberSms (uint8_t index)
497
521
{
498
522
_buffer=readSms (index);
@@ -513,25 +537,28 @@ String Sim800L::getNumberSms(uint8_t index)
513
537
514
538
String Sim800L::readSms (uint8_t index)
515
539
{
516
-
517
540
// Can take up to 5 seconds
518
541
519
- this ->SoftwareSerial ::print (F (" AT+CMGF=1\r " ));
542
+ if (( _readSerial (5000 ).indexOf (" ER" )) != -1 )
543
+ {
544
+ return " " ;
545
+ }
520
546
521
- if (( _readSerial (5000 ).indexOf (" ER" )) ==-1 )
547
+ this ->SoftwareSerial ::print (F (" AT+CMGR=" ));
548
+ this ->SoftwareSerial ::print (index);
549
+ this ->SoftwareSerial ::print (" \r " );
550
+ _buffer=_readSerial ();
551
+ // Serial.println(_buffer);
552
+ if (_buffer.indexOf (" CMGR" ) == -1 )
522
553
{
523
- this ->SoftwareSerial ::print (F (" AT+CMGR=" ));
524
- this ->SoftwareSerial ::print (index);
525
- this ->SoftwareSerial ::print (" \r " );
526
- _buffer=_readSerial ();
527
- if (_buffer.indexOf (" CMGR:" )!=-1 )
528
- {
529
- return _buffer;
530
- }
531
- else return " " ;
554
+ return " " ;
532
555
}
533
- else
534
- return " " ;
556
+
557
+ _buffer=_readSerial ();
558
+ // Serial.println(_buffer);
559
+ byte first = _buffer.indexOf (' \n ' , 2 ) + 1 ;
560
+ byte second = _buffer.indexOf (' \n ' , first);
561
+ return _buffer.substring (first, second);
535
562
}
536
563
537
564
0 commit comments