Skip to content

Instantly share code, notes, and snippets.

@unixbigot
Created April 14, 2022 00:23
Show Gist options
  • Save unixbigot/580a82fdea8a1058e40b92d6242107fe to your computer and use it in GitHub Desktop.
Save unixbigot/580a82fdea8a1058e40b92d6242107fe to your computer and use it in GitHub Desktop.
diff --git a/Code/Adafruit_FONA.cpp b/Code/Adafruit_FONA.cpp
index cc4cf53..cc7fc38 100644
--- a/Code/Adafruit_FONA.cpp
+++ b/Code/Adafruit_FONA.cpp
@@ -28,9 +28,9 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst)
_rstpin = rst;
// apn = F("FONAnet");
- apn = F("");
- apnusername = 0;
- apnpassword = 0;
+ apn[0] = '\0';
+ apnusername[0] = '\0';
+ apnpassword[0] = '\0';
mySerial = 0;
httpsredirect = false;
useragent = F("FONA");
@@ -41,7 +41,7 @@ uint8_t Adafruit_FONA::type(void) {
return _type;
}
-boolean Adafruit_FONA::begin(Stream &port) {
+boolean Adafruit_FONA::begin(Stream &port,fona_timeout_t timeout) {
mySerial = &port;
if (_rstpin != 99) { // Pulse the reset pin only if it's not an LTE module
@@ -54,10 +54,8 @@ boolean Adafruit_FONA::begin(Stream &port) {
digitalWrite(_rstpin, HIGH);
}
- DEBUG_PRINTLN(F("Attempting to open comm with ATs"));
- // give 7 seconds to reboot
- int16_t timeout = 7000;
-
+ DEBUG_PRINTLN(F("Attempting to elicit modem response to AT"));
+ // give 12 seconds to reboot
while (timeout > 0) {
while (mySerial->available()) mySerial->read();
if (sendCheckReply(F("AT"), ok_reply))
@@ -65,14 +63,18 @@ boolean Adafruit_FONA::begin(Stream &port) {
while (mySerial->available()) mySerial->read();
if (sendCheckReply(F("AT"), F("AT")))
break;
- delay(500);
- timeout-=500;
+ delay(1000);
+ timeout-=1000;
}
if (timeout <= 0) {
#ifdef ADAFRUIT_FONA_DEBUG
DEBUG_PRINTLN(F("Timeout: No response to AT... last ditch attempt."));
#endif
+ write('+');
+ write('+');
+ write('+');
+ delay(3000);
sendCheckReply(F("AT"), ok_reply);
delay(100);
sendCheckReply(F("AT"), ok_reply);
@@ -86,8 +88,10 @@ boolean Adafruit_FONA::begin(Stream &port) {
delay(100);
if (! sendCheckReply(F("ATE0"), ok_reply)) {
+ DEBUG_PRINTLN(F("Modem not responding to ATE0"));
return false;
}
+ DEBUG_PRINTLN(F("Modem responded correctly to ATE0"));
// turn on hangupitude
if (_rstpin != 99) sendCheckReply(F("AT+CVHU=0"), ok_reply);
@@ -95,15 +99,13 @@ boolean Adafruit_FONA::begin(Stream &port) {
delay(100);
flushInput();
-
DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN("ATI");
mySerial->println("ATI");
readline(500, true);
- DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
-
-
+ DEBUG_PRINT (F("\t<--- [")); DEBUG_PRINT(replybuffer); DEBUG_PRINTLN("]");
+ flushInput();
if (prog_char_strstr(replybuffer, (prog_char *)F("SIM808 R14")) != 0) {
_type = SIM808_V2;
@@ -134,29 +136,42 @@ boolean Adafruit_FONA::begin(Stream &port) {
} else if (prog_char_strstr(replybuffer, (prog_char *)F("SIM7600E")) != 0) {
_type = SIM7600E;
}
-
+ else {
+ DEBUG_PRINT("Unknown modem type: ");
+ DEBUG_PRINTLN(replybuffer);
+ return false;
+ }
if (_type == SIM800L) {
// determine if L or H
- DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN("AT+GMM");
+ DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN("AT+GMM");
mySerial->println("AT+GMM");
readline(500, true);
- DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
-
+ DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
if (prog_char_strstr(replybuffer, (prog_char *)F("SIM800H")) != 0) {
_type = SIM800H;
}
}
-#if defined(FONA_PREF_SMS_STORAGE)
- sendCheckReply(F("AT+CPMS=" FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE), ok_reply);
+ bool success = true;
+
+#if 0 // defined(FONA_PREF_SMS_STORAGE)
+ if (!sendCheckReply(F("AT+CPMS=" FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE), ok_reply)) {
+ DEBUG_PRINTLN("SMS setup failed");
+ success = false;
+ }
#endif
- return true;
+ if (!sendCheckReply(F("AT"), ok_reply)) {
+ DEBUG_PRINTLN("Modem not responding to AT");
+ success = false;
+ }
+
+ return success;
}
@@ -1400,38 +1415,43 @@ boolean Adafruit_FONA::enableGPSNMEA(uint8_t i) {
/********* GPRS **********************************************************/
-boolean Adafruit_FONA::enableGPRS(boolean onoff) {
+boolean Adafruit_FONA::enableGPRS(boolean onoff, fona_timeout_t timeout) {
if (_type == SIM5320A || _type == SIM5320E || _type == SIM7500A || _type == SIM7500E || _type == SIM7600A || _type == SIM7600C || _type == SIM7600E) {
if (onoff) {
// disconnect all sockets
//sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 5000);
- if (! sendCheckReply(F("AT+CGATT=1"), ok_reply, 10000))
+ if (! sendCheckReply(F("AT+CGATT=1"), ok_reply, timeout))
return false;
// set bearer profile access point name
- if (apn) {
+ if (apn[0]) {
// Send command AT+CGSOCKCONT=1,"IP","<apn value>" where <apn value> is the configured APN name.
if (! sendCheckReplyQuoted(F("AT+CGSOCKCONT=1,\"IP\","), apn, ok_reply, 10000))
return false;
// set username/password
- if (apnusername) {
+ if (apnusername[0]) {
char authstring[100] = "AT+CGAUTH=1,1,\"";
// char authstring[100] = "AT+CSOCKAUTH=1,1,\""; // For 3G
char *strp = authstring + strlen(authstring);
- prog_char_strcpy(strp, (prog_char *)apnusername);
- strp+=prog_char_strlen((prog_char *)apnusername);
+ strcpy(strp, apnusername);
+ strp+=strlen(apnusername);
+ //prog_char_strcpy(strp, (prog_char *)apnusername);
+ //strp+=prog_char_strlen((prog_char *)apnusername);
+
strp[0] = '\"';
strp++;
strp[0] = 0;
- if (apnpassword) {
+ if (apnpassword[0]) {
strp[0] = ','; strp++;
strp[0] = '\"'; strp++;
- prog_char_strcpy(strp, (prog_char *)apnpassword);
- strp+=prog_char_strlen((prog_char *)apnpassword);
+ strcpy(strp, apnpassword);
+ strp+=strlen(apnpassword);
+ //prog_char_strcpy(strp, (prog_char *)apnpassword);
+ //strp+=prog_char_strlen((prog_char *)apnpassword);
strp[0] = '\"';
strp++;
strp[0] = 0;
@@ -1481,9 +1501,9 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) {
if (onoff) {
// if (_type < SIM7000A) { // UNCOMMENT FOR LTE ONLY!
// disconnect all sockets
- sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 20000);
+ sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), timeout);
- if (! sendCheckReply(F("AT+CGATT=1"), ok_reply, 10000))
+ if (! sendCheckReply(F("AT+CGATT=1"), ok_reply, timeout))
return false;
// set bearer profile! connection type GPRS
@@ -1494,7 +1514,7 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) {
delay(200); // This seems to help the next line run the first time
// set bearer profile access point name
- if (apn) {
+ if (apn[0]) {
// Send command AT+SAPBR=3,1,"APN","<apn value>" where <apn value> is the configured APN value.
if (! sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"APN\","), apn, ok_reply, 10000))
return false;
@@ -1505,11 +1525,11 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) {
mySerial->print(F("AT+CSTT=\""));
mySerial->print(apn);
- if (apnusername) {
+ if (apnusername[0]) {
mySerial->print("\",\"");
mySerial->print(apnusername);
}
- if (apnpassword) {
+ if (apnpassword[0]) {
mySerial->print("\",\"");
mySerial->print(apnpassword);
}
@@ -1518,11 +1538,11 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) {
DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(F("AT+CSTT=\""));
DEBUG_PRINT(apn);
- if (apnusername) {
+ if (apnusername[0]) {
DEBUG_PRINT("\",\"");
DEBUG_PRINT(apnusername);
}
- if (apnpassword) {
+ if (apnpassword[0]) {
DEBUG_PRINT("\",\"");
DEBUG_PRINT(apnpassword);
}
@@ -1532,12 +1552,12 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) {
// } // UNCOMMENT FOR LTE ONLY!
// set username/password
- if (apnusername) {
+ if (apnusername[0]) {
// Send command AT+SAPBR=3,1,"USER","<user>" where <user> is the configured APN username.
if (! sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"USER\","), apnusername, ok_reply, 10000))
return false;
}
- if (apnpassword) {
+ if (apnpassword[0]) {
// Send command AT+SAPBR=3,1,"PWD","<password>" where <password> is the configured APN password.
if (! sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"PWD\","), apnpassword, ok_reply, 10000))
return false;
@@ -1585,13 +1605,13 @@ boolean Adafruit_FONA_3G::enableGPRS(boolean onoff) {
// set bearer profile access point name
- if (apn) {
+ if (apn[0]) {
// Send command AT+CGSOCKCONT=1,"IP","<apn value>" where <apn value> is the configured APN name.
if (! sendCheckReplyQuoted(F("AT+CGSOCKCONT=1,\"IP\","), apn, ok_reply, 10000))
return false;
// set username/password
- if (apnusername) {
+ if (apnusername[0]) {
char authstring[100] = "AT+CGAUTH=1,1,\"";
char *strp = authstring + strlen(authstring);
prog_char_strcpy(strp, (prog_char *)apnusername);
@@ -1600,7 +1620,7 @@ boolean Adafruit_FONA_3G::enableGPRS(boolean onoff) {
strp++;
strp[0] = 0;
- if (apnpassword) {
+ if (apnpassword[0]) {
strp[0] = ','; strp++;
strp[0] = '\"'; strp++;
prog_char_strcpy(strp, (prog_char *)apnpassword);
@@ -1650,11 +1670,50 @@ int8_t Adafruit_FONA::GPRSstate(void) {
}
void Adafruit_FONA::setNetworkSettings(FONAFlashStringPtr apn,
- FONAFlashStringPtr username, FONAFlashStringPtr password) {
- this->apn = apn;
- this->apnusername = username;
- this->apnpassword = password;
+ FONAFlashStringPtr username, FONAFlashStringPtr password) {
+ if (apn) {
+ prog_char_strcpy(this->apn, (prog_char *)apn);
+ }
+ else {
+ this->apn[0]='\0';
+ }
+ if (username) {
+ prog_char_strcpy(this->apnusername, (prog_char *)username);
+ }
+ else {
+ this->apnusername[0]='\0';
+ }
+ if (password) {
+ prog_char_strcpy(this->apnpassword, (prog_char *)password);
+ }
+ else {
+ this->apnpassword[0]='\0';
+ }
+
+ if (_type >= SIM7000A) sendCheckReplyQuoted(F("AT+CGDCONT=1,\"IP\","), apn, ok_reply, 10000);
+}
+void Adafruit_FONA::setNetworkSettings(const char *apn,
+ const char *username, const char *password) {
+ if (apn) {
+ strcpy(this->apn, apn);
+ }
+ else {
+ this->apn[0]='\0';
+ }
+ if (username) {
+ strcpy(this->apnusername, username);
+ }
+ else {
+ this->apnusername[0]='\0';
+ }
+ if (password) {
+ strcpy(this->apnpassword, password);
+ }
+ else {
+ this->apnpassword[0]='\0';
+ }
+
if (_type >= SIM7000A) sendCheckReplyQuoted(F("AT+CGDCONT=1,\"IP\","), apn, ok_reply, 10000);
}
@@ -2420,15 +2479,15 @@ boolean Adafruit_FONA::MQTTsubscribe(const char* topic, byte QoS) {
}
boolean Adafruit_FONA::MQTTunsubscribe(const char* topic) {
-
+ return true;
}
boolean Adafruit_FONA::MQTTreceive(const char* topic, const char* buf, int maxlen) {
-
+ return true;
}
boolean Adafruit_FONA::MQTTdisconnect(void) {
-
+ return true;
}
/********* SIM7000 MQTT FUNCTIONS ************************************/
@@ -2436,9 +2495,9 @@ boolean Adafruit_FONA::MQTTdisconnect(void) {
// Parameter tags can be "CLIENTID", "URL", "KEEPTIME", "CLEANSS", "USERNAME",
// "PASSWORD", "QOS", "TOPIC", "MESSAGE", or "RETAIN"
boolean Adafruit_FONA_LTE::MQTT_setParameter(const char* paramTag, const char* paramValue, uint16_t port) {
- char cmdStr[50];
+ char cmdStr[100];
- if (strcmp(paramTag, "CLIENTID") == 0 || strcmp(paramTag, "URL") == 0 || strcmp(paramTag, "TOPIC") == 0 || strcmp(paramTag, "MESSAGE") == 0) {
+ if (strcmp(paramTag, "CLIENTID") == 0 || strcmp(paramTag, "URL") == 0 || strcmp(paramTag, "TOPIC") == 0 || strcmp(paramTag, "MESSAGE") == 0 /*|| strcmp(paramTag, "USERNAME") == 0 || strcmp(paramTag, "PASSWORD") == 0*/) {
if (port == 0) sprintf(cmdStr, "AT+SMCONF=\"%s\",\"%s\"", paramTag, paramValue); // Quoted paramValue
else sprintf(cmdStr, "AT+SMCONF=\"%s\",\"%s\",\"%i\"", paramTag, paramValue, port);
if (! sendCheckReply(cmdStr, ok_reply)) return false;
@@ -2452,8 +2511,8 @@ boolean Adafruit_FONA_LTE::MQTT_setParameter(const char* paramTag, const char* p
}
// Connect or disconnect MQTT
-boolean Adafruit_FONA_LTE::MQTT_connect(bool yesno) {
- if (yesno) return sendCheckReply(F("AT+SMCONN"), ok_reply, 5000);
+boolean Adafruit_FONA_LTE::MQTT_connect(bool yesno, fona_timeout_t timeout) {
+ if (yesno) return sendCheckReply(F("AT+SMCONN"), ok_reply, timeout);
else return sendCheckReply(F("AT+SMDISC"), ok_reply);
}
@@ -2465,19 +2524,19 @@ boolean Adafruit_FONA_LTE::MQTT_connectionStatus(void) {
// Subscribe to specified MQTT topic
// QoS can be from 0-2
-boolean Adafruit_FONA_LTE::MQTT_subscribe(const char* topic, byte QoS) {
- char cmdStr[32];
+boolean Adafruit_FONA_LTE::MQTT_subscribe(const char* topic, byte QoS, fona_timeout_t timeout) {
+ char cmdStr[80];
sprintf(cmdStr, "AT+SMSUB=\"%s\",%i", topic, QoS);
- if (! sendCheckReply(cmdStr, ok_reply)) return false;
+ if (! sendCheckReply(cmdStr, ok_reply, timeout)) return false;
return true;
}
// Unsubscribe from specified MQTT topic
-boolean Adafruit_FONA_LTE::MQTT_unsubscribe(const char* topic) {
- char cmdStr[32];
+boolean Adafruit_FONA_LTE::MQTT_unsubscribe(const char* topic, fona_timeout_t timeout) {
+ char cmdStr[80];
sprintf(cmdStr, "AT+SMUNSUB=\"%s\"", topic);
- if (! sendCheckReply(cmdStr, ok_reply)) return false;
+ if (! sendCheckReply(cmdStr, ok_reply, timeout)) return false;
return true;
}
@@ -2485,21 +2544,47 @@ boolean Adafruit_FONA_LTE::MQTT_unsubscribe(const char* topic) {
// Message length can be from 0-512 bytes
// QoS can be from 0-2
// Server hold message flag can be 0 or 1
-boolean Adafruit_FONA_LTE::MQTT_publish(const char* topic, const char* message, uint16_t contentLength, byte QoS, byte retain) {
- char cmdStr[40];
- sprintf(cmdStr, "AT+SMPUB=\"%s\",%i,%i,%i", topic, contentLength, QoS, retain);
+boolean Adafruit_FONA_LTE::MQTT_publish(const char* topic, const char* message, uint16_t contentLength, byte QoS, byte retain, fona_timeout_t timeout) {
- getReply(cmdStr, 20000);
- if (strstr(replybuffer, ">") == NULL) return false; // Wait for "> " to send message
- if (! sendCheckReply(message, ok_reply, 5000)) return false; // Now send the message
+ // Send the publish command and topic
+ char cmdStr[100];
+ snprintf(cmdStr, sizeof(cmdStr), "AT+SMPUB=\"%s\",%i,%i,%i", topic, contentLength, QoS, retain);
+ flushInput();
+ DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN(cmdStr);
+ mySerial->println(cmdStr);
+
+ // Wait for a '>' prompt in response (possibly without newline!)
+ bool prompted = false;
+ fona_timeout_t prompt_timeout = timeout;
+ while (prompt_timeout--) {
+ if (mySerial->available()) {
+ char c = mySerial->read();
+ if (c=='>') {
+ prompted = true;
+ break;
+ }
+ }
+ else {
+ delay(1);
+ }
+ }
+ if (!prompted){
+ DEBUG_PRINTLN(F("Timeout waiting for prompt"));
+ return false;
+ }
+
+ //getReply(cmdStr, timeout);
+ //if (strstr(replybuffer, ">") == NULL) return false; // Wait for "> " to send message
- return true;
+ // Now send the message
+ return sendCheckReply(message, ok_reply, timeout);
}
// Change MQTT data format to hex
// Enter "true" if you want hex, "false" if you don't
boolean Adafruit_FONA_LTE::MQTT_dataFormatHex(bool yesno) {
if (yesno) sendCheckReply(F("AT+SMPUBHEX="), yesno, ok_reply);
+ return true;
}
/********* SSL FUNCTIONS ************************************/
@@ -2864,7 +2949,7 @@ boolean Adafruit_FONA::HTTP_setup(char *url) {
/********* HELPERS *********************************************/
boolean Adafruit_FONA::expectReply(FONAFlashStringPtr reply,
- uint16_t timeout) {
+ fona_timeout_t timeout) {
readline(timeout);
DEBUG_PRINT(F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
@@ -2896,7 +2981,7 @@ inline void Adafruit_FONA::flush() {
void Adafruit_FONA::flushInput() {
// Read all available serial input to flush pending data.
- uint16_t timeoutloop = 0;
+ fona_timeout_t timeoutloop = 0;
while (timeoutloop++ < 40) {
while(available()) {
read();
@@ -2921,7 +3006,7 @@ uint16_t Adafruit_FONA::readRaw(uint16_t b) {
return idx;
}
-uint8_t Adafruit_FONA::readline(uint16_t timeout, boolean multiline) {
+uint8_t Adafruit_FONA::readline(fona_timeout_t timeout, boolean multiline) {
uint16_t replyidx = 0;
while (timeout--) {
@@ -2931,6 +3016,7 @@ uint8_t Adafruit_FONA::readline(uint16_t timeout, boolean multiline) {
}
while(mySerial->available()) {
+
char c = mySerial->read();
if (c == '\r') continue;
if (c == 0xA) {
@@ -2957,7 +3043,7 @@ uint8_t Adafruit_FONA::readline(uint16_t timeout, boolean multiline) {
return replyidx;
}
-uint8_t Adafruit_FONA::getReply(const char *send, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReply(const char *send, fona_timeout_t timeout) {
flushInput();
@@ -2968,12 +3054,12 @@ uint8_t Adafruit_FONA::getReply(const char *send, uint16_t timeout) {
uint8_t l = readline(timeout);
- DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
+ DEBUG_PRINT(F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
return l;
}
-uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, fona_timeout_t timeout) {
flushInput();
@@ -2984,13 +3070,13 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, uint16_t timeout) {
uint8_t l = readline(timeout);
- DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
+ DEBUG_PRINT(F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
return l;
}
// Send prefix, suffix, and newline. Return response (and also set replybuffer with response).
-uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, fona_timeout_t timeout) {
flushInput();
@@ -3008,7 +3094,7 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, uint16_
}
// Send prefix, suffix, and newline. Return response (and also set replybuffer with response).
-uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, fona_timeout_t timeout) {
flushInput();
@@ -3026,7 +3112,7 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, uint1
}
// Send prefix, suffix, suffix2, and newline. Return response (and also set replybuffer with response).
-uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, fona_timeout_t timeout) {
flushInput();
@@ -3047,7 +3133,7 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, int3
}
// Send prefix, ", suffix, ", and newline. Return response (and also set replybuffer with response).
-uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, fona_timeout_t timeout) {
flushInput();
@@ -3067,7 +3153,25 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashString
return l;
}
-boolean Adafruit_FONA::sendCheckReply(const char *send, const char *reply, uint16_t timeout) {
+uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, const char *suffix, fona_timeout_t timeout) {
+ flushInput();
+
+ DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(prefix);
+ DEBUG_PRINT('"'); DEBUG_PRINT(suffix); DEBUG_PRINTLN('"');
+
+ mySerial->print(prefix);
+ mySerial->print('"');
+ mySerial->print(suffix);
+ mySerial->println('"');
+
+ uint8_t l = readline(timeout);
+
+ DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer);
+
+ return l;
+}
+
+boolean Adafruit_FONA::sendCheckReply(const char *send, const char *reply, fona_timeout_t timeout) {
if (! getReply(send, timeout) )
return false;
/*
@@ -3083,14 +3187,14 @@ boolean Adafruit_FONA::sendCheckReply(const char *send, const char *reply, uint1
return (strcmp(replybuffer, reply) == 0);
}
-boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, uint16_t timeout) {
+boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, fona_timeout_t timeout) {
if (! getReply(send, timeout) )
return false;
return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
}
-boolean Adafruit_FONA::sendCheckReply(const char* send, FONAFlashStringPtr reply, uint16_t timeout) {
+boolean Adafruit_FONA::sendCheckReply(const char* send, FONAFlashStringPtr reply, fona_timeout_t timeout) {
if (! getReply(send, timeout) )
return false;
return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
@@ -3098,29 +3202,33 @@ boolean Adafruit_FONA::sendCheckReply(const char* send, FONAFlashStringPtr reply
// Send prefix, suffix, and newline. Verify FONA response matches reply parameter.
-boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, uint16_t timeout) {
+boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, fona_timeout_t timeout) {
getReply(prefix, suffix, timeout);
return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
}
// Send prefix, suffix, and newline. Verify FONA response matches reply parameter.
-boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, uint16_t timeout) {
+boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, fona_timeout_t timeout) {
getReply(prefix, suffix, timeout);
return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
}
// Send prefix, suffix, suffix2, and newline. Verify FONA response matches reply parameter.
-boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, FONAFlashStringPtr reply, uint16_t timeout) {
+boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, FONAFlashStringPtr reply, fona_timeout_t timeout) {
getReply(prefix, suffix1, suffix2, timeout);
return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
}
// Send prefix, ", suffix, ", and newline. Verify FONA response matches reply parameter.
-boolean Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, uint16_t timeout) {
+boolean Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, fona_timeout_t timeout) {
getReplyQuoted(prefix, suffix, timeout);
return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
}
+boolean Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, const char *suffix, FONAFlashStringPtr reply, fona_timeout_t timeout) {
+ getReplyQuoted(prefix, suffix, timeout);
+ return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0);
+}
boolean Adafruit_FONA::parseReply(FONAFlashStringPtr toreply,
uint16_t *v, char divider, uint8_t index) {
diff --git a/Code/Adafruit_FONA.h b/Code/Adafruit_FONA.h
index 7f727c6..6d745e9 100644
--- a/Code/Adafruit_FONA.h
+++ b/Code/Adafruit_FONA.h
@@ -83,10 +83,16 @@
#define FONA_CALL_RINGING 3
#define FONA_CALL_INPROGRESS 4
+#ifdef ADAFRUIT_FONA_LONG_TIMEOUT
+typedef uint32_t fona_timeout_t;
+#else
+typedef uint16_t fona_timeout_t;
+#endif
+
class Adafruit_FONA : public FONAStreamType {
public:
Adafruit_FONA(int8_t);
- boolean begin(FONAStreamType &port);
+ boolean begin(FONAStreamType &port, fona_timeout_t timeout=10000);
uint8_t type();
// Stream
@@ -157,11 +163,12 @@ class Adafruit_FONA : public FONAStreamType {
boolean readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, uint8_t *min, uint8_t *sec);
// GPRS handling
- boolean enableGPRS(boolean onoff);
+ boolean enableGPRS(boolean onoff, fona_timeout_t timeout=10000);
int8_t GPRSstate(void);
boolean getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen);
boolean getGSMLoc(float *lat, float *lon);
void setNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username=0, FONAFlashStringPtr password=0);
+ void setNetworkSettings(const char *apn, const char *username=NULL, const char *password=NULL);
boolean postData(const char *request_type, const char *URL, const char *body = "", const char *token = "", uint32_t bodylen = 0);
boolean postData(const char *server, uint16_t port, const char *connType, const char *URL, const char *body = "");
void getNetworkInfo(void);
@@ -236,10 +243,10 @@ class Adafruit_FONA : public FONAStreamType {
boolean incomingCallNumber(char* phonenum);
// Helper functions to verify responses.
- boolean expectReply(FONAFlashStringPtr reply, uint16_t timeout = 10000);
- boolean sendCheckReply(const char *send, const char *reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- boolean sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- boolean sendCheckReply(const char* send, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean expectReply(FONAFlashStringPtr reply, fona_timeout_t timeout = 10000);
+ boolean sendCheckReply(const char *send, const char *reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean sendCheckReply(const char* send, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
protected:
@@ -247,9 +254,9 @@ class Adafruit_FONA : public FONAStreamType {
uint8_t _type;
char replybuffer[255];
- FONAFlashStringPtr apn;
- FONAFlashStringPtr apnusername;
- FONAFlashStringPtr apnpassword;
+ char apn[32];
+ char apnusername[32];
+ char apnpassword[32];
boolean httpsredirect;
FONAFlashStringPtr useragent;
FONAFlashStringPtr ok_reply;
@@ -259,18 +266,20 @@ class Adafruit_FONA : public FONAStreamType {
void flushInput();
uint16_t readRaw(uint16_t b);
- uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, boolean multiline = false);
- uint8_t getReply(const char *send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- uint8_t getReply(FONAFlashStringPtr send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- uint8_t getReply(FONAFlashStringPtr prefix, char *suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- uint8_t getReply(FONAFlashStringPtr prefix, int32_t suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- uint8_t getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout); // Don't set default value or else function call is ambiguous.
- uint8_t getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
-
- boolean sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, int32_t suffix2, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
- boolean sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ uint8_t readline(fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS, boolean multiline = false);
+ uint8_t getReply(const char *send, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ uint8_t getReply(FONAFlashStringPtr send, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ uint8_t getReply(FONAFlashStringPtr prefix, char *suffix, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ uint8_t getReply(FONAFlashStringPtr prefix, int32_t suffix, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ uint8_t getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, fona_timeout_t timeout); // Don't set default value or else function call is ambiguous.
+ uint8_t getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ uint8_t getReplyQuoted(FONAFlashStringPtr prefix, const char *suffix, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+
+ boolean sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, int32_t suffix2, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean sendCheckReplyQuoted(FONAFlashStringPtr prefix, const char *suffix, FONAFlashStringPtr reply, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
void mqtt_connect_message(const char *protocol, byte *mqtt_message, const char *client_id, const char *username, const char *password);
void mqtt_publish_message(byte *mqtt_message, const char *topic, const char *message);
@@ -340,11 +349,11 @@ class Adafruit_FONA_LTE : public Adafruit_FONA {
// MQTT
boolean MQTT_setParameter(const char* paramTag, const char* paramValue, uint16_t port = 0);
- boolean MQTT_connect(bool yesno);
+ boolean MQTT_connect(bool yesno, fona_timeout_t timeout=10000);
boolean MQTT_connectionStatus(void);
- boolean MQTT_subscribe(const char* topic, byte QoS);
- boolean MQTT_unsubscribe(const char* topic);
- boolean MQTT_publish(const char* topic, const char* message, uint16_t contentLength, byte QoS, byte retain);
+ boolean MQTT_subscribe(const char* topic, byte QoS, fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean MQTT_unsubscribe(const char* topic,fona_timeout_t timeout = FONA_DEFAULT_TIMEOUT_MS);
+ boolean MQTT_publish(const char* topic, const char* message, uint16_t contentLength, byte QoS, byte retain, fona_timeout_t timeout = 20000);
boolean MQTT_dataFormatHex(bool yesno);
// SSL
diff --git a/Code/includes/FONAConfig.h b/Code/includes/FONAConfig.h
index 5fa3e13..64ede71 100644
--- a/Code/includes/FONAConfig.h
+++ b/Code/includes/FONAConfig.h
@@ -28,7 +28,9 @@
* DebugStream set in the appropriate platform/ header.
*/
-#define ADAFRUIT_FONA_DEBUG
+#undef ADAFRUIT_FONA_DEBUG
+
+#define ADAFRUIT_FONA_LONG_TIMEOUT
#endif /* ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_FONACONFIG_H_ */
diff --git a/Code/library.properties b/Code/library.properties
index 755b529..63285c4 100644
--- a/Code/library.properties
+++ b/Code/library.properties
@@ -1,9 +1,9 @@
-name=Adafruit FONA Library
+name=SIM7000 LTE Shield (forked from Adafruit FONA)
version=1.3.3
-author=Adafruit
-maintainer=Adafruit <[email protected]>
-sentence=Arduino library for the Adafruit FONA
-paragraph=Arduino library for the Adafruit FONA
+author=Various
+maintainer=Unixbigot <[email protected]>
+sentence=Arduino library for the SIM7000
+paragraph=Arduino library for the SIM7000
category=Communication
-url=https://github.com/adafruit/Adafruit_FONA
+url=https://github.com/accelerando-consulting/SIM7000-LTE-Shield
architectures=*
diff --git a/src b/src
new file mode 120000
index 0000000..c28873d
--- /dev/null
+++ b/src
@@ -0,0 +1 @@
+Code
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment