Holland
Offline
Newbie
Karma: 0
Posts: 12
|
 |
« on: November 29, 2012, 01:45:07 pm » |
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  I think: 8 MHz arduino, pick a byte from SD, sent it over the internet etc., 150kB shouldn't take 20 seconds?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #1 on: February 17, 2013, 06:19:01 pm » |
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
|
|
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #3 on: February 17, 2013, 09:14:23 pm » |
thanks alot really
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3447
|
 |
« Reply #4 on: February 18, 2013, 07:31:49 am » |
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. 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. 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
Online
Tesla Member
Karma: 50
Posts: 6531
Arduino rocks
|
 |
« Reply #5 on: February 19, 2013, 12:20:55 am » |
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. 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
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3447
|
 |
« Reply #6 on: February 20, 2013, 08:03:20 am » |
@zoomkat: You forgot this part. Without it, it may not send the last packet. There may have been less than 64 bytes in clientBuf. if(clientCount > 0) client.write(clientBuf,clientCount); Compared to 15 seconds, 62 seconds is relatively forever.
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 50
Posts: 6531
Arduino rocks
|
 |
« Reply #7 on: February 20, 2013, 11:23:10 pm » |
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. 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
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 103
|
 |
« Reply #8 on: February 24, 2013, 12:44:34 pm » |
Why did you choose 64 bytes?? What is the maximum bytes per packet that ethernet shield can send??
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3447
|
 |
« Reply #9 on: February 24, 2013, 03:09:45 pm » |
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. 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
Full Member
Karma: 0
Posts: 103
|
 |
« Reply #10 on: February 24, 2013, 04:52:06 pm » |
it makes sense  in my code i have int16_t c; while ((c = file.read()) >= 0) { client.print((char)c); } adapting it with the information you provide, is something like 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
Faraday Member
Karma: 50
Posts: 3447
|
 |
« Reply #11 on: February 24, 2013, 04:57:40 pm » |
I didn't compile it, but that looks like it! 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 103
|
 |
« Reply #12 on: February 24, 2013, 05:02:51 pm » |
Thanks i'll try it because i have the same speed problem with images. One more thing... what does this line exactly do? if(clientCount > 0) client.write(clientBuf,clientCount);
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3447
|
 |
« Reply #13 on: February 24, 2013, 05:12:03 pm » |
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
Full Member
Karma: 0
Posts: 103
|
 |
« Reply #14 on: February 24, 2013, 05:28:56 pm » |
got it  thanks!!
|
|
|
|
|
Logged
|
|
|
|
|
|