Browse Source

Tweeked the getSignalQuality for XBee

v_master
SRGDamia1 7 years ago
parent
commit
34db96ac21
1 changed files with 11 additions and 13 deletions
  1. +11
    -13
      src/TinyGsmClientXBee.h

+ 11
- 13
src/TinyGsmClientXBee.h View File

@ -462,17 +462,13 @@ public:
if (!commandMode()) return 0; // Return immediately if (!commandMode()) return 0; // Return immediately
if (beeType == XBEE_WIFI) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity if (beeType == XBEE_WIFI) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity
else sendAT(GF("DB")); // ask for the cell strength in dBm else sendAT(GF("DB")); // ask for the cell strength in dBm
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
char buf[2] = {0}; // Set up buffer for response
buf[0] = streamRead();
buf[1] = streamRead();
// DBG(buf[0], buf[1], "\n");
String res = readResponse(); // it works better if we read in as a string
exitCommand(); exitCommand();
int intr = strtol(buf, 0, 16);
if (beeType == XBEE_WIFI) return -93 + intr; // the maximum sensitivity is -93dBm
else return -1*intr; // need to convert to negative number
char buf[3] = {0,}; // Set up buffer for response
res.toCharArray(buf, 3);
int intRes = strtol(buf, 0, 16);
if (beeType == XBEE_WIFI) return -93 + intRes; // the maximum sensitivity is -93dBm
else return -1*intRes; // need to convert to negative number
} }
bool isNetworkConnected() { bool isNetworkConnected() {
@ -590,11 +586,12 @@ private:
bool gotIP = false; bool gotIP = false;
// XBee's require a numeric IP address for connection, but do provide the // XBee's require a numeric IP address for connection, but do provide the
// functionality to look up the IP address from a fully qualified domain name // functionality to look up the IP address from a fully qualified domain name
while (!gotIP && millis() - startMillis < 30000) // the lookup can take a while
while (!gotIP && millis() - startMillis < 60000) // the lookup can take a while
{ {
sendAT(GF("LA"), host); sendAT(GF("LA"), host);
while (stream.available() < 4) {};// wait for the response
while (stream.available() < 4) {}; // wait for any response
strIP = streamReadUntil('\r'); // read result strIP = streamReadUntil('\r'); // read result
// DBG("<<< ", strIP);
if (!strIP.endsWith(GF("ERROR"))) gotIP = true; if (!strIP.endsWith(GF("ERROR"))) gotIP = true;
delay(100); // short wait before trying again delay(100); // short wait before trying again
} }
@ -664,11 +661,11 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
String return_string = stream.readStringUntil(c); String return_string = stream.readStringUntil(c);
return_string.trim(); return_string.trim();
// DBG(return_string, c);
return return_string; return return_string;
} }
void streamClear(void) { void streamClear(void) {
TINY_GSM_YIELD();
while (stream.available()) { streamRead(); } while (stream.available()) { streamRead(); }
} }
@ -705,6 +702,7 @@ public:
unsigned long startMillis = millis(); unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < timeout) {}; while (!stream.available() && millis() - startMillis < timeout) {};
String res = streamReadUntil('\r'); // lines end with carriage returns String res = streamReadUntil('\r'); // lines end with carriage returns
// DBG("<<< ", res);
return res; return res;
} }


Loading…
Cancel
Save