I would like to connect a local address like this:
http://192.168.1.4:8080/GetValue.php?key=XYZNote that: I am calling the IP address directly, using a nonstandard port (8080), and there are parameters after the web page name.
I believe I should be able to do this with the following code. However it doesn't seem to be reliable:
ip = 3232235780; //192.168.1.4 converted to int.
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 8080);
if (www.connected()) {
www.fastrprint(F("GET "));
www.fastrprint("/GetValue.php?key=XYZ");
www.fastrprint(F(" HTTP/1.1\r\n"));
www.fastrprint(F("Host: ")); www.fastrprint("192.168.1.4"); www.fastrprint(F("\r\n"));
www.fastrprint(F("\r\n"));
www.println();
Serial.println(F("Connected!"));
} else {
Serial.println(F("Connection failed"));
return;
}
Serial.println(F("-------------------------------------"));
/* Read data until either the connection is closed, or the idle timeout is reached. */
unsigned long lastRead = millis();
while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
while (www.available()) {
char c = www.read();
Serial.print(c);
lastRead = millis();
}
}
Serial.println("");Serial.println("");
www.close();
Whenever I call the address at the top of the post in a browser, it always works reliably. But, the code above seems to load the wrong content most of the time. And, weirdly, might start working properly after a while.
Any ideas on what's going on, and what to do about that?