Skip to content

Commit 7d6aff2

Browse files
authored
Added sleep mode and functionality mode
Added sleep mode and functionality mode
1 parent 77b76e2 commit 7d6aff2

File tree

6 files changed

+289
-19
lines changed

6 files changed

+289
-19
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
## Library SIM800l Module for Arduino UNO
22
The Purpose of This library is to use the module in the most easy way and transparent.
3-
Website: [Sim800l library](https://cristiansteib.github.io/Sim800l/)
3+
Website: [Sim800l library](https://github.com/VittorioEsposito/Sim800l-revised)
44

5-
##To download and Install.
6-
Go to [Releases](https://github.com/cristiansteib/Sim800l/releases) click the " Source Code (zip) " button, then rename the uncompressed folder to **Sim800l**.
7-
Check that the *Sim800l* folder contains Sim800l.cpp and Sim800l.h
85

96
Go to arduino IDE Sketch >> Import Library >> add library... Select the folder Sim800l
107

@@ -31,6 +28,10 @@ Name|Return|Notes
3128
begin()|None|Initialize the library
3229
begin(number)|None|Initialize the library
3330
reset()|None|Reset the module,and wait to Sms Ready.
31+
setSleepMode(bool)|true or false|enable or disable sleep mode
32+
getSleepMode()|true or false|return sleep mode
33+
setFunctionalityMode(number)|true or false|set functionality mode
34+
getFunctionalityMode()|true or false|return functionality mode
3435
sendSms(number,text)|true or false|parameters must be Strings.
3536
readSms(index)|String|index is the position of the sms in the prefered memory storage
3637
getNumberSms(index)|String|returns the number of the sms.

Sim800l.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ void Sim800l::begin(){
7676
_baud = DEFAULT_BAUD_RATE; // Default baud rate 9600
7777
SIM.begin(_baud);
7878

79+
_sleepMode = 0;
80+
_functionalityMode = 1;
81+
7982
#if (LED_FLAG)
8083
pinMode(LED_PIN, OUTPUT);
8184
#endif
@@ -100,6 +103,57 @@ void Sim800l::begin(uint32_t baud) {
100103
}
101104

102105

106+
/*
107+
* AT+CSCLK=0 Disable slow clock, module will not enter sleep mode.
108+
* AT+CSCLK=1 Enable slow clock, it is controlled by DTR. When DTR is high, module can enter sleep mode. When DTR changes to low level, module can quit sleep mode
109+
*/
110+
bool Sim800l::setSleepMode(bool state) {
111+
112+
_sleepMode = state;
113+
114+
if (_sleepMode) SIM.print(F("AT+CSCLK=1\r\n "));
115+
else SIM.print(F("AT+CSCLK=0\r\n "));
116+
117+
if ( (_readSerial().indexOf("ER"))!=-1) {return false;}else return true;
118+
}
119+
120+
bool Sim800l::getSleepMode() {
121+
return _sleepMode;
122+
}
123+
124+
/*
125+
* AT+CFUN=0 Minimum functionality
126+
* AT+CFUN=1 Full functionality (defualt)
127+
* AT+CFUN=4 Flight mode (disable RF function)
128+
*/
129+
bool Sim800l::setFunctionalityMode(uint8_t fun) {
130+
131+
if (fun!=0 || fun!=1 || fun!=4) return true;
132+
133+
_functionalityMode = fun;
134+
135+
switch(_functionalityMode) {
136+
case 0:
137+
SIM.print(F("AT+CFUN=0\r\n "));
138+
break;
139+
case 1:
140+
SIM.print(F("AT+CFUN=1\r\n "));
141+
break;
142+
case 4:
143+
SIM.print(F("AT+CFUN=4\r\n "));
144+
break;
145+
}
146+
147+
if ( (_readSerial().indexOf("ER"))!=-1) {return false;}else return true;
148+
149+
}
150+
151+
uint8_t Sim800l::getFunctionalityMode() {
152+
return _functionalityMode;
153+
}
154+
155+
156+
103157
//
104158
//PRIVATE METHODS
105159
//
@@ -394,4 +448,4 @@ bool Sim800l::updateRtc(int utc){
394448
if ( (_readSerial().indexOf("ER"))!=-1) {return false;}else return true;
395449

396450

397-
}
451+
}

Sim800l.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,33 @@ class Sim800l
8585
uint32_t _baud;
8686
int _timeout;
8787
String _buffer;
88+
bool _sleepMode;
89+
uint8_t _functionalityMode;
8890

8991
String _readSerial();
9092

9193

9294
public:
93-
95+
9496
void begin(); //Default baud 9600
9597
void begin(uint32_t baud);
9698
void reset();
97-
98-
// Methods for calling || Funciones de llamadas.
99+
100+
bool setSleepMode(bool state);
101+
bool getSleepMode();
102+
bool setFunctionalityMode(uint8_t fun);
103+
uint8_t getFunctionalityMode();
104+
105+
// Methods for callinG
99106
bool answerCall();
100107
void callNumber(char* number);
101108
bool hangoffCall();
102109
uint8_t getCallStatus();
103-
//Methods for sms || Funciones de SMS.
110+
//Methods for sms
104111
bool sendSms(char* number,char* text);
105-
String readSms(uint8_t index); //return all the content of sms
106-
String getNumberSms(uint8_t index); //return the number of the sms..
107-
bool delAllSms(); // return : OK or ERROR ..
112+
String readSms(uint8_t index); //return all the content of sms
113+
String getNumberSms(uint8_t index); //return the number of the sms..
114+
bool delAllSms(); // return : OK or ERROR ..
108115

109116
void signalQuality();
110117
void setPhoneFunctionality();
@@ -114,6 +121,7 @@ class Sim800l
114121
void RTCtime(int *day,int *month, int *year,int *hour,int *minute, int *second);
115122
String dateNet(); //return date,time, of the network
116123
bool updateRtc(int utc); //Update the RTC Clock with de Time AND Date of red-.
124+
117125
};
118126

119127
#endif
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* This library was written by Cristian Steib.
3+
* steibkhriz@gmail.com
4+
*
5+
* Revised by:
6+
* Vittorio Esposito - https://github.com/VittorioEsposito
7+
*
8+
*
9+
* Designed to work with the GSM Sim800l.
10+
*
11+
* ENG
12+
* This library uses SoftwareSerial, you can define RX and TX pins
13+
* in the header "Sim800l.h", by default pins are RX=10 and TX=11.
14+
* Be sure that GND is connected to arduino too.
15+
* You can also change the RESET_PIN as you prefer.
16+
*
17+
* ESP
18+
* Esta libreria usa SoftwareSerial, se pueden cambiar los pines de RX y TX
19+
* en el archivo header, "Sim800l.h", por defecto los pines vienen configurado en
20+
* RX=10 TX=11.
21+
* Tambien se puede cambiar el RESET_PIN por otro que prefiera
22+
*
23+
* ITA
24+
* Questa libreria utilizza la SoftwareSerial, si possono cambiare i pin di RX e TX
25+
* dall' intestazione "Sim800l.h", di default essi sono impostati come RX=10 RX=11
26+
* Assicurarsi di aver collegato il dispositivo al pin GND di Arduino.
27+
* E' anche possibile cambiare il RESET_PIN.
28+
*
29+
*
30+
* PINOUT:
31+
* _____________________________
32+
* | ARDUINO UNO >>> SIM800L |
33+
* -----------------------------
34+
* GND >>> GND
35+
* RX 10 >>> TX
36+
* TX 11 >>> RX
37+
* RESET 2 >>> RST
38+
*
39+
* POWER SOURCE 4.2V >>> VCC
40+
*
41+
*
42+
* SOFTWARE SERIAL NOTES:
43+
*
44+
* PINOUT
45+
* The library has the following known limitations:
46+
* 1. If using multiple software serial ports, only one can receive data at a time.
47+
* 2. Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
48+
* 3. Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
49+
* 4. On Arduino or Genuino 101 the current maximum RX speed is 57600bps
50+
* 5. On Arduino or Genuino 101 RX doesn't work on Pin 13
51+
*
52+
* BAUD RATE
53+
* Supported baud rates are 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, and 115200.
54+
*
55+
*
56+
* Created on: April 20, 2016
57+
* Author: Cristian Steib
58+
* Reviser: Vittorio Esposito
59+
*
60+
*
61+
*/
62+
63+
#include <Sim800l.h>
64+
#include <SoftwareSerial.h> // This is necesary for the library
65+
Sim800l Sim800l; // to declare the library
66+
67+
68+
void setup(){
69+
Serial.begin(9600); // only for debug the results .
70+
Sim800l.begin(); // initializate the library.
71+
72+
73+
74+
// Minimum functionality
75+
if (Sim800l.setFunctionalityMode(0)) Serial.println("ERROR");
76+
else Serial.println("Minimum functionality");
77+
78+
Serial.print("Functionality mode: ");
79+
Serial.println(Sim800l.getFunctionalityMode());
80+
81+
delay(5000);
82+
83+
84+
85+
// full functionality
86+
if (Sim800l.setFunctionalityMode(1)) Serial.println("ERROR");
87+
else Serial.println("Full functionality");
88+
89+
Serial.print("Functionality mode: ");
90+
Serial.println(Sim800l.getFunctionalityMode());
91+
92+
delay(5000);
93+
94+
95+
96+
// Flight mode (disable RF function)
97+
if (Sim800l.setFunctionalityMode(4)) Serial.println("ERROR");
98+
else Serial.println("Flight mode (disable RF function)");
99+
100+
Serial.print("Functionality mode: ");
101+
Serial.println(Sim800l.getFunctionalityMode());
102+
103+
delay(5000);
104+
105+
}
106+
107+
void loop() {
108+
109+
}
110+

examples/sleepMode/sleepMode.ino

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* This library was written by Cristian Steib.
3+
* steibkhriz@gmail.com
4+
*
5+
* Revised by:
6+
* Vittorio Esposito - https://github.com/VittorioEsposito
7+
*
8+
*
9+
* Designed to work with the GSM Sim800l.
10+
*
11+
* ENG
12+
* This library uses SoftwareSerial, you can define RX and TX pins
13+
* in the header "Sim800l.h", by default pins are RX=10 and TX=11.
14+
* Be sure that GND is connected to arduino too.
15+
* You can also change the RESET_PIN as you prefer.
16+
*
17+
* ESP
18+
* Esta libreria usa SoftwareSerial, se pueden cambiar los pines de RX y TX
19+
* en el archivo header, "Sim800l.h", por defecto los pines vienen configurado en
20+
* RX=10 TX=11.
21+
* Tambien se puede cambiar el RESET_PIN por otro que prefiera
22+
*
23+
* ITA
24+
* Questa libreria utilizza la SoftwareSerial, si possono cambiare i pin di RX e TX
25+
* dall' intestazione "Sim800l.h", di default essi sono impostati come RX=10 RX=11
26+
* Assicurarsi di aver collegato il dispositivo al pin GND di Arduino.
27+
* E' anche possibile cambiare il RESET_PIN.
28+
*
29+
*
30+
* PINOUT:
31+
* _____________________________
32+
* | ARDUINO UNO >>> SIM800L |
33+
* -----------------------------
34+
* GND >>> GND
35+
* RX 10 >>> TX
36+
* TX 11 >>> RX
37+
* RESET 2 >>> RST
38+
*
39+
* POWER SOURCE 4.2V >>> VCC
40+
*
41+
*
42+
* SOFTWARE SERIAL NOTES:
43+
*
44+
* PINOUT
45+
* The library has the following known limitations:
46+
* 1. If using multiple software serial ports, only one can receive data at a time.
47+
* 2. Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
48+
* 3. Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
49+
* 4. On Arduino or Genuino 101 the current maximum RX speed is 57600bps
50+
* 5. On Arduino or Genuino 101 RX doesn't work on Pin 13
51+
*
52+
* BAUD RATE
53+
* Supported baud rates are 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, and 115200.
54+
*
55+
*
56+
* Created on: April 20, 2016
57+
* Author: Cristian Steib
58+
* Reviser: Vittorio Esposito
59+
*
60+
*
61+
*/
62+
63+
#include <Sim800l.h>
64+
#include <SoftwareSerial.h> // This is necesary for the library
65+
Sim800l Sim800l; // to declare the library
66+
67+
68+
void setup(){
69+
Serial.begin(9600); // only for debug the results .
70+
Sim800l.begin(); // initializate the library.
71+
72+
// Sleep
73+
if (Sim800l.setSleepMode(true)) Serial.println("ERROR");
74+
75+
if (Sim800l.setSleepMode(false)) Serial.println("Sleep mode is enabled");
76+
else Serial.println("Sleep mode is NOT enabled");
77+
78+
delay(5000);
79+
80+
//Wake up
81+
if (Sim800l.setSleepMode(false)) Serial.println("ERROR");
82+
83+
if (Sim800l.getSleepMode()) Serial.println("Sleep mode is enabled");
84+
else Serial.println("Sleep mode is NOT enabled");
85+
86+
delay(5000);
87+
88+
}
89+
90+
void loop(){
91+
92+
}
93+

keywords.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ getNumberSms KEYWORD2
3333

3434
# Methods for Module (KEYWORD2)
3535
#######################################
36-
begin KEYWORD2
37-
reset KEYWORD2
36+
begin KEYWORD2
37+
reset KEYWORD2
3838
activateBearerProfile KEYWORD2
39-
deactivateBearerProfile KEYWORD2
40-
RTCtime KEYWORD2
41-
dateNet KEYWORD2
42-
updateRtc KEYWORD2
43-
setPhoneFunctionality KEYWORD2
39+
deactivateBearerProfile KEYWORD2
40+
RTCtime KEYWORD2
41+
dateNet KEYWORD2
42+
updateRtc KEYWORD2
43+
setPhoneFunctionality KEYWORD2
44+
setSleepMode KEYWORD2
45+
getSleepMode KEYWORD2
46+
setFunctionalityMode KEYWORD2
47+
getFunctionalityMode KEYWORD2

0 commit comments

Comments
 (0)