How to download the file in sd to the server using ethernet sheild

HI,

In my project the temperature and humidity was stored in sd card with the file name,test.txt.Now iam trying to download this file to the server using the ethernet sheild w5100.How to give the the path of this file in the html code.Anyone pls hlp me.

The first step is to run some kind of TCP/IP server on your Arduino. It can be a web (HTTP) server if you want to access the file with a web browser. See File->Examples->Ethernet->WebServer for a basic web server. You will need to modify it to return data from the text file on your SD card instead of the hard-coded text (all those client.println() calls). When that is working you can integrate your web server into your existing code as you would merge any two sketches.

johnwasser:
You will need to modify it to return data from the text file on your SD card instead of the hard-coded text (all those client.println() calls).

hi,
Actually i want to store data in sd card in every 1 minute ,but in server it should be displayed in every 20 sec.So the ethernet, sd card should read data separately.How to give the file path in htmlcode for ethernet.Hereby iam attaching the relevant part of code

code:

EthernetClient client = server.available();
if (client) {
Serial.println("new client");
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("");
client.println("");
client.println("
");
client.println(" <a href='file:///SDcard/myFile/test.csv'download='test.csv'>Download");
client.print("Humidity(%): ");
client.print(h);
client.println("
");
client.print("Temperature(*C): ");
client.print(t);
client.println("
");
client.println();
}
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
digitalWrite(10, HIGH);
delay(1000);
}
j=3;
if(j=3)
{
digitalWrite(ss, LOW);
float h = dht.readHumidity();
float t = dht.readTemperature();
File myFile = SD.open("test.csv", FILE_WRITE);
if (myFile)
{
myFile.println(h, 2);
myFile.println(t, 2);
myFile.println();
myFile.close();
}
else {
Serial.println("error opening test.csv");
}
delay (1);
digitalWrite(ss, HIGH);
}
j=0;
}

Test code for down loading a file from the SD card to a browser.

//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString; 

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  //delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

            client.println("HTTP/1.1 200 OK"); //send new page
          //client.println("Content-Type: text/html");
          client.println("Content-Type: image/jpeg");
          //client.println("Content-Type: image/gif");
          //client.println("Content-Type: application/x-javascript");
          //client.println("Content-Type: text");

          client.println();

          //File myFile = SD.open("boom.htm");
          File myFile = SD.open("HYPNO.JPG");
          //File myFile = SD.open("BLUEH_SL.GIF");
          //File myFile = SD.open("SERVOSLD.HTM");

          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();
          }
          delay(1);
          //stopping client
          client.stop();
          readString="";
        }
      }
    }
  } 
}

Is it any solution for this thread? I see in last code no link (html link) generated to in browser to click and download the file, how to make an active link which works at click and download the desired files from SD card?

antonio1:
Is it any solution for this thread? I see in last code no link (html link) generated to in browser to click and download the file, how to make an active link which works at click and download the desired files from SD card?

The browser would send a request like below tor the HYPNO.JPG file. readString would be checked to see if it contained HYPNO.JPG, and if so, that file would be read from the SD card and sent back to the browser.

http://192.168.1.102:84/HYPNO.JPG

ok, let's try to implement it. First error is
while(myFile.available()) "cannot convert SDLib from type int to type bool". Did you test the code and it's working for you?

I erased available and it's working, but it's not I was expected. At the loading page the file is listed on the page, it is a text file in my case. Lots of chars on the page, but I need to save the file as it is on SD to my PC.

"Did you test the code and it's working for you?"

It worked back in 2012, but sometimes things change. The "cannot convert SDLib from type int to type bool" error code indicate you may be trying something different.

the error was normal, as I said I tried something different replacing this "while(myFile.available())" with this "while(myFile)".
But the result is not the desired one, because the file from SD, which is text in my case, it's filling the web page with no space between lines and chars. I want to have a popup with downloading the file from SD to the PC not showing in html.

Do you have any idea?