Connecting to Local IP Address, and nonstandard port, with Tiny WiFi sheild

MitchLampert

  • Jr. Member
  • **
    • Posts: 7
    • View Profile
I would like to connect a local address like this: http://192.168.1.4:8080/GetValue.php?key=XYZ
Note 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:

Code: [Select]
  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?


MitchLampert

  • Jr. Member
  • **
    • Posts: 7
    • View Profile
Just an update. It appears as though I might have gotten a BAD WiFi shield unit.  :( I happened to run the code on a different set of parts, and THEN it always worked perfectly!

I replace only the WiFi shield within those parts, with the one I previously tried, and it gets issues again.

So, it looks like this wasn't a code problem. I'll see about getting a refund or replacement, soon, on this bad unit.


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
Sorry we're slow on the forum- have you contacted info@tinycircuits.com?

Although, have you checked that they have the same firmware? Different Texas Instrument firmwares will produce different results with issues similar to what you've described.


 

SMF spam blocked by CleanTalk