Skip to content

Commit 5f54d5e

Browse files
authored
New methods
bool setPIN(String pin); String getProductInfo(); String getOperatorsList(); String getOperator(); String signalQuality(); // Return value changed to String
1 parent f639320 commit 5f54d5e

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sendSms(number,text)|true or false|parameters must be Strings.
4040
readSms(index)|String|index is the position of the sms in the prefered memory storage
4141
getNumberSms(index)|String|returns the number of the sms.
4242
delAllSms()|true or false|Delete all sms
43+
signalQuality()|String|return info about signal quality
4344
answerCall()|true or false|
4445
callNumber(number)|None|
4546
hangoffCall()|true or false|

Sim800l.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ SoftwareSerial SIM(RX_PIN,TX_PIN);
7070
void Sim800l::begin()
7171
{
7272

73-
pinMode(RX_PIN, INPUT);
74-
pinMode(TX_PIN, OUTPUT);
7573
pinMode(RESET_PIN, OUTPUT);
7674

7775
_baud = DEFAULT_BAUD_RATE; // Default baud rate 9600
@@ -90,8 +88,6 @@ void Sim800l::begin()
9088
void Sim800l::begin(uint32_t baud)
9189
{
9290

93-
pinMode(RX_PIN, INPUT);
94-
pinMode(TX_PIN, OUTPUT);
9591
pinMode(RESET_PIN, OUTPUT);
9692

9793
_baud = baud;
@@ -139,7 +135,7 @@ bool Sim800l::getSleepMode()
139135
bool Sim800l::setFunctionalityMode(uint8_t fun)
140136
{
141137

142-
if (fun!=0 || fun!=1 || fun!=4) return true;
138+
if (fun!=0 || fun!=1 || fun!=4) return false;
143139

144140
_functionalityMode = fun;
145141

@@ -292,7 +288,7 @@ void Sim800l::setPhoneFunctionality()
292288
}
293289

294290

295-
void Sim800l::signalQuality()
291+
String Sim800l::signalQuality()
296292
{
297293
/*Response
298294
+CSQ: <rssi>,<ber>Parameters
@@ -308,7 +304,7 @@ void Sim800l::signalQuality()
308304
99 Not known or not detectable
309305
*/
310306
SIM.print (F("AT+CSQ\r\n"));
311-
Serial.println(_readSerial());
307+
return(_readSerial());
312308
}
313309

314310

@@ -381,8 +377,13 @@ bool Sim800l::hangoffCall()
381377
{
382378
SIM.print (F("ATH\r\n"));
383379
_buffer=_readSerial();
384-
if ( (_buffer.indexOf("OK") ) != -1) return false;
380+
if ( (_buffer.indexOf("ER")) == -1)
381+
{
382+
return false;
383+
}
385384
else return true;
385+
// Error found, return 1
386+
// Error NOT found, return 0
386387
}
387388

388389

@@ -404,21 +405,20 @@ bool Sim800l::sendSms(char* number,char* text)
404405
SIM.print((char)26);
405406
_buffer=_readSerial();
406407
//expect CMGS:xxx , where xxx is a number,for the sending sms.
407-
if (((_buffer.indexOf("CMGS") ) != -1 ) )
408-
{
409-
return true;
410-
}
411-
else
408+
if ( (_buffer.indexOf("ER")) == -1)
412409
{
413410
return false;
414411
}
412+
else return true;
413+
// Error found, return 1
414+
// Error NOT found, return 0
415415
}
416416

417417

418418
String Sim800l::getNumberSms(uint8_t index)
419419
{
420420
_buffer=readSms(index);
421-
Serial.println(_buffer.length());
421+
//Serial.println(_buffer.length());
422422
if (_buffer.length() > 10) //avoid empty sms
423423
{
424424
uint8_t _idx1=_buffer.indexOf("+CMGR:");
@@ -443,7 +443,7 @@ String Sim800l::readSms(uint8_t index)
443443
{
444444
SIM.print (F("AT+CMGR="));
445445
SIM.print (index);
446-
SIM.print("\r");
446+
SIM.print ("\r");
447447
_buffer=_readSerial();
448448
if (_buffer.indexOf("CMGR:")!=-1)
449449
{
@@ -460,15 +460,13 @@ bool Sim800l::delAllSms()
460460
{
461461
SIM.print(F("at+cmgda=\"del all\"\n\r"));
462462
_buffer=_readSerial();
463-
if (_buffer.indexOf("OK")!=-1)
463+
if ( (_buffer.indexOf("ER")) == -1)
464464
{
465465
return false;
466466
}
467-
else
468-
{
469-
return true;
470-
}
471-
// ERROR -> return true
467+
else return true;
468+
// Error found, return 1
469+
// Error NOT found, return 0
472470
}
473471

474472

Sim800l.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
#define BUFFER_RESERVE_MEMORY 255
7777
#define DEFAULT_BAUD_RATE 9600
78-
#define TIME_OUT_READ_SERIAL 60000
78+
#define TIME_OUT_READ_SERIAL 10000
7979

8080

8181
class Sim800l
@@ -108,26 +108,25 @@ class Sim800l
108108
String getOperatorsList();
109109
String getOperator();
110110

111-
// Methods for callinG
112111
bool answerCall();
113112
void callNumber(char* number);
114113
bool hangoffCall();
115114
uint8_t getCallStatus();
116-
//Methods for sms
115+
117116
bool sendSms(char* number,char* text);
118-
String readSms(uint8_t index); //return all the content of sms
119-
String getNumberSms(uint8_t index); //return the number of the sms..
120-
bool delAllSms(); // return : OK or ERROR ..
117+
String readSms(uint8_t index);
118+
String getNumberSms(uint8_t index);
119+
bool delAllSms();
121120

122121

123-
void signalQuality();
122+
String signalQuality();
124123
void setPhoneFunctionality();
125124
void activateBearerProfile();
126125
void deactivateBearerProfile();
127-
//get time with the variables by reference
126+
128127
void RTCtime(int *day,int *month, int *year,int *hour,int *minute, int *second);
129-
String dateNet(); //return date,time, of the network
130-
bool updateRtc(int utc); //Update the RTC Clock with de Time AND Date of red-.
128+
String dateNet();
129+
bool updateRtc(int utc);
131130

132131
};
133132

examples/functionalityMode/functionalityMode.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void setup(){
7272

7373

7474
// Minimum functionality
75-
if (Sim800l.setFunctionalityMode(0)) Serial.println("ERROR");
75+
if (!Sim800l.setFunctionalityMode(0)) Serial.println("ERROR");
7676
else Serial.println("Minimum functionality");
7777

7878
Serial.print("Functionality mode: ");
@@ -83,7 +83,7 @@ void setup(){
8383

8484

8585
// full functionality
86-
if (Sim800l.setFunctionalityMode(1)) Serial.println("ERROR");
86+
if (!Sim800l.setFunctionalityMode(1)) Serial.println("ERROR");
8787
else Serial.println("Full functionality");
8888

8989
Serial.print("Functionality mode: ");
@@ -94,7 +94,7 @@ void setup(){
9494

9595

9696
// Flight mode (disable RF function)
97-
if (Sim800l.setFunctionalityMode(4)) Serial.println("ERROR");
97+
if (!Sim800l.setFunctionalityMode(4)) Serial.println("ERROR");
9898
else Serial.println("Flight mode (disable RF function)");
9999

100100
Serial.print("Functionality mode: ");
@@ -107,4 +107,3 @@ void setup(){
107107
void loop() {
108108

109109
}
110-

examples/sendSms/sendSms.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@
6161
*/
6262

6363
#include <Sim800l.h>
64-
#include <SoftwareSerial.h> //is necesary for the library!!
65-
Sim800l Sim800l; //to declare the library
64+
#include <SoftwareSerial.h> //is necesary for the library!!
65+
Sim800l Sim800l; //to declare the library
6666
char* text;
6767
char* number;
68-
bool error; //to catch the response of sendSms
68+
bool error; //to catch the response of sendSms
6969

7070

7171
void setup(){
72-
Sim800l.begin(); // initializate the library.
73-
text="Testing Sms"; //text for the message.
74-
number="2926451386"; //change to a valid number.
72+
Sim800l.begin(); // initializate the library.
73+
text="Testing Sms"; //text for the message.
74+
number="2926451386"; //change to a valid number.
7575
error=Sim800l.sendSms(number,text);
76+
7677
// OR
7778
//Sim800l.sendSms("+540111111111","the text go here")
7879

79-
8080
}
8181

8282
void loop(){

examples/sleepMode/sleepMode.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ void setup(){
7070
Sim800l.begin(); // initializate the library.
7171

7272
// Sleep
73-
if (Sim800l.setSleepMode(true)) Serial.println("ERROR");
73+
if (!Sim800l.setSleepMode(true)) Serial.println("ERROR");
7474

7575
if (Sim800l.setSleepMode(false)) Serial.println("Sleep mode is enabled");
7676
else Serial.println("Sleep mode is NOT enabled");
7777

7878
delay(5000);
7979

8080
//Wake up
81-
if (Sim800l.setSleepMode(false)) Serial.println("ERROR");
81+
if (!Sim800l.setSleepMode(false)) Serial.println("ERROR");
8282

8383
if (Sim800l.getSleepMode()) Serial.println("Sleep mode is enabled");
8484
else Serial.println("Sleep mode is NOT enabled");

0 commit comments

Comments
 (0)