I am having a strange problem trying to operate the cc3000 (firmware 1.24) on a Mega2560 as an echo server. The Arduino IDE is version 1.0.5-r2.
I have run the various example scripts for the cc3000 (buildTest, etc) and everything worked fine. The shield and library are working correctly.
However, when I run the echoServer sketch I get strange behavior. The problem: when the client program sends data the sketch freezes . Before the client program sends data I see the "Checking echoServer" message as seen in the Serial Console output below. When data is received from the client program the sketch "freezes" on the if statement marked as "A" in the code. I do see the appropriate (I think) values for theClient.Connected and theClient.Available. The sketch never reaches the println "Client exists", and the LED remains on; the code never reaches the point "B" where the LED is turned off.
I have slightly modified the original sketch to
- add print statements and to light pin 13 LED for debugging; the code is shown below.
- change the name of the client variable to theClient, just in case the compiler was getting confused.
- I tried the test -->if (theClient.available())<-- instead of -->if (theClient)<-- just to see if it makes a difference - it doesn't.
Modified Code:
Code: Select all
void loop(void)
{
char s[100];
// Try to get a client which is connected.
Serial.print("Checking echoServer.available...");
Adafruit_CC3000_ClientRef theClient = echoServer.available();
sprintf(s, "OK %d %d Avail %d", iter, theClient.connected(), theClient.available());
Serial.println(s);
iter++;
digitalWrite(13,HIGH);
if (theClient) { [color=#FF0000]// A - Freeze point[/color]
// Check if there is data available to read.
digitalWrite(13,LOW); [color=#FF0000]// B - Never gets here[/color]
Serial.println("Client exists");
if (theClient.available() > 0) {
// Read a byte and write it to all clients.
uint8_t buf[256];
uint8_t ch = theClient.read();
theClient.write(ch);
Serial.println(".");
}
}
delay(500);
digitalWrite(13,LOW);
delay(300);
}
Checking echoServer.available...OK 18 0 Avail 0 <-- LED 13 blinking, as expected
Checking echoServer.available...OK 19 0 Avail 0
Checking echoServer.available...OK 20 0 Avail 0
Checking echoServer.available...OK 21 0 Avail 0
Checking echoServer.available...OK 22 0 Avail 0
Checking echoServer.available...OK 23 0 Avail 0
Checking echoServer.available...OK 24 0 Avail 0
Checking echoServer.available...OK 25 1 Avail 1 <--- data sent from Client program
Nothing appears after this, and LED 13 stays on
I don't know what else to test - this "seems" pretty simple, I don't know why the sketch would freeze.