minor clean up, removed some debugging
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -11,9 +11,7 @@
|
|||||||
#define SRC_TINYGSMCLIENTXBEE_H_
|
#define SRC_TINYGSMCLIENTXBEE_H_
|
||||||
// #pragma message("TinyGSM: TinyGsmClientXBee")
|
// #pragma message("TinyGSM: TinyGsmClientXBee")
|
||||||
|
|
||||||
#ifdef TinyGsmClientXbee_DBG
|
// #define TINY_GSM_DEBUG Serial
|
||||||
#define TINY_GSM_DEBUG Serial
|
|
||||||
#endif //TinyGsmClientXbee_DBG
|
|
||||||
|
|
||||||
// XBee's do not support multi-plexing in transparent/command mode
|
// XBee's do not support multi-plexing in transparent/command mode
|
||||||
// The much more complicated API mode is needed for multi-plexing
|
// The much more complicated API mode is needed for multi-plexing
|
||||||
@@ -110,13 +108,12 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// NOTE: The XBee saves all connection information (ssid/pwd etc) except
|
// NOTE: The XBee saves all connection information (ssid/pwd etc) except
|
||||||
// IP address and port number, in flash (NVM).
|
// IP address and port number, in flash (NVM).
|
||||||
// The NVM is be updated only when it is initialized.
|
// The NVM is be updated only when it is initialized.
|
||||||
// The TCP connection
|
// The TCP connection itself is not opened until you attempt to send data.
|
||||||
// itself is not opened until you attempt to send data. Because all settings
|
// Because all settings are saved to flash, it is possible (or likely) that
|
||||||
// are saved to flash, it is possible (or likely) that you could send data
|
// you could send data even if you haven't "made" any connection.
|
||||||
// even if you haven't "made" any connection.
|
|
||||||
virtual int connect(const char* host, uint16_t port, int timeout_s) {
|
virtual int connect(const char* host, uint16_t port, int timeout_s) {
|
||||||
// NOTE: Not caling stop() or yeild() here
|
// NOTE: Not caling stop() or yeild() here
|
||||||
at->streamClear(); // Empty anything in the buffer before starting
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
@@ -247,7 +244,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
|
|
||||||
String remoteIP() {
|
String remoteIP() {
|
||||||
IPAddress savedIP = at->savedIP;
|
IPAddress savedIP = at->savedIP;
|
||||||
return TinyGsmStringFromIp(savedIP);
|
return TinyGsmStringFromIp(savedIP);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -510,19 +507,18 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
delay(1);
|
delay(1);
|
||||||
digitalWrite(resetPin, HIGH);
|
digitalWrite(resetPin, HIGH);
|
||||||
} else {
|
} else {
|
||||||
DBG("pinReset - using software restart");
|
DBG("### Attempting a modem software restart");
|
||||||
restartImpl();
|
restartImpl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool restartImpl(const char* pin = NULL) {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!commandMode()) {
|
if (!commandMode()) {
|
||||||
DBG("restartImpl not in commandMode. Exit");
|
DBG("### XBee not in command mode for restart; Exit");
|
||||||
return false;
|
return false;
|
||||||
} // Return immediately
|
} // Return immediately
|
||||||
|
|
||||||
if (beeType == XBEE_UNKNOWN) getSeries(); // how we restart depends on this
|
if (beeType == XBEE_UNKNOWN) getSeries(); // how we restart depends on this
|
||||||
DBG("restartImpl",beeType );
|
|
||||||
|
|
||||||
if (beeType != XBEE_S6B_WIFI) {
|
if (beeType != XBEE_S6B_WIFI) {
|
||||||
sendAT(GF("AM1")); // Digi suggests putting cellular modules into
|
sendAT(GF("AM1")); // Digi suggests putting cellular modules into
|
||||||
@@ -660,7 +656,6 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
break;
|
break;
|
||||||
default: stat = REG_UNKNOWN; break;
|
default: stat = REG_UNKNOWN; break;
|
||||||
}
|
}
|
||||||
DBG("Digi WiFi regStatus",stat,",",intRes);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: { // Cellular XBee's
|
default: { // Cellular XBee's
|
||||||
@@ -1134,29 +1129,25 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
// Put in SSL over TCP communication mode
|
// Put in SSL over TCP communication mode
|
||||||
changesMade |= changeSettingIfNeeded(GF("IP"), 0x4);
|
changesMade |= changeSettingIfNeeded(GF("IP"), 0x4);
|
||||||
} else {
|
} else {
|
||||||
// Put in TCP mode
|
// Put in unsecured TCP mode
|
||||||
changesMade |= changeSettingIfNeeded(GF("IP"), 0x1);
|
changesMade |= changeSettingIfNeeded(GF("IP"), 0x1);
|
||||||
}
|
}
|
||||||
bool changesMadeCpy=changesMade;
|
bool changesMadeSSL = changesMade;
|
||||||
|
|
||||||
changesMade |= changeSettingIfNeeded(
|
changesMade |= changeSettingIfNeeded(
|
||||||
GF("DL"), String(host)); // Set the "Destination Address Low"
|
GF("DL"), String(host)); // Set the "Destination Address Low"
|
||||||
changesMade |= changeSettingIfNeeded(
|
changesMade |= changeSettingIfNeeded(
|
||||||
GF("DE"), String(port, HEX)); // Set the destination port
|
GF("DE"), String(port, HEX)); // Set the destination port
|
||||||
|
|
||||||
if (beeType == XBEE_S6B_WIFI) {
|
// WiFi Bee is different
|
||||||
DBG("modemConnect IP changes not saved");
|
if (beeType == XBEE_S6B_WIFI) { changesMade = changesMadeSSL; }
|
||||||
changesMade = changesMadeCpy;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changesMade) { success &= writeChanges(); }
|
if (changesMade) { success &= writeChanges(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// confirm the XBee type if needed so we know if we can know if connected
|
||||||
|
if (beeType == XBEE_UNKNOWN) { getSeries(); }
|
||||||
// we'll accept either unknown or connected
|
// we'll accept either unknown or connected
|
||||||
if (XBEE_UNKNOWN == beeType ) {
|
|
||||||
getSeries();
|
|
||||||
DBG("BeeType modemConnect refresh",XBEE_S6B_WIFI,"=", beeType);
|
|
||||||
}
|
|
||||||
if (beeType != XBEE_S6B_WIFI) {
|
if (beeType != XBEE_S6B_WIFI) {
|
||||||
uint16_t ci = getConnectionIndicator();
|
uint16_t ci = getConnectionIndicator();
|
||||||
success &= (ci == 0x00 || ci == 0xFF || ci == 0x28);
|
success &= (ci == 0x00 || ci == 0xFF || ci == 0x28);
|
||||||
@@ -1170,16 +1161,15 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool modemStop(uint32_t maxWaitMs) {
|
bool modemStop(uint32_t maxWaitMs) {
|
||||||
DBG("modemStop WaitMs=",maxWaitMs);
|
|
||||||
streamClear(); // Empty anything in the buffer
|
streamClear(); // Empty anything in the buffer
|
||||||
// empty the saved currently-in-use destination address
|
// empty the saved currently-in-use destination address
|
||||||
savedOperatingIP = IPAddress(0, 0, 0, 0);
|
savedOperatingIP = IPAddress(0, 0, 0, 0);
|
||||||
|
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
|
|
||||||
// This is a
|
// For WiFi models, there's no direct way to close the socket;
|
||||||
// hack to shut the socket by setting the timeout to zero.
|
// use DigiXBeeWifi::disconnectInternet(void)
|
||||||
// For WiFi use DigiXBeeWifi::disconnectInternet(void)
|
|
||||||
if (beeType != XBEE_S6B_WIFI) {
|
if (beeType != XBEE_S6B_WIFI) {
|
||||||
// Get the current socket timeout
|
// Get the current socket timeout
|
||||||
sendAT(GF("TM"));
|
sendAT(GF("TM"));
|
||||||
@@ -1189,7 +1179,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
// timeout) value while in Transparent Mode, the current connection is
|
// timeout) value while in Transparent Mode, the current connection is
|
||||||
// immediately closed - this works even if the TM values is unchanged
|
// immediately closed - this works even if the TM values is unchanged
|
||||||
sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout
|
sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout
|
||||||
waitResponse(maxWaitMs); // This response can be slow
|
waitResponse(maxWaitMs); // This response can be slow
|
||||||
}
|
}
|
||||||
|
|
||||||
XBEE_COMMAND_END_DECORATOR
|
XBEE_COMMAND_END_DECORATOR
|
||||||
@@ -1407,9 +1397,9 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
data.replace(GSM_NL GSM_NL, GSM_NL);
|
data.replace(GSM_NL GSM_NL, GSM_NL);
|
||||||
data.replace(GSM_NL, "\r\n ");
|
data.replace(GSM_NL, "\r\n ");
|
||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG("### waitResponse ms=",timeout_ms," Unhandled:", data.c_str(), "\r\n");
|
DBG("### Unhandled:", data, "\r\n");
|
||||||
} else {
|
} else {
|
||||||
DBG("### waitResponse ms=",timeout_ms," NO RESPONSE FROM MODEM!\r\n");
|
DBG("### NO RESPONSE FROM MODEM!\r\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data.trim();
|
data.trim();
|
||||||
@@ -1439,13 +1429,11 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
if (inCommandMode && (millis() - lastCommandModeMillis) < 10000L)
|
if (inCommandMode && (millis() - lastCommandModeMillis) < 10000L)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
uint8_t triesMade = 0;
|
uint8_t triesMade = 0;
|
||||||
uint8_t triesUntilReset = 4; // reset after number of tries
|
int8_t res;
|
||||||
int8_t res ;
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if (beeType == XBEE_S6B_WIFI) {
|
uint8_t triesUntilReset = 4; // reset after number of tries
|
||||||
triesUntilReset=9;
|
if (beeType == XBEE_S6B_WIFI) { triesUntilReset = 9; }
|
||||||
}
|
|
||||||
streamClear(); // Empty everything in the buffer before starting
|
streamClear(); // Empty everything in the buffer before starting
|
||||||
|
|
||||||
while (!success && triesMade < retries) {
|
while (!success && triesMade < retries) {
|
||||||
@@ -1454,25 +1442,24 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
delay(guardTime + 10);
|
delay(guardTime + 10);
|
||||||
streamWrite(GF("+++")); // enter command mode
|
streamWrite(GF("+++")); // enter command mode
|
||||||
|
|
||||||
|
|
||||||
if (beeType != XBEE_S6B_WIFI) {
|
if (beeType != XBEE_S6B_WIFI) {
|
||||||
res = waitResponse(guardTime * 2);
|
res = waitResponse(guardTime * 2);
|
||||||
} else {
|
} else {
|
||||||
//S6B used longer guard time, to allow to recover
|
// S6B wait a full second for OK
|
||||||
res = waitResponse();
|
res = waitResponse();
|
||||||
}
|
}
|
||||||
success = (1 == res);
|
|
||||||
|
success = (1 == res);
|
||||||
if (0 == res) {
|
if (0 == res) {
|
||||||
triesUntilReset--;
|
triesUntilReset--;
|
||||||
if (triesUntilReset == 0) {
|
if (triesUntilReset == 0) {
|
||||||
DBG("commandMode Module PinReset");
|
|
||||||
triesUntilReset = 4;
|
triesUntilReset = 4;
|
||||||
pinReset(); // if it's unresponsive, reset
|
pinReset(); // if it's unresponsive, reset
|
||||||
delay(250); // a short delay to allow it to come back up
|
delay(250); // a short delay to allow it to come back up
|
||||||
// TODO(SRGDamia1) optimize this
|
// TODO(SRGDamia1) optimize this
|
||||||
}
|
}
|
||||||
if (beeType == XBEE_S6B_WIFI) {
|
if (beeType == XBEE_S6B_WIFI) {
|
||||||
delay(5000); // WiFi module frozen, wait longer
|
delay(5000); // WiFi module frozen, wait longer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
triesMade++;
|
triesMade++;
|
||||||
@@ -1509,16 +1496,16 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
void getSeries(void) {
|
void getSeries(void) {
|
||||||
sendAT(GF("HS")); // Get the "Hardware Series";
|
sendAT(GF("HS")); // Get the "Hardware Series";
|
||||||
int16_t intRes = readResponseInt();
|
int16_t intRes = readResponseInt();
|
||||||
// if no response from module, then try again
|
// if no response from module, then try again
|
||||||
if (0xff == intRes) {
|
if (0xff == intRes) {
|
||||||
sendAT(GF("HS")); // Get the "Hardware Series";
|
sendAT(GF("HS")); // Get the "Hardware Series";
|
||||||
intRes = readResponseInt();
|
intRes = readResponseInt();
|
||||||
if (0xff == intRes) {
|
if (0xff == intRes) {
|
||||||
//Still no response, leave a known value - should reset
|
// Still no response, leave a known value - should reset
|
||||||
intRes = XBEE_UNKNOWN;
|
intRes = XBEE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
beeType = (XBeeType)intRes;
|
beeType = (XBeeType)intRes;
|
||||||
DBG(GF("### Modem: "), getModemName(), beeType);
|
DBG(GF("### Modem: "), getModemName(), beeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1573,12 +1560,11 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
sendAT(cmd, newValue);
|
sendAT(cmd, newValue);
|
||||||
// return false if we attempted to change but failed
|
// return false if we attempted to change but failed
|
||||||
if (waitResponse(timeout_ms) != 1) { return false; }
|
if (waitResponse(timeout_ms) != 1) { return false; }
|
||||||
// check if we succeeded in staging a change
|
// check if we succeeded in staging a change and retry once
|
||||||
sendAT(cmd);
|
sendAT(cmd);
|
||||||
if (readResponseString() != newValue) {
|
if (readResponseString() != newValue) {
|
||||||
sendAT(cmd, newValue);
|
sendAT(cmd, newValue);
|
||||||
if (waitResponse(timeout_ms) != 1) { return false; }
|
if (waitResponse(timeout_ms) != 1) { return false; }
|
||||||
DBG("changeSettingIfNeeded try2",cmd,newValue);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user