Created
August 23, 2012 12:11
-
-
Save mrichardson23/3436099 to your computer and use it in GitHub Desktop.
XIG URL Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String check(String URL) { | |
String response = ""; | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(URL); | |
XBee.println(URL); | |
requestTime = millis(); | |
while ((XBee.available() == 0) && (millis() - requestTime < responseTimeout)) | |
{ | |
//wait here until we hear something back or timeout | |
} | |
if (XBee.available()) { // if we received a response: | |
Serial.print("Server response: "); | |
int i = 0; | |
do { | |
char c = XBee.read(); | |
Serial.print(c); | |
response += c; | |
i++; | |
delay(1); | |
} while (XBee.available()); | |
} | |
else { // we timed out: | |
Serial.println("\nFailed to get a response."); | |
response = "ERR"; | |
XBee.println("abort"); | |
delay(1000); | |
} | |
Serial.print("\nPassing the value: "); | |
Serial.println(response); | |
if (response == "ERR"){ | |
failCount++; | |
} | |
else { | |
failCount = 0; | |
} | |
while (XBee.available()) { | |
XBee.read(); //flush anything else. | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment