WiFly GSX breakout - sporadic latency

Hi folks,

My first post here so greetings to all.

I have a WiFly GSX breakout that I’m using with an Arduino Uno over UART (via the NewSoftSerial library). I am experiencing highly inconsistent latency in the WiFly sending received data over UART to the Arduino. Packets take anywhere from seconds to minutes to be received. The data is strings being sent from a java application from my mac laptop.

This is the java on my lappy code that establishes the connection to the WiFly:

echoSocket = new Socket(“192.168.1.18”, 2000);

out = new PrintWriter(echoSocket.getOutputStream(), true);

out.println(“hello?”);

When I see the ‘hello?’ message has been received by the WiFly (on the Arduino Serial Monitor), I then run the following java to send 10 separate messages every two seconds:

Thread.sleep(2000);

SendMessage(“packet1”);

Thread.sleep(2000);

SendMessage(“packet2”);

Thread.sleep(2000);

SendMessage(“packet3”);

Thread.sleep(2000);

SendMessage(“packet10”);

When the first packet is received by the Arduino from the WiFly, it records the current millis() time which it then uses to determine how many milliseconds pass until the next packet arrives, and so on for each packet until packet 10 has been received. The code on the Arduino for this is as follows:

//Check wifly for data

if(wiFly.available() > 0)

{

String response = “”;

//Read data

while(wiFly.available() > 0)

{

char c = wiFly.read();

response += c;

delay(2);

}

wiFly.flush();

//If message is ‘packet1’, start timer

if(response.startsWith(“packet1”) && !response.endsWith(“packet10”))

{

timeStart = millis();

bStarted = true;

Serial.println(“Wifly: " + response + " (timer started)”);

}

//if(if packet1 has been received, check time difference for this packet)

else if(bStarted)

{

//Check time difference

unsigned long timeDiff = millis() - timeStart;

Serial.print(“Wifly: " + response + " (”);

Serial.print(timeDiff);

Serial.println(“)”);

//Stop at ‘packet10’

if(response.endsWith(“packet10”))

{

bStarted = false;

}

//Reset for next packet

timeStart = millis();

}

//General untimed message

else

{

Serial.println("Wifly: " + response);

}

}

Now, the time between each of these packets being received varies pretty wildly. Below is the output from three separate executions of the above code:

Wifly: packet1

(timer started)

Wifly: packet2

(2219)

Wifly: packet3

(1752)

Wifly: packet4

(1977)

Wifly: packet5

packet6

packet7

(6424)

Wifly: packet8

(1501)

Wifly: packet9

packet10

(36510)

Wifly: packet1

(timer started)

Wifly: packet2

packet3

packet4

(5929)

Wifly: packet5

(1781)

Wifly: packet6

(1985)

Wifly: packet7

(2611)

Wifly: packet8

packet9

packet10

(11111)

Wifly: packet1

packet2

packet3

packet4

packet5

packet6

(timer started)

Wifly: packet7

(1312)

Wifly: packet8

(1395)

Wifly: packet9

packet10

(10966)

As you can see, the packets arrive anywhere from nearly straight away to over 30 seconds, sometimes minutes. Often, several will even spool up in the WiFly before being sent to the Arduino, a couple of times I saw nothings for several minutes before all 10 messages appeared at once.

Sending data from the Wifly back to my laptop are always almost instantaneous. And I’ve also tested the java code with connecting to just another computer and all packets are received very quickly so I’m positive the issue is with the WiFly.

It is running firmware 2.23 and I’ve also disabled the auto sleep timer which did not seem to help. Connection is over a Dlink wireless router. Can provide any more details, not sure what else is pertinent.

So, thoughts?

(Sorry for the long post, thanks if you’ve read this far!)

To simplify my first post, I sent the string “a” from my laptop 5 times to the wifly and measured the time it took for the wifly to send a response back:

  1. 15413 ms

  2. 47 ms

  3. 302 ms

  4. 41051 ms

  5. 55 ms

So for the exact same packet, the wifly can take anywhere from 47 milliseconds to 41 seconds to respond. Ideally I’d like to average below 300ms.