upload data from arduino SD to web page

Hello everyone

I am trying to upload a txt file from arduino SD to web page but my data rate its slow
(for 1.4MB data complete loading in 5.15 minutes)

Is that any way to do the job faster or any other method?
Thanks in advance!

this is my code:

void setup()
{

void ListFiles(UIPClient, uint8_t);

}

void loop()
{

ETH_SERVER();

}

void ListFiles(EthernetClient client, uint8_t flags) {
// This code is just copied from SdFile.cpp in the SDFat library
// and tweaked to print to the client output in html!
dir_t p;

root.rewind ();
client.println("

    ");
    while (root.readDir(&p) > 0) {
    // done if past last used entry
    if (p.name[0] == DIR_NAME_FREE) break;

    // skip deleted entry and entries for . and ..
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;

    // only list subdirectories and files
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;

    // print any indent spaces
    client.print("

  • <a href=""); //δημιουργία σειράς και link
    for (uint8_t i = 0; i < 11; i++) {
    if (p.name == ' ') continue;

    • if (i==8) {*
    • client.print('.');*
    • }*
    • //client.print("&#");*
      _ client.print((char)p.name*); //diaforetiko sto site*_
      * }*
      * client.print("">");*

    * // print file name with possible blank fill*
    * for (uint8_t i = 0; i < 11; i++) {
    _ if (p.name == ' ') continue;
    if (i==8) {
    client.print('.');
    }*_

    _ client.print((char)p.name*);
    }*_

    * client.print("");*

    * if (DIR_IS_SUBDIR(&p)) {
    _ client.print('/');
    }*_

    * // print modify date/time if requested*
    * if (flags & LS_DATE) {
    _ root.printFatDate(p.lastWriteDate);
    client.print(' ');
    root.printFatTime(p.lastWriteTime);
    }
    // print size if requested*

    * if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {*
    * client.print(' ');
    client.print(p.fileSize);
    }
    client.println("

  • ");
    }
    client.println("
");
}[/color]
void ETH_SERVER(void)
{
char clientline[BUFSIZ];
int index = 0;*_

* EthernetClient client = server.available();*
* if (client) {*
* // an http request ends with a blank line*
* boolean current_line_is_blank = true;
_ // reset the input buffer*
* index = 0;*_

* while (client.connected()) {*
* if (client.available()) {*
* char c = client.read();*
* // If it isn't a new line, add the character to the buffer*
* if (c != '\n' && c != '\r') {*
* clientline[index] = c;*
* index++;*
* // are we too big for the buffer? start tossing out data*
* if (index >= BUFSIZ)*
* index = BUFSIZ -1;*

* // continue to read more data!*
* continue;*
* }*

* // got a \n or \r new line, which means the string is done*
* clientline[index] = 0;*

* // Look for substring such as a request to get the root file*
* if (strstr (clientline, "GET / ") != 0) {*
* // send a standard http response header*
* client.println("HTTP/1.1 200 OK");*
* client.println("Content-Type: text/html");*
* client.println();*

* // print all the files, use a helper to keep it clean*
* client.println("

Files:

");*
* ListFiles(client, LS_SIZE);
_ } else if (strstr (clientline, "GET /") != 0) {
// this time no space after the /, so a sub-file!*

char *filename;_

* filename = clientline + 5; // look after the "GET /" (5 chars)*
* // a little trick, look for the " HTTP/1.1" string and*
* // turn the first character of the substring into a 0 to clear it out.*
* (strstr (clientline, " HTTP"))[0] = 0;*

* // print the file we want*
* // Serial.println(filename);*

* if (! file.open(&root, filename, O_READ)) {
_ client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("

File Not Found!

");
break;
}*_

* Serial.println("Opened!");*

* client.println("HTTP/1.1 200 OK");*
* client.println("Content-Type: text/plain");*
* client.println();*

* int16_t c;
_ while ((c = file.read()) > 0) {
// uncomment the serial to debug (slow!)
//Serial.print((char)c);
client.print((char)c);
}
file.close();
} else {
// everything else is a 404*

* client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("

File Not Found!

");
}
break;
}
}
// give the web browser time to receive the data*

* delay(1);
client.stop();
}
}*_

Why do you have a function prototype in setup()?

Reading one byte at a time from the file, and sending a packet containing that one byte IS going to be slow.

Read more than one byte; send more than one byte.

Yes Its better to put the function out

if i read more than one byte at the time its possible to lose some data, isnt it?

how many bytes per time i have to read to be safe?

maybe something like this?

if (client) {
byte buf[512];
while (1) {
int n = client.available();
if (n == 0) break;
if (n > 512) n = 512;
client.read(buf, n);
client.write(buf, n);
}
client.close();
}

can you give me an example?

if i read more than one byte at the time its possible to lose some data, isnt it?

Sure, if your code is wrong.

maybe something like this?

No, not a thing like that.

You don't want to read from the client and then write to the client. You want to read from the file, and write to the client. The packet sent by the client will be 512 bytes. A 512 byte packet can't contain a 512 byte payload.

Try reading 64 bytes from the file, and writing however many bytes you actually read to the client.

Yes, you are right i'll try it!

upload 1.4 MB in 25 sec.

Changes:

byte buf[512];

while ((file.read()) > 0) {
int n = file.available();
if (n == 0) break;
if (n > 512) n = 512;
file.read(buf, n);
client.write(buf, n);
}

but i am trying to make it faster!

 while ((file.read()) > 0) {

WTF? Are you REALLY expecting to iterate reading NULL from the file?

but i am trying to make it faster!

Using a 512 character buffer is NOT the way to make it faster.

If you REALLY want faster, use a PC.