how to update the data in a file to a link

Hi,
iam doing the project to monitoring the temperature and humidity using dht 22 sensor.In my project iam trying to store data in sd card and display in the ethernet.Also provide a link in the ethernet to showing the data stored in the sd card.But its not updating the data in that link. How to link sd file with ethernet.Hereby I am attaching the code.Anyone pls suggest some methods to trobleshoot this problem.

code:

#include <SPI.h>
#include "DHT.h"
int ss=4;
#include <Ethernet.h>
#include <LiquidCrystal.h>
#include <SD.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(A5,A4,A3,A2,A1,A0);
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36};
IPAddress ip(192, 168, 1, 49);
EthernetServer server(80);
File myFile;
int i,j;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(ss)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
File myFile;
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile)
{
myFile.print("RH(%) Temp(*C)");
myFile.println();
myFile.close();
}
pinMode(2,INPUT);
pinMode(10,OUTPUT);
digitalWrite(10, HIGH);
dht.begin();
SPI.begin();
Ethernet.begin(mac,ip);
server.begin();
lcd.begin(16, 2);
lcd.clear();
}
void loop()
{
for(j=0;j<3;j++)
{
digitalWrite(ss, HIGH);
float h = dht.readHumidity();
float t = dht.readTemperature();

for(i=0;i<20;i++)
{
float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
digitalWrite(A3, LOW);
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);
delay(100);
lcd.setCursor(0,0);
lcd.print("Humidity %:");
lcd.print(h);
lcd.setCursor(0,1);
lcd.print("Temp(*c):");
lcd.print(t);
delay(1000);
}
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
digitalWrite(10, LOW);
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("Content-Disposition: attachment;filename="test.txt"") ; client.println("Connection: close");
//client.println("Refresh: 20"); // refresh the page automatically every 60 sec
client.println();
client.println("");
client.println("");
client.println("Data of Sensor");
client.print("Humidity(%): ");
client.print(h);
client.println("
");
client.print("Temperature(*C): ");
client.print(t);
client.println("
");
client.println("test.txt");
client.println("");
break;
}
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.txt", FILE_WRITE);
if (myFile)
{

myFile.print(h, 2);
myFile.print(" ");
myFile.print(t, 2);
myFile.println();
myFile.close();
}
else {
Serial.println("error opening test.txt");
}
delay (1);
digitalWrite(ss, HIGH);
}
j=0;
}

sruthy:
Hi,
In my project iam trying to store data in sd card and display in the ethernet.Also provide a link in the ethernet to showing the data stored in the sd card.But its not updating the data in that link. How to link sd file with ethernet.

The usage of "Ethernet" in your described intent is unclear - for my little brain anyway.

Maybe if you described your intent step by step in terms of the hardware (e.g. lcd screen, serial monitor etc )you are using, it may be clearer.

Hi,

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks Tom.... :slight_smile:

[/code]

TomGeorge:
Can you please post a copy of your sketch, using code tags?

#include <SPI.h>
#include "DHT.h"
int ss=4;
#include <Ethernet.h>
#include <LiquidCrystal.h>
#include <SD.h>
#define DHTPIN 2     
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(A5,A4,A3,A2,A1,A0);
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36};
IPAddress ip(192, 168, 1, 49);
EthernetServer server(80);
File myFile;
int i,j;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
    if (!SD.begin(ss)) {
Serial.println("Card failed, or not present");
     return;
  }
  Serial.println("card initialized.");
  File myFile;
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile)
  {
   myFile.print("RH(%)   Temp(*C)");
   myFile.println();
   myFile.close();
    }
  pinMode(2,INPUT);
  pinMode(10,OUTPUT);
  digitalWrite(10, HIGH);
  dht.begin();
  SPI.begin();
Ethernet.begin(mac,ip);
  server.begin();
  lcd.begin(16, 2);
  lcd.clear();
}
 void loop()
 {
   for(j=0;j<3;j++)
 {
 digitalWrite(ss, HIGH);
 float h = dht.readHumidity();
 float t = dht.readTemperature();

 for(i=0;i<20;i++)
   {
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 
          if (isnan(h) || isnan(t))
   {
   Serial.println("Failed to read from DHT sensor!");
    return;
 }
     digitalWrite(A0, LOW);
     digitalWrite(A1, LOW);
     digitalWrite(A2, LOW);
     digitalWrite(A3, LOW);
     digitalWrite(A4, LOW);
     digitalWrite(A5, LOW);
     delay(100);
   lcd.setCursor(0,0);
   lcd.print("Humidity %:");
   lcd.print(h);
   lcd.setCursor(0,1);
   lcd.print("Temp(*c):");
   lcd.print(t);
   delay(1000);
   }
  if (isnan(h) || isnan(t))
    {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
   digitalWrite(10, LOW);
   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("Refresh: 20");  
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
  client.println("<title>Data of Sensor</title>");
  client.print("Humidity(%): ");
  client.print(h);
  client.println("
");
  client.print("Temperature(*C): ");
  client.print(t);
  client.println("
");
  client.println("<a href='http:Data of Sensor'>test.txt</a>");
  client.println("</html>");
          break;
        }
        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.txt", FILE_WRITE);
   if (myFile)
   {
   
    myFile.print(h, 2);
    myFile.print("     ");
    myFile.print(t, 2);
    myFile.println();
    myFile.close();
     }
  else {
    Serial.println("error opening test.txt");
  }
  delay (1);
  digitalWrite(ss, HIGH);
 }
 j=0;
}

aisc:
The usage of "Ethernet" in your described intent is unclear - for my little brain anyway.

Iam using an ethernet sheild in this project to display temperature and humidity in the perticular ip address.So,what iam actually trying is that, when i click in the link provided,(test.txt)the file in the sd should be displayed in that ip.Pls help me to complete this project.