Wifi shield inexplicable delay (1.6 seconds per packet)

Greetings, done a pile of searching and seeing people with similar problems with the official wifi shield…

Using official shield on an uno, upgraded firmware 1.1.

I’ve set up the demo sketch “WifiWebServer” and tweaked it so instead of outputting the analog values, it simply outputs the delay it took to send each line.

Other people have found that more Client.print or Client.write commands creates unnecessary packets, so I’ve condensed each line of html into a single string. Each string cannot exceed 90 characters or the spi on the wifi will reject it.

basically, it’s quite quick to transmit, but every 11th packet poops the bed and instead of taking 1-9 milliseconds to transmit, it takes 1600-1800ms.

I’ve condensed the http/html header to be 2 packets, meaning when I get to the loop , the 9th and n+11 iterations later will all have a long delay. It doesn’t matter how long the packet is. The transmit time is 1-9 milliseconds regardless of length for all other packets, then 100-2000 for the bad ones. Even if I include a delay in the iterative code it still takes as long to transmit the 11th packet, so the delay is introduced when the data is sent to the wifi board.

Mozilla developer inspector shows 1500ms of waiting and 2000ms of receiving when that number should be more like 100ms total for the 2k of data.

attached is the web output and serial output

  WiFi Web Server

 A simple web server that outputs delay values to html client
 using a WiFi shield.

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.

 * WiFi shield attached
 * Analog inputs attached to pins A0 through A5 (optional)

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe


#include <SPI.h>
#include <WiFi.h>

char ssid[] = "TelusSucks";      // your network SSID (name)
char pass[] = "*******";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {
  //Initialize serial and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);

  String fv = WiFi.firmwareVersion();
  if ( fv != "1.1.0" )
    Serial.println("Please upgrade the firmware");

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 6 seconds for connection:
  // you're connected now, so print out the status:

void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          long curTime = millis();
          //http html header
          client.println("HTTP/1.1 200 OK\nContent-Type: text/html\nConnection: close\nRefresh: 5\n");
          //client.println("Content-Type: text/html");
          //client.println("Connection: close");  // the connection will be closed after completion of the response
          //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println("<!DOCTYPE HTML>\n<html>");
          // Output a bunch of data as single strings to save packets
          String strOutput = "";
          for (int lineNumber = 0; lineNumber < 37; lineNumber++) {
            strOutput = "";
            int intTimer = millis()-curTime; //how long has it been per iteration, resets per connection
            strOutput += String("Deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelay on line ");  //build one line of packet
            strOutput += lineNumber;
            strOutput += " is ";
            strOutput += intTimer;
            strOutput += "
            long txDelay = millis();
            client.println(strOutput);  //send packet
            Serial.print("packet ");
            Serial.print(" transmission time:");
            Serial.println(millis() - txDelay);

        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data

    // close the connection:
    Serial.println("client disonnected\n");

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(" dBm");

test results.txt (5.69 KB)

It is a known problem, and not the only one. http://forum.arduino.cc/index.php?topic=210164.msg1543210#msg1543210

Here is a post from December 2013 that has a list of the problems and the related reports to the Arduino crew about the wifi shield. AFAIK, none have been fixed. http://forum.arduino.cc/index.php?topic=207128.msg1523429#msg1523429

Thanks for the heads up - was hoping there was some sneaky solution that someone had come up with; I guess with the advent of the raspberry pi there is no point trying to interface an atmega with interwebs...

Oh well, I'll see if I can learn to code what I need in python...

@arduino...this sucks.

I hope you realize that a lot of your issues lie with the String class. Ditch that, and I'll bet that the results get better.