diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 836cca05..f488961c 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -589,6 +589,10 @@ class TinyGsmXBee : public TinyGsmModem, bool powerOffImpl() { // NOTE: Not supported for WiFi or older cellular firmware + //Per Digi Xbee3 Shutdown Guide PCN_200305 + DBG(GF("powerOffImpl")); + savedIP = IPAddress(0, 0, 0, 0); //Force to set hw + XBEE_COMMAND_START_DECORATOR(5, false) sendAT(GF("SD")); bool ret_val = waitResponse(TGWRIDH+0x08,120000L) == 1; @@ -602,6 +606,9 @@ class TinyGsmXBee : public TinyGsmModem, bool radioOffImpl() { bool success = true; bool changesMade = false; + DBG(GF("radioOffImpl")); + savedIP = IPAddress(0, 0, 0, 0); //Force to set hw + XBEE_COMMAND_START_DECORATOR(5, false) changesMade = changeSettingIfNeeded(GF("AM"), 0x1, 5000L); if (changesMade) { success = applyChanges(); } @@ -903,6 +910,18 @@ class TinyGsmXBee : public TinyGsmModem, bool gprsDisconnectImpl() { bool success = true; + DBG("gprsDisconnectImpl",beeType); //njh + /* NJH Future if PSM implemented + switch (beeType) { + case XBEE_LTE1_VZN: + case XBEE3_LTE1_ATT: + case XBEE3_LTEM_ATT: + //for LTE - no action or SD ~ powerOffImpl() + // powerOffImpl(); + break; + default: { + */ + savedIP = IPAddress(0, 0, 0, 0); //Force to set hw XBEE_COMMAND_START_DECORATOR(5, false) // Cheating and disconnecting by turning on airplane mode bool changesMade = changeSettingIfNeeded(GF("AM"), 0x1, 5000L); @@ -1117,6 +1136,7 @@ class TinyGsmXBee : public TinyGsmModem, bool ssl = false, int timeout_s = 75) { bool retVal = false; XBEE_COMMAND_START_DECORATOR(5, false) + DBG("modemConnect1 :",host,port); // If this is a new host name, replace the saved host and wipe out the saved // host IP @@ -1142,11 +1162,12 @@ class TinyGsmXBee : public TinyGsmModem, return retVal; } + /* Ensure the hardware is set to destination */ bool modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0, bool ssl = false) { bool success = true; bool changesMade = false; - + DBG("modemConnect2 :",ip,port); if (mux != 0) { DBG("XBee only supports 1 IP channel in transparent mode!"); } @@ -1179,7 +1200,7 @@ class TinyGsmXBee : public TinyGsmModem, bool changesMadeSSL=changesMade; changesMade |= changeSettingIfNeeded( - GF("DL"), String(host)); // Set the "Destination Address Low" + GF("DL"), String(host)); // Set the "Destination Address" changesMade |= changeSettingIfNeeded( GF("DE"), String(port, HEX)); // Set the destination port @@ -1190,6 +1211,9 @@ class TinyGsmXBee : public TinyGsmModem, if (changesMade) { success &= applyChanges(); } } + else { + DBG(GF("modemConnect2 cache good:"),savedIP ); + } // confirm the XBee type if needed so we know if we can know if connected if (XBEE_UNKNOWN == beeType ) { @@ -1237,7 +1261,7 @@ class TinyGsmXBee : public TinyGsmModem, 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!"); + DBG(GF("XBee only supports 1 IP channel in transparent mode!")); } stream.write(reinterpret_cast(buff), len); stream.flush(); @@ -1261,8 +1285,9 @@ class TinyGsmXBee : public TinyGsmModem, // really be open, but no data has yet been sent. We return this unknown // value as true so there's a possibility it's wrong. bool modemGetConnected(uint8_t) { + DBG(GF("modemGetConnected")); // If the IP address is 0, it's not valid so we can't be connected - if (savedIP == IPAddress(0, 0, 0, 0)) { return false; } + if (savedIP == IPAddress(0, 0, 0, 0)) { DBG(GF("invalid savedIP")); return false; } XBEE_COMMAND_START_DECORATOR(5, false) @@ -1294,8 +1319,10 @@ class TinyGsmXBee : public TinyGsmModem, // but it's possible the socket is set to the wrong place if (od != IPAddress(0, 0, 0, 0) && od != savedIP) { sockets[0]->stop(); + DBG(GF("modemGetConnected wrong socket"),od); return false; } + DBG(GF("modemGetConnected good socket"),od); return true; } @@ -1651,10 +1678,10 @@ class TinyGsmXBee : public TinyGsmModem, int16_t guardTime; XBeeType beeType; int8_t resetPin; - IPAddress savedIP; + IPAddress savedIP; //Last value sent to hw.Clear on gprsDisconnect powerOffImpl radioOffImpl String savedHost; - IPAddress savedHostIP; - IPAddress savedOperatingIP; + IPAddress savedHostIP; // Value looked up from savedHost + IPAddress savedOperatingIP; //read from hw, Cleared on modemStop - njh needs deleting bool inCommandMode; uint32_t lastCommandModeMillis; };