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:
- 2:3fc229f5ec3f
- Parent:
- 1:c0ae7ecfa511
- Child:
- 3:addc5ef76145
--- a/Adafruit_FONA.cpp Sun Aug 05 14:26:22 2018 +0000 +++ b/Adafruit_FONA.cpp Mon Aug 06 05:54:30 2018 +0000 @@ -267,6 +267,7 @@ uint8_t Adafruit_FONA::unlockSIM(char *pin) { + // AT+CPIN=0000 char sendbuff[14] = "AT+CPIN="; sendbuff[8] = pin[0]; sendbuff[9] = pin[1]; @@ -1058,6 +1059,73 @@ /********* TCP FUNCTIONS ************************************/ +uint8_t Adafruit_FONA_3G::TCPinitialize(void) +{ + + // AT+CGDCONT=1,"IP","orange-mib" AT+CGDCONT? + if (! sendCheckReply("AT+CGDCONT=1,\"IP\",\"orange-mib\"", ok_reply, 5000)) return 1; + wait_ms(1000); + if (! sendCheckReply("AT+CGDCONT?", "+CGDCONT: 1,\"IP\",\"orange-mib\",\"0.0.0.0\",0,0", 5000)) return 1; + wait_ms(1000); + + // AT+CREG=1 AT+CREG? + if (! sendCheckReply("AT+CREG=1", ok_reply, 500)) return 2; + wait_ms(1000); + if (! sendCheckReply("AT+CREG?", "+CREG: 1,1", 500)) return 2; + wait_ms(1000); + + /* + // AT+CSOCKSETPN=1 AT+CSOCKSETPN? + if (! sendCheckReply("AT+CSOCKSETPN=1", ok_reply, 5000)) return 3; + wait_ms(1000); + if (! sendCheckReply("AT+CSOCKSETPN?", "+CSOCKSETPN: 1", 5000)) return 3; + wait_ms(1000); + */ + + /* + // AT+CGAUTH=1,2,"orange","orange" AT+CGAUTH? + if (! sendCheckReply("AT+CGAUTH=1,2,\"orange\",\"orange\"", ok_reply, 5000)) return 4; + wait_ms(1000); + if (! sendCheckReply("AT+CGAUTH?", "+CGAUTH: 1,2,\"orange\"", 5000)) return 4; + wait_ms(1000); + */ + + /* + // AT+CSOCKAUTH=1,2,"orange","orange" AT+CSOCKAUTH? + if (! sendCheckReply("AT+CSOCKAUTH=1,2,\"orange\",\"orange\"", ok_reply, 5000)) return 5; + wait_ms(1000); + */ + + // AT+CIPMODE=1 AT+CIPMODE? + if (! sendCheckReply("AT+CIPMODE=1", ok_reply, 5000)) return 6; + wait_ms(1000); + if (! sendCheckReply("AT+CIPMODE?", "+CIPMODE: 1", 5000)) return 6; + wait_ms(1000); + + // ATS0=007 ATS0? + if (! sendCheckReply("ATS0=007", ok_reply, 5000)) return 7; + wait_ms(1000); + if (! sendCheckReply("ATS0?", "007", 5000)) return 7; + wait_ms(1000); + + /* + // AT+CGATT=1 AT+CGATT? + if (! sendCheckReply("AT+CGATT=1", ok_reply, 5000)) return 8; + wait_ms(1000); + */ + + // AT+CGACT=1,1 AT+CGACT? + if (! sendCheckReply("AT+CGACT=1,1", ok_reply, 5000)) return 9; + wait_ms(1000); + if (! sendCheckReply("AT+CGACT?", "+CGACT: 1,1", 5000)) return 9; + wait_ms(1000); + + // AT+NETOPEN? + if (! sendCheckReply("AT+NETOPEN", ok_reply, 5000)) return 10; + wait_ms(1000); + + return 0; +} bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { @@ -1079,7 +1147,34 @@ mySerial.printf("AT+CIPSTART=\"TCP\",\"%s\",\"%d\"\r\n", server, port); if (! expectReply(ok_reply)) return false; + if (! expectReply("CONNECT OK")) return false; + + return true; +} + +bool Adafruit_FONA_3G::TCPconnect(char *server, uint16_t port) +{ + flushInput(); + + // AT+CSOCKSETPN=1 AT+CSOCKSETPN? + if (! sendCheckReply("AT+CSOCKSETPN=1", ok_reply, 5000)) return false; + + if (! sendCheckReply("AT+CIPMODE=1", ok_reply) ) return false; + + if (! sendCheckReply("AT+NETOPEN", ok_reply) ) return false; + +#ifdef ADAFRUIT_FONA_DEBUG + printf("AT+CIPOPEN=0,\"TCP\",\"%s\",%d\r\n", server, port); +#endif + mySerial.printf("AT+CIPOPEN=0,\"TCP\",\"%s\",%d\r\n", server, port); + // AT+CIPOPEN=0,"TCP","217.182.85.123",2323 + + if (! expectReply(ok_reply)) return false; + + if (! expectReply("CONNECT OK")) return false; + + return true; } @@ -1088,6 +1183,11 @@ return sendCheckReply("AT+CIPCLOSE", ok_reply); } +bool Adafruit_FONA_3G::TCPclose(void) +{ + return sendCheckReply("AT+CIPCLOSE=0", ok_reply); +} + bool Adafruit_FONA::TCPconnected(void) { if (! sendCheckReply("AT+CIPSTATUS", ok_reply, 100) ) return false;