Merge pull request #10 from dawidcieszynski/master
Skip stream timeouts, et al.
This commit is contained in:
BIN
extras/doc/SIM800 Series_AT Command Manual_V1.09.pdf
Normal file
BIN
extras/doc/SIM800 Series_AT Command Manual_V1.09.pdf
Normal file
Binary file not shown.
Binary file not shown.
BIN
extras/doc/SIM800+Series_Bluetooth_Application_Note_V1.04.pdf
Normal file
BIN
extras/doc/SIM800+Series_Bluetooth_Application_Note_V1.04.pdf
Normal file
Binary file not shown.
BIN
extras/doc/SIM800+Series_Email_Application_Note_V1.00.pdf
Normal file
BIN
extras/doc/SIM800+Series_Email_Application_Note_V1.00.pdf
Normal file
Binary file not shown.
@@ -645,9 +645,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -413,9 +413,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -590,9 +590,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -223,6 +223,11 @@ public:
|
|||||||
if (waitResponse() != 1) {
|
if (waitResponse() != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PREFERRED SMS STORAGE
|
||||||
|
sendAT(GF("+CPMS="), GF("\"SM\""), GF(","), GF("\"SM\""), GF(","), GF("\"SM\""));
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
getSimStatus();
|
getSimStatus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -326,6 +331,28 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool enableBluetooth() {
|
||||||
|
uint16_t state;
|
||||||
|
|
||||||
|
sendAT(GF("+BTPOWER=1"));
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool disableBluetooth() {
|
||||||
|
uint16_t state;
|
||||||
|
|
||||||
|
sendAT(GF("+BTPOWER=0"));
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
During sleep, the SIM800 module has its serial communication disabled. In order to reestablish communication
|
During sleep, the SIM800 module has its serial communication disabled. In order to reestablish communication
|
||||||
pull the DRT-pin of the SIM800 module LOW for at least 50ms. Then use this function to disable sleep mode.
|
pull the DRT-pin of the SIM800 module LOW for at least 50ms. Then use this function to disable sleep mode.
|
||||||
@@ -652,9 +679,167 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t getSMSInterrupt(void){
|
||||||
|
sendAT(GF("+CFGRI?"));
|
||||||
|
if(waitResponse(GF(GSM_NL "+CFGRI:")) != 1) return -1;
|
||||||
|
return stream.readStringUntil('\n').toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool setSMSInterrupt(uint8_t status){
|
||||||
|
sendAT(GF("+CFGRI="), status);
|
||||||
|
if(waitResponse() != 1) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t countSMS(void){
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
if(waitResponse() != 1) return -1;
|
||||||
|
|
||||||
|
sendAT(GF("+CPMS?"));
|
||||||
|
if(waitResponse(GF(GSM_NL "+CPMS:")) != 1) return -1;
|
||||||
|
|
||||||
|
streamSkipUntil(',');
|
||||||
|
uint8_t count = stream.readStringUntil(',').toInt() - 1;
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deleteSMS(){
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
if(waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
sendAT(GF("+CMGDA=\"DEL ALL\""));
|
||||||
|
if(waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deleteSMS(uint8_t i){
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
if(waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
sendAT(GF("+CMGD="), i);
|
||||||
|
if(waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String deleteSMSOpt() {
|
||||||
|
sendAT(GF("+CMGD=?"));
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (waitResponse(10000L, GF(GSM_NL "+CMGD::")) != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
stream.readStringUntil('"');
|
||||||
|
String indexes = stream.readStringUntil('"');
|
||||||
|
stream.readStringUntil(',');
|
||||||
|
String options = stream.readStringUntil('\n');
|
||||||
|
return indexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readSMS(uint8_t i, String& msg){
|
||||||
|
// set message format to text mode
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
// show sms text mode parameters
|
||||||
|
sendAT(GF("+CSDH=1"));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
// set GSM charset
|
||||||
|
sendAT(GF("+CSCS=\"GSM\""));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
sendAT(GF("+CMGR="), i);
|
||||||
|
uint8_t cmgrResponse = waitResponse(GF(GSM_NL "+CMGR:"));
|
||||||
|
if ( cmgrResponse == 1 ) {
|
||||||
|
streamSkipUntil('\n');
|
||||||
|
msg = stream.readStringUntil('\n');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getNewSMSIndex() {
|
||||||
|
if (waitResponse(GF(GSM_NL "+CMTI:")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
streamSkipUntil(',');
|
||||||
|
int res = stream.readStringUntil('\n').toInt();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readSMSRaw(uint8_t i, String& msg) {
|
||||||
|
// set message format to text mode
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
// show sms text mode parameters
|
||||||
|
sendAT(GF("+CSDH=1"));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
// set GSM charset
|
||||||
|
sendAT(GF("+CSCS=\"GSM\""));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
// get message by index
|
||||||
|
sendAT(GF("+CMGR="), i);
|
||||||
|
uint8_t cmgrResponse = waitResponse(GF(GSM_NL "+CMGR:"));
|
||||||
|
if ( cmgrResponse != 1 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = stream.readStringUntil('\n') + '\n'
|
||||||
|
+ stream.readStringUntil('\n') + '\n';
|
||||||
|
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readAllSMSRaw(String& msg) {
|
||||||
|
// set message format to text mode
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
// show sms text mode parameters
|
||||||
|
sendAT(GF("+CSDH=1"));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
// set GSM charset
|
||||||
|
sendAT(GF("+CSCS=\"GSM\""));
|
||||||
|
if (waitResponse() != 1) return false;
|
||||||
|
|
||||||
|
// get all messages
|
||||||
|
sendAT(GF("+CMGL=\"ALL\""));
|
||||||
|
|
||||||
|
const unsigned long timeout = 10000L;
|
||||||
|
unsigned long startMillis = millis();
|
||||||
|
bool isTimeout = false;
|
||||||
|
String line;
|
||||||
|
do {
|
||||||
|
line = stream.readStringUntil('\n');
|
||||||
|
line.trim();
|
||||||
|
if ( line != "" && line != "OK" ) {
|
||||||
|
msg = msg + line + String("\r\n");
|
||||||
|
}
|
||||||
|
isTimeout = (millis() - startMillis) > timeout;
|
||||||
|
delay(0);
|
||||||
|
if ( isTimeout ) {
|
||||||
|
DBG("timeout");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (line != "OK");
|
||||||
|
|
||||||
|
return (line == "OK");
|
||||||
|
}
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
sendAT(GF("+CSCS=\"GSM\""));
|
||||||
|
waitResponse();
|
||||||
sendAT(GF("+CMGS=\""), number, GF("\""));
|
sendAT(GF("+CMGS=\""), number, GF("\""));
|
||||||
if (waitResponse(GF(">")) != 1) {
|
if (waitResponse(GF(">")) != 1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -837,9 +1022,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -606,9 +606,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user