Go Down

Topic: SD card html page load time? (Read 2 times) previous topic - next topic

mistergreen

Mar 06, 2014, 04:40 pm Last Edit: Mar 06, 2014, 04:43 pm by mistergreen Reason: 1
Hi,
I'm working on a web server that pulls a simple html page off the SD card, about 50 lines.
It takes 1 minute - 12 seconds to load! Is that normal?

code below

Code: [Select]
webFile = SD.open("index.htm");        // open web page file
   if (webFile) {
      while(webFile.available()) {
          client.write(webFile.read()); // send web page to client
      }
      webFile.close();
    }

liudr

Is the arduino using a Wifi shield or Ethernet shield?

BTW, you should be reading bulk amount of the file instead of nibbling one byte at a time.

SurferTim

Here is what I use. tBuf is a 64 byte array. This gives you a 4x improvement in speed.
Code: [Select]
                  while(myFile.available()) {
                    tBuf[clientCount] = myFile.read();
                    clientCount++;
                    tBuf[clientCount] = 0;

                    if(clientCount > 63) {
                      client.write((byte*)tBuf,64);
                      clientCount = 0;
                    }

                  }
                  if(clientCount > 0) {
                    client.write((byte*)tBuf,clientCount);
                  }


mistergreen

I'm using the wifi shield.

Thanks SurferTim, I'll give the code a try.

mistergreen

Oh, well, the code doesn't work. It resets the app/web server for some reason instead of loading the index.htm.
When I'm done, I guess I'll just put the html file on the arduino itself. I still have plenty of space on the mega.


Here is what I use. tBuf is a 64 byte array. This gives you a 4x improvement in speed.
Code: [Select]
                  while(myFile.available()) {
                    tBuf[clientCount] = myFile.read();
                    clientCount++;
                    tBuf[clientCount] = 0;

                    if(clientCount > 63) {
                      client.write((byte*)tBuf,64);
                      clientCount = 0;
                    }

                  }
                  if(clientCount > 0) {
                    client.write((byte*)tBuf,clientCount);
                  }



mistergreen

It looks like the client.write for WIFI can't do chunks. oh well


liudr

You should post your complete code.

No, WiFi client write works differently than the rest of write. You should use write(*byte, int) instead.

mistergreen

#7
Mar 07, 2014, 03:32 am Last Edit: Mar 07, 2014, 04:53 am by mistergreen Reason: 1

You should post your complete code.

No, WiFi client write works differently than the rest of write. You should use write(*byte, int) instead.


according to the documentation, there is no second parameter

http://arduino.cc/en/Reference/WiFiClientWrite#.Uxkw3lxdJoo

I deleted the code but it's basically this
Code: [Select]

byte tBuf[64];
int clientCount = 0;

   File myFile = SD.open("index.htm");        // open web page file
   if (myFile) {
            while(myFile.available()) {
                   tBuf[clientCount] = myFile.read();
                   clientCount++;
                   tBuf[clientCount] = 0;

                   if(clientCount > 63) {
                     client.write((byte*)tBuf,64);
                     clientCount = 0;
                   }

           }
                 if(clientCount > 0) {
                   client.write((byte*)tBuf,clientCount);
                 }
       myFile.close();
   }


SurferTim

There is a write with two parameters. This is taken from WiFiClient.h.
Quote
virtual size_t write(uint8_t);
  virtual size_t write(const uint8_t *buf, size_t size);

You will find the wifi shield transfer rate is much more sluggish than the ethernet shield. The wifi shield also has some nasty one to two second delays every few seconds during a large download. It is one of a few bugs in the shield's firmware.

mistergreen

Ah, Yeah, it's weird. The code above resets the wifi shield. It restarts the wifi init process.

liudr


Ah, Yeah, it's weird. The code above resets the wifi shield. It restarts the wifi init process.


How did you know it restarts or resets?

SurferTim

Are you saying it restarts the Arduino again? Is it running the setup function when using that code? That could be caused by a SRAM problem. The extra 64 bytes used by that array may be enough to overflow the SRAM.

mistergreen

#12
Mar 07, 2014, 05:16 am Last Edit: Mar 07, 2014, 05:22 am by mistergreen Reason: 1

Are you saying it restarts the Arduino again? Is it running the setup function when using that code? That could be caused by a SRAM problem. The extra 64 bytes used by that array may be enough to overflow the SRAM.



Yup, the Void Setup is called again. I have Serial prints that tells me. I suspected it's a memory issue but I have plenty left on the board like 5200 bytes.

Ok, I'm bumping tBuf down to 32 bytes and see.

SurferTim

So it is a Mega 2560 you are using? That code does not cause a restart on my Mega.

mistergreen

Yup, I'm on a 2560 mega clone, maybe that's the cause.

Go Up