CC3000 shield communication problem

Hi, I'm using an Arduino UNO with a CC3000 shield for wifi communication. I created a TCP server using an example sketch contained in the shield library, it's a simple echo server just for testing purpose. I'm using a Java TCP Client to send data to the server. The default example implementation does:

void loop(void)
{
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = echoServer.available();
  if (client) {
     // Check if there is data available to read.
     if (client.available() > 0) {
       // Read a byte and write it to all clients.
       uint8_t ch = client.read()
       client.write(ch);
     }
  }
}

this works like charm, it returns on my java client the same sent string.

Now, I'm triyng to return from server a custom string

void loop(void)
{
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = echoServer.available();
  if (client) {
     // Check if there is data available to read.
     if (client.available() > 0) {

       Serial.println("test");
       char array[10] = "mystring";
       client.write((uint8_t)atoi(array));
     }
  }
}

but the server loops writing "test", and it never returns the string. Removing "Serial.println("test");" does not help.

where is the error?

thanks a lot, regards,

Antonio

Hi Antonio

Try changing to this:

if (client.available() > 0) {
       uint8_t ch = client.read()
       Serial.println("test");
       client.println("mystring");
     }

The write method you were using sends just one byte of data. The atoi function converts a string containing a number (e.g. "12345") into an integer.

The code will print "mystring" for each character in the received data. Without the client.read(), it would keep on printing.

Regards

Ray