Hi!
im new member here..
i have a problem with my arduino ethernet. i have a html web on microsd card and i create a .txt file on microsd card with humidity and temperature. But when i see on ethernet my html web, i cant see the temperature and humidity. I have tested on PC and there its working... you can see web.jpg to see image. I dont know why it doesnt work on Arduino
Could someone help me?
Thanks!
this is my code
/*
*
*/
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h> //libreria para el control del lector SD
#include <dht.h> // libreria con la que trabaja el sensor de temp y hum
#define dht_dpin 4
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 111); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
File webFile;
dht DHT;
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
DHT.read11(dht_dpin);
Serial.begin(9600);
Serial.print("Initializing SD card...");
}
void loop()
{
int h = DHT.humidity; //Guarda la lectura de la humedad en la variable float h
int t = DHT.temperature; //Guarda la lectura de la temperatura en la variable float t
// Comprobamos si lo que devuelve el sensor es valido, si no son numeros algo esta fallando
// if (isnan(t) || isnan(h)) // funcion que comprueba si son numeros las variables indicadas
// {
// Serial.println("Fallo al leer del sensor DHT"); //Mostramos mensaje de fallo si no son numeros
// } else {
//Mostramos mensaje con valores actuales de humedad y temperatura, asi como maximos y minimos de cada uno de ellos
// }
// make a string for assembling the data to log:
String dataString = "";
Serial.println("Guardant");
dataString += String((int) h,DEC);
dataString += "% HR - ";
dataString += String((int) t,DEC);
dataString += " graus Celsius";
Serial.println("acaba string");
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.print("grabado :");
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
dataFile.close();
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
//La lectura de la temperatura o de la humedad lleva sobre 250 milisegundos
// La lectura del sensor tambien puede estar sobre los 2 segundos (es un sensor muy lento)
if (!SD.begin(4))
{
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
Serial.println("Humidity and temperature\n\n");
if (!SD.exists("web/index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
delay(4000);
Serial.println("Removing datalog.txt...");
SD.remove("datalog.txt");
if (SD.exists("datalog.txt")){
Serial.println("datalog.txt exists.");
}
else {
Serial.println("datalog.txt doesn't exist.");
}
delay(3000);
}