You’re totally right! Either the documentation is wrong, or the function should be updated, I’ll add that to our bug tracker. In the meantime you could always do a read with something like:
int bufSize = 256;
byte buffer[256];
int idx = 0;
while (client.available()) {
if (idx >= bufSize) { break; }
buffer[idx++] = client.read();
}
Serial.print("Msg was ");
Serial.print(idx);
Serial.println(" bytes ");
Hmm - what happens when you don’t have the delay? It’s possible that calling client.available()before client.connect() has completed (on the CC3000 side) might cause an issue; if so, we can put in a safeguard against that.
It’s because the client.available() has no data yet, i.e. your request is taking longer than 1 second, but less than 2 seconds. When that happens your “bytes” == 0 so your for() loop gets skipped and your client.stop() is run.
On the surface, better code would be instead of the delay(2000);
// wait 5 seconds or less for the server to respond
uint32_t startTime = millis();
while(!client.available() && (millis() - startTime) < 5000);
It might be possible to put this functionality into the client.available() method… but would you really want it in there?
EDIT: I tried this in your code and it works great!