Tweeked the getSignalQuality for XBee
This commit is contained in:
@@ -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
|
String res = readResponse(); // it works better if we read in as a string
|
||||||
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");
|
|
||||||
exitCommand();
|
exitCommand();
|
||||||
int intr = strtol(buf, 0, 16);
|
char buf[3] = {0,}; // Set up buffer for response
|
||||||
if (beeType == XBEE_WIFI) return -93 + intr; // the maximum sensitivity is -93dBm
|
res.toCharArray(buf, 3);
|
||||||
else return -1*intr; // need to convert to negative number
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user