From 4b736d8cc9a2d7cfbd7418f39bb4840c451146c3 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 22:17:37 -0400 Subject: [PATCH] Fixed xbee wifi perpetual instant timeout --- src/TinyGsmClientXBee.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 4f72afc..086c88b 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -126,24 +126,29 @@ public: // 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 (using Digi default of 10 seconds) + 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 change the TM (socket + + // For cellular models, per documentation: If you write the TM (socket // timeout) value while in Transparent Mode, the current connection is - // immediately closed. - at->sendAT(GF("TM")); // Get socket timeout - String timeoutUsed = at->readResponseString(5000L); + // 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 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() @@ -1138,7 +1143,6 @@ public: // we force close so it can reopen case 0x21 : case 0x27 : { - Serial.println("Here!"); sendAT(GF("TM")); // Get socket timeout String timeoutUsed = readResponseString(5000L); sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout