From 93690952d36125bc7de85a5a3ad369b11a67f445 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 1 Aug 2019 12:52:01 -0400 Subject: [PATCH] Touchup on 5360 --- library.json | 2 +- library.properties | 2 +- src/TinyGsmClient.h | 4 +- src/TinyGsmClientSIM5360.h | 76 ++++++++++++++++++++------------------ src/TinyGsmCommon.h | 2 +- 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/library.json b/library.json index 17f573d..1dd9926 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.5", + "version": "0.9.6", "description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.", "keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M", "authors": diff --git a/library.properties b/library.properties index fe147e9..8f9275b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.5 +version=0.9.6 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClient.h b/src/TinyGsmClient.h index 78eb27b..02f9910 100644 --- a/src/TinyGsmClient.h +++ b/src/TinyGsmClient.h @@ -40,7 +40,9 @@ typedef TinyGsmSim7000::GsmClient TinyGsmClient; // typedef TinyGsmSim7000::GsmClientSecure TinyGsmClientSecure; TODO! -#elif defined(TINY_GSM_MODEM_SIM5360) || defined(TINY_GSM_MODEM_SIM5320) +#elif defined(TINY_GSM_MODEM_SIM5320) || defined(TINY_GSM_MODEM_SIM5360) || \ + defined(TINY_GSM_MODEM_SIM5300) || defined(TINY_GSM_MODEM_SIM7100) || \ + defined(TINY_GSM_MODEM_SIM7500) || defined(TINY_GSM_MODEM_SIM7600) #define TINY_GSM_MODEM_HAS_GPRS #include typedef TinyGsmSim5360 TinyGsm; diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 30cf2c5..41da9b8 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -316,49 +316,46 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() // Define the PDP context - // Using CGDCONT sets up an "external" PCP context, i.e. a data connection - // using the external IP stack (e.g. Windows dial up) and PPP link over the - // serial interface. Is this preferred? + // The CGDCONT commands set up the "external" PDP context - // Set the authentication + // Set the external authentication if (user && strlen(user) > 0) { sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); waitResponse(); } // Define PDP context 1 - sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); + sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"',",\"0.0.0.0\",0,0"); waitResponse(); - sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1 - if (waitResponse(75000L) != 1) { - return false; - } - - // Using CGSOCKCONT commands defines a PDP context for Embedded TCP/IP application - // CGDCONT commands could be used for an external PDP context + // The CGSOCKCONT commands define the "embedded" PDP context for TCP/IP - // ?? Unsure if this step is needed - redundant with +CGDCONT + // Define the socket PDP context sendAT(GF("+CGSOCKCONT=1,\"IP\",\""), apn, '"'); waitResponse(); - // Set the user name and password - // ?? Unsure if this step is needed - redundant with +CGAUTH + // Set the embedded authentication if (user && strlen(user) > 0) { sendAT(GF("+CSOCKAUTH=1,1,\""), user, "\",\"", pwd, '"'); waitResponse(); } // Set active PDP context’s profile number - // ?? Unsure if this step is needed - redundant with +CGAUTH + // This ties the embedded TCP/IP application to the external PDP context sendAT(GF("+CSOCKSETPN=1")); waitResponse(); + // Configure TCP parameters + + // Select TCP/IP application mode (command mode) + sendAT(GF("+CIPMODE=0")); + waitResponse(); + // Set Sending Mode - send without waiting for peer TCP ACK sendAT(GF("+CIPSENDMODE=0")); waitResponse(); - // Configure TCP parameters + // Configure socket parameters //AT+CIPCCFG= [][,[][,[][,[][,]][,[[][,[]]]]]]]] // NmRetry = number of retransmission to be made for an IP packet = 10 (default) // DelayTm = number of milliseconds to delay to output data of Receiving = 0 (default) @@ -372,23 +369,16 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - // Select TCP/IP application mode (command mode) - sendAT(GF("+CIPMODE=0")); - waitResponse(); - - // Configure timeouts for open and close socket + // Configure timeouts for opening and closing sockets // AT+CIPTIMEOUT=[][, [][, []]] sendAT(GF("+CIPTIMEOUT="), 75000, ',', 15000, ',', 15000); waitResponse(); - // attach to GPRS - sendAT(GF("+CGATT=1")); - if (waitResponse(360000L) != 1) { - return false; - } - // Start the socket service - // Response may be an immediate "OK" followed later by "+NETOPEN: 1". + + // This activates and attaches to the external PDP context that is tied + // to the embedded context for TCP/IP (ie AT+CGACT=1,1 and AT+CGATT=1) + // Response may be an immediate "OK" followed later by "+NETOPEN: 0". // We to ignore any immediate response and wait for the // URC to show it's really connected. sendAT(GF("+NETOPEN")); @@ -415,12 +405,14 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 1 + // Deactivate PDP context 1 + sendAT(GF("+CGACT=1,0")); if (waitResponse(40000L) != 1) { return false; } - sendAT(GF("+CGATT=0")); // detach from GPRS + // Detach from GPRS + sendAT(GF("+CGATT=0")); if (waitResponse(360000L) != 1) { return false; } @@ -438,8 +430,9 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() sendAT(GF("+IPADDR")); // Inquire Socket PDP address // sendAT(GF("+CGPADDR=1")); // Show PDP address - if (waitResponse() != 1) + if (waitResponse() != 1) { return false; + } return true; } @@ -624,6 +617,10 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() } float getTemperature() TINY_GSM_ATTR_NOT_AVAILABLE; + // ToDo: + // # Enable Temparature Reading: + //AT+CMTE=1 + //AT+CMTE? /* * Client related functions @@ -639,9 +636,9 @@ protected: return false; } - // Establish connection in multi-socket mode + // Establish a connection in multi-socket mode sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); - // reply is +CIPOPEN: ## of socket created + // The reply is +CIPOPEN: ## of socket created if (waitResponse(15000L, GF(GSM_NL "+CIPOPEN:")) != 1) { return false; } @@ -696,6 +693,7 @@ protected: #endif sockets[mux]->rx.put(c); } + DBG("### READ:", len_requested, "from", mux); // sockets[mux]->sock_available = modemGetAvailable(mux); sockets[mux]->sock_available = len_confirmed; @@ -722,7 +720,7 @@ protected: bool modemGetConnected(uint8_t mux) { // Read the status of all sockets at once sendAT(GF("+CIPCLOSE?"), mux); - if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+CIPCLOSE: ")) != 2) + if (waitResponse(GFP(GSM_OK), GF("+CIPCLOSE: ")) != 2) return false; for (int muxNo = 0; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) { // +CIPCLOSE:,,..., @@ -805,6 +803,14 @@ TINY_GSM_MODEM_STREAM_UTILITIES() } data = ""; DBG("### Closed: ", mux); + } else if (data.endsWith(GF("+CIPEVENT:"))) { + // Need to close all open sockets and release the network library. + // User will then need to reconnect. + DBG("### Network error!"); + if (!isGprsConnected()) { + gprsDisconnect(); + } + data = ""; } } } while (millis() - startMillis < timeout_ms); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 879b473..c0ec41d 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -10,7 +10,7 @@ #define TinyGsmCommon_h // The current library version number -#define TINYGSM_VERSION "0.9.5" +#define TINYGSM_VERSION "0.9.6" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h"