Pages: [1] 2   Go Down
Author Topic: Why's SD -> Ethernet Card -> Webbrowser so slow?  (Read 6629 times)
0 Members and 1 Guest are viewing this topic.
Holland
Offline Offline
Newbie
*
Karma: 2
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys,

Not a real problem, but could somebody explain why data transfer is so terribly slow:

I've an Arduino Ethernet card with 8GB SD card.
This SD card contains a complete html code including several jpg's and png's files.
It's all working fine: the webbrowser gives a request, arduino delivers the html page via the SD card, the webbrowser asks for the images (as put in the html file) and Arduino sent the files.
But an image of approx. 150kB takes about 20 seconds to load, what's the bottleneck around here?
(Arduino, Wiznet 5100, SD card, libraries..)

In all my simplicity smiley-slim I think: 8 MHz arduino, pick a byte from SD, sent it over the internet etc., 150kB shouldn't take 20 seconds?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi ,
how you make arduino open webpage on sd card having pictures and open it .. i tried to do that for 2 days and failed at the end
any help please
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The below discussion may have some useful info and examples.

http://arduino.cc/forum/index.php/topic,144675.0.html
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks alot really smiley
Logged

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

If you want to avoid the fate of the OP, then you need to send these files more than one byte per packet. If you are sending a big file, this will take relatively forever.
Code:
           while (myFile.available()) {
              client.write(myFile.read());
            }
            // close the file:
            myFile.close();

This sends the data in 64 byte packets, rather than one byte per packet.
Code:
 Serial.println("Writing");

  byte clientBuf[64];
  int clientCount = 0;

  while(fh.available())
  {
    clientBuf[clientCount] = fh.read();
    clientCount++;

    if(clientCount > 63)
    {
      Serial.println("Packet");
      client.write(clientBuf,64);
      clientCount = 0;
    }
  }

  if(clientCount > 0) client.write(clientBuf,clientCount);

edit: If you want it to work really fast, remove or comment out the Serial.println("Packet") statement. That was just for debugging.
« Last Edit: February 18, 2013, 10:09:46 am by SurferTim » Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I put the below in my origional code and it reduced the upload time of a 253k jpg file from 62 sec. to 15 sec.

Code:
          if (myFile) {

            byte clientBuf[64];
            int clientCount = 0;

            while(myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++;

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
            }
            // close the file:
            myFile.close();
          }
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

@zoomkat: You forgot this part. Without it, it may not send the last packet. There may have been less than 64 bytes in clientBuf.
Code:
  if(clientCount > 0) client.write(clientBuf,clientCount);

Compared to 15 seconds, 62 seconds is relatively forever.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Without it, it may not send the last packet. There may have been less than 64 bytes in clientBuf.

Good point, I went and added it back like below. Next project is to get all the file uploading into a single function.

Code:
          if (myFile) {

            byte clientBuf[64];
            int clientCount = 0;

            while(myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++;

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
            }
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);           
            // close the file:
            myFile.close();
          }
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why did you choose 64 bytes??  What is the maximum bytes per packet that ethernet shield can send??
Logged

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

Why did you choose 64 bytes??  What is the maximum bytes per packet that ethernet shield can send??
The maximum is about 1400. However, you can't use a variable declaration like this.
Code:
byte outBuf[1400];
You don't have that much memory in an Uno. So I wanted to insure it might be able to run on an Uno, but also send more data than header. The header is normally 48 bytes, so I picked 64.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it makes sense   smiley  in my code i have
Code:
int16_t c;
          while ((c = file.read()) >= 0) {
client.print((char)c);
          }
adapting it with the information you provide, is something like
Code:
byte clientBuf[64];
            int clientCount = 0;
              clientBuf[clientCount] = file.read();
              clientCount++;

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
           
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);           
            // close the file:
            file.close();
is this right?
Logged

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

I didn't compile it, but that looks like it!  smiley
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks i'll try it because i have the same speed problem with images.
One more thing... what does this line exactly do?
Code:
if(clientCount > 0) client.write(clientBuf,clientCount);
Logged

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

That sends the last packet. Unless you are really lucky, your files will not be an even multiple of 64, so there may be a few bytes remaining in that buffer when the file read is finished.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

got it  smiley   thanks!!
Logged

Pages: [1] 2   Go Up
Jump to: