Go Down

Topic: Ethernet File passing. (Read 442 times) previous topic - next topic

aShadow

Hi

I have an arduino webserver that is logging data to an external EEPROM chip. The user needs to be able to download all the logged data from the browser. thus i need to do one of the following:

-->Create a text file on the arduino and pass it to the browser for the user to download. (In this case my issue is sending a text file via ethernet).

-->Send the browser a string and have php or asp script assemble it into a .txt file for the user to download.

I am something of a novice programmer and I can't get the client side to execute the PHP or ASP code i send it using client.println commands.

I have the browser displaying the data in realtime.

Any help would be appreciated, i am sure it is a simple 2 or 3 lines of code i am missing that is needed to pass the .txt file (or a variable of type string) through the ethernet.

PaulS

Quote
I have the browser displaying the data in realtime.

Why not provide a form button save the data? The action method for that form need no involve the Arduino at all. Execute a PHP script (or cgi or asp or whatever your comfortable with) that collects data from the (hidden, if necessary) fields on the form.

billroy

It's most straightforward to send the data as a file in response to a GET request.  There are plenty of web server examples to start from, some with SD card support.  The easiest way is to read the file a byte at a time and send it to the network.

You can force a browser to download a resource instead of displaying it by including a "content disposition" header in the response headers, after the content-type header:
Code: [Select]

Content-Disposition: attachment; filename="filename.ext"


Search for "content disposition" for more.

So, find the place where the web server example is sending the Content-Type and add similar code to send the Content-Disposition.  Then send your file, a byte at a time, and it will show up on the browser side as a downloaded file.


-br

PaulS

Quote
The easiest way is to read the file a byte at a time and send it to the network.

But hardly the most efficient - one character per packet involves a huge amount of overhead.

billroy

That's true, Paul, I believe there is a thread documenting the performance cost of the underlying packet-per-call approach that the library uses elsewhere on the forums.

Having said that, every web server example for Arduino I have seen posted here does it one byte at a time, and it would be unfortunate for the OP to be left with the impression he has to work out a fully buffered implementation as part of his first project.  Most people seem to find the performance acceptable, however it looks on a network monitor.

Cheers,

-br

PaulS

Quote
it would be unfortunate for the OP to be left with the impression he has to work out a fully buffered implementation as part of his first project.

True, but there are methods for reading more than one character at a time from the SD card, and there are methods for sending more than one character at a time to the client. It really is very little more work to considerably improve the performance.

One extra line of code to declare the buffer, and one extra argument on the read() and print() calls.

Go Up