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:
- 3:addc5ef76145
- Parent:
- 2:3fc229f5ec3f
- Child:
- 4:05c32425d2da
--- a/Adafruit_FONA.cpp Mon Aug 06 05:54:30 2018 +0000 +++ b/Adafruit_FONA.cpp Tue Aug 07 14:30:19 2018 +0000 @@ -1062,67 +1062,43 @@ 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+CGDCONT=1,"IP","orange-mib" AT+CGDCONT? N/A + // if (! sendCheckReply("AT+CGDCONT=1,\"IP\",\"orange-mib\"", ok_reply, 5000)) return 1; - /* - // 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+CMMSPROTO=1,"172.16.2.8",8000 N/A + // if (! sendCheckReply("AT+CMMSPROTO=1,\"172.16.2.8\",8000", ok_reply, 5000)) return 2; - /* - // 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+CREG=1 AT+CREG? OK + if (! sendCheckReply("AT+CREG=1", ok_reply, 500)) return 3; - /* - // 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); + // 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; - // 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+CIPMODE=1 AT+CIPMODE? OK + if (! sendCheckReply("AT+CIPMODE=1", ok_reply, 5000)) return 8; + + // ATS0=007 ATS0? OK + if (! sendCheckReply("ATS0=007", ok_reply, 5000)) return 9; - /* - // AT+CGATT=1 AT+CGATT? - if (! sendCheckReply("AT+CGATT=1", ok_reply, 5000)) return 8; - wait_ms(1000); - */ + // AT+CGATT=1 AT+CGATT? N/A + if (! sendCheckReply("AT+CGATT=1", ok_reply, 5000)) return 10; - // 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+CGACT=1,1 AT+CGACT? OK + if (! sendCheckReply("AT+CGACT=1,1", ok_reply, 5000)) return 11; - // AT+NETOPEN? - if (! sendCheckReply("AT+NETOPEN", ok_reply, 5000)) return 10; - wait_ms(1000); + // AT+NETOPEN OK + if (! sendCheckReply("AT+NETOPEN", ok_reply, 5000)) return 12; + + wait_ms(5000); return 0; } @@ -1156,24 +1132,15 @@ 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; - + if (! sendCheckReply("AT+CIPOPEN=0,\"TCP\",\"217.182.85.123\",2323", "CONNECT 4800", 5000)) return false; + + mySerial.printf("12\r\n"); return true; }