From 97edce96bdf1e57630d5444cfe5bb6a2f13ccc46 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 23:05:12 -0400 Subject: [PATCH] Try again to get stop right --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientXBee.h | 57 ++++++++++++++++++++++----------------- src/TinyGsmCommon.h | 2 +- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index e1e354e..4e7fe68 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index 8108dc8..3a32dcb 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.15", + "version": "0.9.16", "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 dcf23a2..cca0b2a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.15 +version=0.9.16 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 086c88b..320e5e2 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -124,31 +124,10 @@ public: virtual void stop(uint32_t maxWaitMs) { at->streamClear(); // Empty anything in the buffer // empty the saved currently-in-use destination address - at->savedOperatingIP = IPAddress(0, 0, 0, 0); - at->commandMode(); - - // Get the current socket timeout - at->sendAT(GF("TM")); - String timeoutUsed = at->readResponseString(5000L); - - // For WiFi models, there's no direct way to close the socket. This is a - // hack to shut the socket by setting the timeout to zero. - if (at->beeType == XBEE_S6B_WIFI) { - at->sendAT(GF("TM0")); // Set socket timeout to 0 - at->waitResponse(maxWaitMs); // This response can be slow - at->writeChanges(); - } - - // For cellular models, per documentation: If you write the TM (socket - // timeout) value while in Transparent Mode, the current connection is - // immediately closed - this works even if the TM values is unchanged - at->sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout - at->waitResponse(maxWaitMs); // This response can be slow - at->writeChanges(); - at->exitCommand(); - at->streamClear(); // Empty anything remaining in the buffer + at->modemStop(maxWaitMs); + at->streamClear(); // Empty anything in the buffer sock_connected = false; - + // Note: because settings are saved in flash, the XBEE will attempt to // reconnect to the previous socket if it receives any outgoing data. // Setting sock_connected to false after the stop ensures that connected() @@ -1016,6 +995,36 @@ public: return success; } + bool modemStop(uint32_t maxWaitMs) { + streamClear(); // Empty anything in the buffer + // empty the saved currently-in-use destination address + savedOperatingIP = IPAddress(0, 0, 0, 0); + + XBEE_COMMAND_START_DECORATOR(5, false) + + // Get the current socket timeout + sendAT(GF("TM")); + String timeoutUsed = readResponseString(5000L); + + // For WiFi models, there's no direct way to close the socket. This is a + // hack to shut the socket by setting the timeout to zero. + if (beeType == XBEE_S6B_WIFI) { + sendAT(GF("TM0")); // Set socket timeout to 0 + waitResponse(maxWaitMs); // This response can be slow + writeChanges(); + } + + // For cellular models, per documentation: If you write the TM (socket + // timeout) value while in Transparent Mode, the current connection is + // immediately closed - this works even if the TM values is unchanged + sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout + waitResponse(maxWaitMs); // This response can be slow + writeChanges(); + + XBEE_COMMAND_END_DECORATOR + return true; + } + int16_t modemSend(const void* buff, size_t len, uint8_t mux = 0) { if (mux != 0) { DBG("XBee only supports 1 IP channel in transparent mode!"); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 3e476f8..9eac502 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.15" +#define TINYGSM_VERSION "0.9.16" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h"