Library for the Adafruit FONA. This is a port of the original Arduino library available at: https://github.com/adafruit/Adafruit_FONA_Library . - Modified by Marc PLOUHINEC 27/06/2015 for use in mbed - Modified by lionel VOIRIN 05/08/2018 for use Adafruit FONA 3

Dependents:   Adafruit_FONA_3G_Library_Test

Revision:
1:c0ae7ecfa511
Parent:
0:bf67af6b3913
Child:
2:3fc229f5ec3f
--- a/Adafruit_FONA.cpp	Sun Aug 05 14:06:59 2018 +0000
+++ b/Adafruit_FONA.cpp	Sun Aug 05 14:26:22 2018 +0000
@@ -230,9 +230,9 @@
 
 bool Adafruit_FONA::enableRTC(uint8_t i)
 {
-    if (! sendCheckReply("AT+CLTS=", i, "OK"))
+    if (! sendCheckReply("AT+CLTS=", i, ok_reply))
         return false;
-    return sendCheckReply("AT&W", "OK");
+    return sendCheckReply("AT&W", ok_reply);
 }
 
 /********* BATTERY & ADC ********************************************/
@@ -338,7 +338,7 @@
     // 0 is headset, 1 is external audio
     if (a > 1) return false;
 
-    return sendCheckReply("AT+CHFA=", a, "OK");
+    return sendCheckReply("AT+CHFA=", a, ok_reply);
 }
 
 uint8_t Adafruit_FONA::getVolume(void)
@@ -352,7 +352,7 @@
 
 bool Adafruit_FONA::setVolume(uint8_t i)
 {
-    return sendCheckReply("AT+CLVL=", i, "OK");
+    return sendCheckReply("AT+CLVL=", i, ok_reply);
 }
 
 
@@ -363,12 +363,12 @@
     str[1] = dtmf;
     str[2] = '\"';
     str[3] = 0;
-    return sendCheckReply("AT+CLDTMF=3,", str, "OK");
+    return sendCheckReply("AT+CLDTMF=3,", str, ok_reply);
 }
 
 bool Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len)
 {
-    return sendCheckReply("AT+STTONE=1,", t, len, "OK");
+    return sendCheckReply("AT+STTONE=1,", t, len, ok_reply);
 }
 
 bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level)
@@ -376,7 +376,7 @@
     // 0 is headset, 1 is external audio
     if (a > 1) return false;
 
-    return sendCheckReply("AT+CMIC=", a, level, "OK");
+    return sendCheckReply("AT+CMIC=", a, level, ok_reply);
 }
 
 /********* FM RADIO *******************************************************/
@@ -385,13 +385,13 @@
 bool Adafruit_FONA::FMradio(bool onoff, uint8_t a)
 {
     if (! onoff) {
-        return sendCheckReply("AT+FMCLOSE", "OK");
+        return sendCheckReply("AT+FMCLOSE", ok_reply);
     }
 
     // 0 is headset, 1 is external audio
     if (a > 1) return false;
 
-    return sendCheckReply("AT+FMOPEN=", a, "OK");
+    return sendCheckReply("AT+FMOPEN=", a, ok_reply);
 }
 
 bool Adafruit_FONA::tuneFMradio(uint16_t station)
@@ -400,7 +400,7 @@
     if ((station < 870) || (station > 1090))
         return false;
 
-    return sendCheckReply("AT+FMFREQ=", station, "OK");
+    return sendCheckReply("AT+FMFREQ=", station, ok_reply);
 }
 
 bool Adafruit_FONA::setFMVolume(uint8_t i)
@@ -410,7 +410,7 @@
         return false;
     }
     // Send FM volume command and verify response.
-    return sendCheckReply("AT+FMVOLUME=", i, "OK");
+    return sendCheckReply("AT+FMVOLUME=", i, ok_reply);
 }
 
 int8_t Adafruit_FONA::getFMVolume()
@@ -453,7 +453,7 @@
     if (period > 2000) return false;
     if (duty > 100) return false;
 
-    return sendCheckReply("AT+SPWM=0,", period, duty, "OK");
+    return sendCheckReply("AT+SPWM=0,", period, duty, ok_reply);
 }
 
 /********* CALL PHONES **************************************************/
@@ -535,14 +535,14 @@
 
 bool Adafruit_FONA::setSMSInterrupt(uint8_t i)
 {
-    return sendCheckReply("AT+CFGRI=", i, "OK");
+    return sendCheckReply("AT+CFGRI=", i, ok_reply);
 }
 
 int8_t Adafruit_FONA::getNumSMS(void)
 {
     uint16_t numsms;
 
-    if (! sendCheckReply("AT+CMGF=1", "OK")) return -1;
+    if (! sendCheckReply("AT+CMGF=1", ok_reply)) return -1;
     // ask how many sms are stored
 
     if (! sendParseReply("AT+CPMS?", "+CPMS: \"SM_P\",", &numsms) ) return -1;
@@ -555,10 +555,10 @@
 bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, uint16_t *readlen)
 {
     // text mode
-    if (! sendCheckReply("AT+CMGF=1", "OK")) return false;
+    if (! sendCheckReply("AT+CMGF=1", ok_reply)) return false;
 
     // show all text mode parameters
-    if (! sendCheckReply("AT+CSDH=1", "OK")) return false;
+    if (! sendCheckReply("AT+CSDH=1", ok_reply)) return false;
 
     // parse out the SMS len
     uint16_t thesmslen = 0;
@@ -596,8 +596,8 @@
 bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen)
 {
     // Ensure text mode and all text mode parameters are sent.
-    if (! sendCheckReply("AT+CMGF=1", "OK")) return false;
-    if (! sendCheckReply("AT+CSDH=1", "OK")) return false;
+    if (! sendCheckReply("AT+CMGF=1", ok_reply)) return false;
+    if (! sendCheckReply("AT+CSDH=1", ok_reply)) return false;
     // Send command to retrieve SMS message and parse a line of response.
     mySerial.printf("AT+CMGR=%d\r\n", i);
     readline(1000);
@@ -610,7 +610,7 @@
 
 bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg)
 {
-    if (! sendCheckReply("AT+CMGF=1", "OK")) return -1;
+    if (! sendCheckReply("AT+CMGF=1", ok_reply)) return -1;
 
     char sendcmd[30] = "AT+CMGS=\"";
     strncpy(sendcmd+9, smsaddr, 30-9-2);  // 9 bytes beginning, 2 bytes for close quote + null
@@ -633,7 +633,7 @@
     readline(1000); // read OK
     //Serial.print("* "); Serial.println(replybuffer);
 
-    if (strcmp(replybuffer, "OK") != 0) {
+    if (strcmp(replybuffer, ok_reply) != 0) {
         return false;
     }
 
@@ -643,7 +643,7 @@
 
 bool Adafruit_FONA::deleteSMS(uint8_t i)
 {
-    if (! sendCheckReply("AT+CMGF=1", "OK")) return -1;
+    if (! sendCheckReply("AT+CMGF=1", ok_reply)) return -1;
     // read an sms
     char sendbuff[12] = "AT+CMGD=000";
     sendbuff[8] = (i / 100) + '0';
@@ -652,7 +652,7 @@
     i %= 10;
     sendbuff[10] = i + '0';
 
-    return sendCheckReply(sendbuff, "OK", 2000);
+    return sendCheckReply(sendbuff, ok_reply, 2000);
 }
 
 /********* TIME **********************************************************/
@@ -660,10 +660,10 @@
 bool Adafruit_FONA::enableNetworkTimeSync(bool onoff)
 {
     if (onoff) {
-        if (! sendCheckReply("AT+CLTS=1", "OK"))
+        if (! sendCheckReply("AT+CLTS=1", ok_reply))
             return false;
     } else {
-        if (! sendCheckReply("AT+CLTS=0", "OK"))
+        if (! sendCheckReply("AT+CLTS=0", ok_reply))
             return false;
     }
 
@@ -675,7 +675,7 @@
 bool Adafruit_FONA::enableNTPTimeSync(bool onoff, const char* ntpserver)
 {
     if (onoff) {
-        if (! sendCheckReply("AT+CNTPCID=1", "OK"))
+        if (! sendCheckReply("AT+CNTPCID=1", ok_reply))
             return false;
 
         mySerial.printf("AT+CNTP=\"");
@@ -686,10 +686,10 @@
         }
         mySerial.printf("\",0\r\n");
         readline(FONA_DEFAULT_TIMEOUT_MS);
-        if (strcmp(replybuffer, "OK") != 0)
+        if (strcmp(replybuffer, ok_reply) != 0)
             return false;
 
-        if (! sendCheckReply("AT+CNTP", "OK", 10000))
+        if (! sendCheckReply("AT+CNTP", ok_reply, 10000))
             return false;
 
         uint16_t status;
@@ -697,7 +697,7 @@
         if (! parseReply("+CNTP:", &status))
             return false;
     } else {
-        if (! sendCheckReply("AT+CNTPCID=0", "OK"))
+        if (! sendCheckReply("AT+CNTPCID=0", ok_reply))
             return false;
     }
 
@@ -732,10 +732,10 @@
         return false;
 
     if (onoff && !state) {
-        if (! sendCheckReply("AT+CGPSPWR=1", "OK"))
+        if (! sendCheckReply("AT+CGPSPWR=1", ok_reply))
             return false;
     } else if (!onoff && state) {
-        if (! sendCheckReply("AT+CGPSPWR=0", "OK"))
+        if (! sendCheckReply("AT+CGPSPWR=0", ok_reply))
             return false;
     }
     return true;
@@ -938,7 +938,7 @@
     i %= 10;
     sendbuff[13] = i + '0';
 
-    return sendCheckReply(sendbuff, "OK", 2000);
+    return sendCheckReply(sendbuff, ok_reply, 2000);
 }
 
 
@@ -951,34 +951,34 @@
         // disconnect all sockets
         sendCheckReply("AT+CIPSHUT", "SHUT OK", 5000);
 
-        if (! sendCheckReply("AT+CGATT=1", "OK", 10000))
+        if (! sendCheckReply("AT+CGATT=1", ok_reply, 10000))
             return false;
 
         // set bearer profile! connection type GPRS
-        if (! sendCheckReply("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"", "OK", 10000))
+        if (! sendCheckReply("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"", ok_reply, 10000))
             return false;
 
         // set bearer profile access point name
         if (apn) {
             // Send command AT+SAPBR=3,1,"APN","<apn value>" where <apn value> is the configured APN value.
-            if (! sendCheckReplyQuoted("AT+SAPBR=3,1,\"APN\",", apn, "OK", 10000))
+            if (! sendCheckReplyQuoted("AT+SAPBR=3,1,\"APN\",", apn, ok_reply, 10000))
                 return false;
 
             // set username/password
             if (apnusername) {
                 // Send command AT+SAPBR=3,1,"USER","<user>" where <user> is the configured APN username.
-                if (! sendCheckReplyQuoted("AT+SAPBR=3,1,\"USER\",", apnusername, "OK", 10000))
+                if (! sendCheckReplyQuoted("AT+SAPBR=3,1,\"USER\",", apnusername, ok_reply, 10000))
                     return false;
             }
             if (apnpassword) {
                 // Send command AT+SAPBR=3,1,"PWD","<password>" where <password> is the configured APN password.
-                if (! sendCheckReplyQuoted("AT+SAPBR=3,1,\"PWD\",", apnpassword, "OK", 10000))
+                if (! sendCheckReplyQuoted("AT+SAPBR=3,1,\"PWD\",", apnpassword, ok_reply, 10000))
                     return false;
             }
         }
 
         // open GPRS context
-        if (! sendCheckReply("AT+SAPBR=1,1", "OK", 10000))
+        if (! sendCheckReply("AT+SAPBR=1,1", ok_reply, 10000))
             return false;
     } else {
         // disconnect all sockets
@@ -986,10 +986,10 @@
             return false;
 
         // close GPRS context
-        if (! sendCheckReply("AT+SAPBR=0,1", "OK", 10000))
+        if (! sendCheckReply("AT+SAPBR=0,1", ok_reply, 10000))
             return false;
 
-        if (! sendCheckReply("AT+CGATT=0", "OK", 10000))
+        if (! sendCheckReply("AT+CGATT=0", ok_reply, 10000))
             return false;
     }
     return true;
@@ -1067,10 +1067,10 @@
     if (! sendCheckReply("AT+CIPSHUT", "SHUT OK", 5000) ) return false;
 
     // single connection at a time
-    if (! sendCheckReply("AT+CIPMUX=0", "OK") ) return false;
+    if (! sendCheckReply("AT+CIPMUX=0", ok_reply) ) return false;
 
     // manually read data
-    if (! sendCheckReply("AT+CIPRXGET=1", "OK") ) return false;
+    if (! sendCheckReply("AT+CIPRXGET=1", ok_reply) ) return false;
 
 #ifdef ADAFRUIT_FONA_DEBUG
     printf("AT+CIPSTART=\"TCP\",\"%s\",\"%d\"\r\n", server, port);
@@ -1078,19 +1078,19 @@
 
     mySerial.printf("AT+CIPSTART=\"TCP\",\"%s\",\"%d\"\r\n", server, port);
 
-    if (! expectReply("OK")) return false;
+    if (! expectReply(ok_reply)) return false;
     if (! expectReply("CONNECT OK")) return false;
     return true;
 }
 
 bool Adafruit_FONA::TCPclose(void)
 {
-    return sendCheckReply("AT+CIPCLOSE", "OK");
+    return sendCheckReply("AT+CIPCLOSE", ok_reply);
 }
 
 bool Adafruit_FONA::TCPconnected(void)
 {
-    if (! sendCheckReply("AT+CIPSTATUS", "OK", 100) ) return false;
+    if (! sendCheckReply("AT+CIPSTATUS", ok_reply, 100) ) return false;
     readline(100);
 #ifdef ADAFRUIT_FONA_DEBUG
     printf("\t<--- %s\r\n", replybuffer);
@@ -1169,12 +1169,12 @@
 
 bool Adafruit_FONA::HTTP_init()
 {
-    return sendCheckReply("AT+HTTPINIT", "OK");
+    return sendCheckReply("AT+HTTPINIT", ok_reply);
 }
 
 bool Adafruit_FONA::HTTP_term()
 {
-    return sendCheckReply("AT+HTTPTERM", "OK");
+    return sendCheckReply("AT+HTTPTERM", ok_reply);
 }
 
 void Adafruit_FONA::HTTP_para_start(const char* parameter, bool quoted)
@@ -1199,7 +1199,7 @@
     else
         mySerial.printf("\r\n");
 
-    return expectReply("OK");
+    return expectReply(ok_reply);
 }
 
 bool Adafruit_FONA::HTTP_para(const char* parameter, const char* value)
@@ -1232,7 +1232,7 @@
 bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout)
 {
     // Send request.
-    if (! sendCheckReply("AT+HTTPACTION=", method, "OK"))
+    if (! sendCheckReply("AT+HTTPACTION=", method, ok_reply))
         return false;
 
     // Parse response status and size.
@@ -1256,7 +1256,7 @@
 
 bool Adafruit_FONA::HTTP_ssl(bool onoff)
 {
-    return sendCheckReply("AT+HTTPSSL=", onoff ? 1 : 0, "OK");
+    return sendCheckReply("AT+HTTPSSL=", onoff ? 1 : 0, ok_reply);
 }
 
 /********* HTTP HIGH LEVEL FUNCTIONS ***************************/
@@ -1302,7 +1302,7 @@
     for (uint16_t i = 0; i < postdatalen; i++) {
         mySerial.putc(postdata[i]);
     }
-    if (! expectReply("OK"))
+    if (! expectReply(ok_reply))
         return false;
 
     // HTTP POST