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:
- 4:05c32425d2da
- Parent:
- 3:addc5ef76145
- Child:
- 5:79e4c91f2b73
--- a/Adafruit_FONA.cpp Tue Aug 07 14:30:19 2018 +0000 +++ b/Adafruit_FONA.cpp Sat Aug 11 09:44:50 2018 +0000 @@ -184,6 +184,7 @@ return !isRxBufferEmpty(); } + void Adafruit_FONA::onSerialDataReceived() { while (mySerial.readable() && !isRxBufferFull()) { @@ -1073,13 +1074,13 @@ // AT+CGSOCKCONT=1,"IP","orange-mib" N/A // if (! sendCheckReply("AT+CGSOCKCONT=1,\"IP\",\"orange-mib\"", ok_reply, 5000)) return 4; - + // AT+CSOCKSETPN=1 AT+CSOCKSETPN? N/A if (! sendCheckReply("AT+CSOCKSETPN=1", ok_reply, 5000)) return 5; - + // AT+CGAUTH=1,2,"orange","orange" AT+CGAUTH? N/A // if (! sendCheckReply("AT+CGAUTH=1,2,\"orange\",\"orange\"", ok_reply, 5000)) return 6; - + // AT+CSOCKAUTH=1,2,"orange","orange" AT+CSOCKAUTH? N/A // if (! sendCheckReply("AT+CSOCKAUTH=1,2,\"orange\",\"orange\"", ok_reply, 5000)) return 7; @@ -1097,12 +1098,30 @@ // AT+NETOPEN OK if (! sendCheckReply("AT+NETOPEN", ok_reply, 5000)) return 12; - + wait_ms(5000); return 0; } +uint8_t Adafruit_FONA_3G::getTCPtimeout(char *tcptimeout) +{ + getReply("AT+CIPTIMEOUT?"); + // up to 28 chars for reply, 20 char total tcptimeout + if (replybuffer[0] == '+') { + // fona 3g? + strncpy(tcptimeout, replybuffer+12, 20); + } else { + // fona 800 or 800 + strncpy(tcptimeout, replybuffer, 20); + } + tcptimeout[20] = 0; + + readline(); // eat 'OK' + + return strlen(tcptimeout); +} + bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { flushInput(); @@ -1132,19 +1151,35 @@ bool Adafruit_FONA_3G::TCPconnect(char *server, uint16_t port) { flushInput(); - + #ifdef ADAFRUIT_FONA_DEBUG printf("AT+CIPOPEN=0,\"TCP\",\"%s\",%d\r\n", server, port); #endif - + // AT+CIPOPEN=0,"TCP","217.182.85.123",2323 if (! sendCheckReply("AT+CIPOPEN=0,\"TCP\",\"217.182.85.123\",2323", "CONNECT 4800", 5000)) return false; - - mySerial.printf("12\r\n"); return true; } +uint8_t Adafruit_FONA::getIPADDR(char *ipaddr) +{ + getReply("AT+IPADDR"); + // up to 28 chars for reply, 20 char total ipaddr + if (replybuffer[0] == '+') { + // fona 3g? + strncpy(ipaddr, replybuffer+8, 20); + } else { + // fona 800 or 800 + strncpy(ipaddr, replybuffer, 20); + } + ipaddr[20] = 0; + + readline(); // eat 'OK' + + return strlen(ipaddr); +} + bool Adafruit_FONA::TCPclose(void) { return sendCheckReply("AT+CIPCLOSE", ok_reply); @@ -1195,6 +1230,13 @@ return (strcmp(replybuffer, "SEND OK") == 0); } +bool Adafruit_FONA_3G::TCPsend(char *packet) +{ + mySerial.printf("%s\r\n", packet); + readline(); + return true; +} + uint16_t Adafruit_FONA::TCPavailable(void) { uint16_t avail;