Skip to content

Commit

Permalink
Reset cached savedIP when gprsDisconnectImpl, #2
Browse files Browse the repository at this point in the history
  • Loading branch information
neilh20 authored and neilh20 committed Sep 5, 2023
1 parent 2a1880c commit e2761de
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/TinyGsmClientXBee.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,

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;
Expand All @@ -602,6 +606,9 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
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(); }
Expand Down Expand Up @@ -903,6 +910,18 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,

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);
Expand Down Expand Up @@ -1117,6 +1136,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
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
Expand All @@ -1142,11 +1162,12 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
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!");
}
Expand Down Expand Up @@ -1179,7 +1200,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
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

Expand All @@ -1190,6 +1211,9 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,

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 ) {
Expand Down Expand Up @@ -1237,7 +1261,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,

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<const uint8_t*>(buff), len);
stream.flush();
Expand All @@ -1261,8 +1285,9 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
// 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)

Expand Down Expand Up @@ -1294,8 +1319,10 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
// 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;
}

Expand Down Expand Up @@ -1651,10 +1678,10 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
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;
};
Expand Down

0 comments on commit e2761de

Please sign in to comment.