Pages: [1] 2   Go Down
Author Topic: SD card html page load time?  (Read 2483 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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();
     }
« Last Edit: March 06, 2014, 10:43:30 am by mistergreen » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5870
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is what I use. tBuf is a 64 byte array. This gives you a 4x improvement in speed.
Code:
                  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);
                  }
 
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the wifi shield.

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

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
                  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);
                  }
 

Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should post your complete code.

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


0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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();
    }

« Last Edit: March 06, 2014, 10:53:48 pm by mistergreen » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5870
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
 
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5870
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 06, 2014, 11:22:31 pm by mistergreen » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5870
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2   Go Up
Jump to: