I am carrying out this project in which the arduino acts as web server and hosts a website in which I show the constantly updated temperature of a laboratory.
The problem is running all this code in the arduino, memory runs out easily.
void loop() {
int value= analogRead(PIN_LM35);
float temperature= value/ 2.046;
myFile = SD.open("temperature.txt");
if (myFile) {
Serial.println(temperature);
}
myFile.close();
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(F("HTTP/1.1 200 OK")); //send new page
client.println(F("Content-Type: text/html"));
client.println();
refreshcounter=refreshcounter+1;
client.println(F("<HTML>"));
client.println(F("<HEAD>"));
client.print(F("<meta http-equiv=\"refresh\" content=\"2\">"));
client.println(F("<meta name='apple-mobile-web-app-capable' content='yes' />"));
client.println(F("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"));
client.println(F("<TITLE>TEMPERATURE SENSOR LAB01</TITLE>"));
client.println(F("</HEAD>"));
client.println(F("<BODY>"));
client.println(F("<H1>TEMPERATURE SENSOR LAB01</H1>"));
client.println(F("<hr />"));
client.println(F("<br />"));
client.println(F("<H2>Arduino with Ethernet Shield</H2>"));
client.println(F("<br />"));
if(temperatura<24){
client.println("<p style=\"font-size:50px; color:#8eff59; font-weight:bold; font-style:italic;\">");
client.println(temperature);
client.println("</p>");
}
else if(temperature>=24 && temperature<=26){
client.println("<p style=\"font-size:50px; color:#ffbc03; font-weight:bold; font-style:italic;\">");
client.println(temperature);
client.println("</p>");
}
else{
client.println("<p style=\"font-size:50px; color:#ff0303; font-weight:bold; font-style:italic;\">");
client.println(temperature);
client.println(F("<H2>It is recommended to activate the air conditioner.</H2>"));
client.println("</p>");
}
client.println(F("<p style=\"font-size:30px; color:#000000; font-weight:bold; ;\">Date/Time: <span id=\"datetime\"></span></p>"));
client.println(F("<script>"));
client.println(F("var dt = new Date();"));
client.println(F("document.getElementById(\"datetime\").innerHTML = ((\"0\"+dt.getDate()).slice(-2)) +\".\"+ ((\"0\"+(dt.getMonth()+1)).slice(-2)) +\".\"+ (dt.getFullYear()) +\" \"+ ((\"0\"+dt.getHours()).slice(-2)) +\":\"+ ((\"0\"+dt.getMinutes()).slice(-2));"));
client.println(F("</script>"));
client.println("<svg width=\"1000\" height=\"250\">");
client.println("<rect width=\"150\" height=\"5\" fill=\"gray\">");
client.println("<animate attributeName=\"x\" from = \"0\" to =\"10000\" dur=\"10s\" fill=\"freeze\" />");
client.println("</rect");
client.println("</svg>");
client.println("<br />");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//clearing string for next read
readString="";
}
}
}
}
}
I thought to save memory to put all the code of the web page in an external sd. However, I don’t really know how to use it from SD card.
The problem that stops me is the fact that the site does not have to be static but constantly updated with new temperature data.
How can I do that?