Skip to main content
added 4646 characters in body
Source Link

I tried using the SD.h library but I am not able to use the library for my code. This is a picture of my code.

My Code

#include <dht.h>
#define dht_apin A0                                  

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

File root;
// initialize the library with the numbers of the interface pins

byte mac[] = {I HIDE THIS};   // physical mac address
byte ip[] = {I HIDE THIS};                        // ip in lan (that's what you need to use in your browser. ("I HIDE THIS")
byte gateway[] = {I HIDE THIS};                   // internet access via router
byte subnet[] = {I HIDE THIS};                  // subnet mask
EthernetServer server(10000);                          // server port  
String readString;
dht DHT;
int Temp;

void setup() {
  // set up the LCD's number of columns and rows:
  Serial.begin(9600);
   while (!Serial) {
    ; 
  }
  delay(100);
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
 
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

    Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");


 Serial.println("done!");


}

void loop() {


  
  EthernetClient client = server.available();    // Create a client connection
  if (client) {
    while (client.connected()) { 
      if (client.available()) {
        char c = client.read();
        
        if (readString.length() < 100) {    //read char by char HTTP request
          readString += c;
         }
         
         if (c == '\n') {      //if  HTTP request has ended
          Temp = 0;
  switch (Temp){
  case 0:
           DHT.read22(dht_apin);
           Serial.print("Vochtigheid = ");
           Serial.print(DHT.humidity);
           Serial.print("%  ");
           Serial.print("Temperatuur = ");
           Serial.print(DHT.temperature);

            
           delay(500);


           File dataFile = SD.open("Icon.png");
           
           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<HTML>");
           client.println("<HEAD>");
           client.println("<TITLE>Home Damian</TITLE>");
           client.println("<meta http-equiv=\"refresh\"content=\"1 \">");
           client.println("<meta name=\"apple-mobile-web-app-title\" content=\"Home\">");
           client.println("<link rel=\"apple-touch-icon\" href=\"/Icon.png"/>");
           client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
           client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\">");
           client.println("</HEAD>");
           client.println("<BODY bgcolor=\"#273B46\">");
           client.println("<br />");   
           client.println("<p><font color=\"white\">Temperatuur = </p>");  
           client.println(DHT.temperature,1); 
           client.print("&#176C"); 
           client.println("<p></p>");
           client.println("<p><font color=\"white\">Vochtigheid = </p>");  
           client.println(DHT.humidity,1);
           client.print("%"); 
           client.println("<br />"); 
           client.println("</BODY>");
           client.println("</HTML>");
          
           delay(1000);
           Serial.println("OK");
           Temp = 0;
           client.stop();

         }
       }
     }
   }
  }
}


void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

I tried using the SD.h library but I am not able to use the library for my code. This is a picture of my code.

My Code

I tried using the SD.h library but I am not able to use the library for my code. This is my code.

#include <dht.h>
#define dht_apin A0                                  

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

File root;
// initialize the library with the numbers of the interface pins

byte mac[] = {I HIDE THIS};   // physical mac address
byte ip[] = {I HIDE THIS};                        // ip in lan (that's what you need to use in your browser. ("I HIDE THIS")
byte gateway[] = {I HIDE THIS};                   // internet access via router
byte subnet[] = {I HIDE THIS};                  // subnet mask
EthernetServer server(10000);                          // server port  
String readString;
dht DHT;
int Temp;

void setup() {
  // set up the LCD's number of columns and rows:
  Serial.begin(9600);
   while (!Serial) {
    ; 
  }
  delay(100);
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
 
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

    Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");


 Serial.println("done!");


}

void loop() {


  
  EthernetClient client = server.available();    // Create a client connection
  if (client) {
    while (client.connected()) { 
      if (client.available()) {
        char c = client.read();
        
        if (readString.length() < 100) {    //read char by char HTTP request
          readString += c;
         }
         
         if (c == '\n') {      //if  HTTP request has ended
          Temp = 0;
  switch (Temp){
  case 0:
           DHT.read22(dht_apin);
           Serial.print("Vochtigheid = ");
           Serial.print(DHT.humidity);
           Serial.print("%  ");
           Serial.print("Temperatuur = ");
           Serial.print(DHT.temperature);

            
           delay(500);


           File dataFile = SD.open("Icon.png");
           
           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<HTML>");
           client.println("<HEAD>");
           client.println("<TITLE>Home Damian</TITLE>");
           client.println("<meta http-equiv=\"refresh\"content=\"1 \">");
           client.println("<meta name=\"apple-mobile-web-app-title\" content=\"Home\">");
           client.println("<link rel=\"apple-touch-icon\" href=\"/Icon.png"/>");
           client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
           client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\">");
           client.println("</HEAD>");
           client.println("<BODY bgcolor=\"#273B46\">");
           client.println("<br />");   
           client.println("<p><font color=\"white\">Temperatuur = </p>");  
           client.println(DHT.temperature,1); 
           client.print("&#176C"); 
           client.println("<p></p>");
           client.println("<p><font color=\"white\">Vochtigheid = </p>");  
           client.println(DHT.humidity,1);
           client.print("%"); 
           client.println("<br />"); 
           client.println("</BODY>");
           client.println("</HTML>");
          
           delay(1000);
           Serial.println("OK");
           Temp = 0;
           client.stop();

         }
       }
     }
   }
  }
}


void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}
Source Link

Get image from Arduino Ethernet Shield sd card

I have a code that uploads the temperature and humidity from a dht22 to a website.

Now i want to add an image to the "add to homescreen" button in safari on ios.

Apple has a html code for this:

<link rel="apple-touch-icon" href="/custom_icon.png">

Now I want the "custom_icon.png" to be a link or some other method to a file "Icon.png" on the ethernet shield sd card.

I think I need something like this:

client.println("<link rel=\"apple-touch-icon\" href=\"/Icon.png\">");

But this doensn't work. It doesn't give an error, but its just the wrong way to acces that file.

I tried using the SD.h library but I am not able to use the library for my code. This is a picture of my code.

My Code