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
Diff: Adafruit_FONA.cpp
- Revision:
- 9:b18cfba4283a
- Parent:
- 8:d54fbb976688
- Child:
- 10:7951d9691cb2
--- a/Adafruit_FONA.cpp Sun Oct 07 12:58:46 2018 +0000 +++ b/Adafruit_FONA.cpp Tue Oct 23 19:16:20 2018 +0000 @@ -293,6 +293,27 @@ return sendCheckReply(sendbuff, ok_reply); } +uint8_t Adafruit_FONA_3G::unlockSIM(char *pin) +{ + // AT+CPIN=0000 + char sendbuff[14] = "AT+CPIN="; + sendbuff[8] = pin[0]; + sendbuff[9] = pin[1]; + sendbuff[10] = pin[2]; + sendbuff[11] = pin[3]; + sendbuff[12] = NULL; + + if (! sendCheckReply(sendbuff, ok_reply)) return false; + + if (! expectReply("+CPIN: READY")) return false; + + if (! expectReply("SMS DONE")) return false; + + if (! expectReply("PB DONE")) return false; + + return true; +} + uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { getReply("AT+CCID"); @@ -1013,7 +1034,7 @@ -uint8_t Adafruit_FONA::GPRSstate(void) +int Adafruit_FONA::GPRSstate(void) { uint16_t state; @@ -1118,6 +1139,16 @@ return 0; } +uint8_t Adafruit_FONA_3G::sslTCPinitialize(void) +{ + // start common channel + if (! sendCheckReply("AT+CCHSTART", ok_reply, 3000) ) return 1; + + if (! expectReply("+CCHSTART: 0")) return 2; + + return 0; +} + uint8_t Adafruit_FONA_3G::getTCPtimeout(char *tcptimeout) { getReply("AT+CIPTIMEOUT?"); @@ -1181,11 +1212,6 @@ { flushInput(); - // start common channel - if (! sendCheckReply("AT+CCHSTART", ok_reply, 3000) ) return false; - - wait(5); - #ifdef ADAFRUIT_FONA_DEBUG printf("AT+CCHOPEN=0,\"%s\",%d,2\r\n", server, port); #endif @@ -1194,6 +1220,10 @@ if (! expectReply(ok_reply)) return false; + if (! expectReply("+CCHOPEN: 0,0")) return false; + + if (! expectReply("+CCHRECV: DATA,0,10", 10000)) return false; + return true; } @@ -1281,24 +1311,25 @@ } else return false; } -bool Adafruit_FONA_3G::sslTCPsend(char *packet, uint8_t len) +bool Adafruit_FONA_3G::sslTCPsend(char *packet) { - mySerial.printf("AT+CCHSEND=0,%d\r\n", len); - readline(); + if (strlen(packet) > 0) { + mySerial.printf("AT+CCHSEND=0,%d\r\n", strlen(packet)); + readline(); #ifdef ADAFRUIT_FONA_DEBUG - printf("\t<--- %s\r\n", replybuffer); + printf("\t<--- %s\r\n", replybuffer); #endif - if (replybuffer[0] != '>') return false; + if (replybuffer[0] != '>') return false; - for (uint16_t i=0; i<len; i++) { - mySerial.putc(packet[i]); - } - readline(3000); // wait up to 3 seconds to send the data + for (uint16_t i=0; i<strlen(packet); i++) { + mySerial.putc(packet[i]); + } + packet[0] = 0; #ifdef ADAFRUIT_FONA_DEBUG - printf("\t<--- %s\r\n", replybuffer); + printf("\t<--- %s\r\n", replybuffer); #endif - - return (strcmp(replybuffer, "OK") == 0); + return true; + } else return false; } uint16_t Adafruit_FONA::TCPavailable(void) @@ -1593,7 +1624,7 @@ while(readable()) { char c = getc(); if (c == '\r') continue; - if (c == 0xA) { + if (c == 0x0A) { if (replyidx == 0) // the first 0x0A is ignored continue;