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 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:
   while (!Serial) {
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");

  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.print("server is at ");

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

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
  Serial.println("initialization 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:
           Serial.print("Vochtigheid = ");
           Serial.print("%  ");
           Serial.print("Temperatuur = ");


           File dataFile = SD.open("Icon.png");

           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           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("<BODY bgcolor=\"#273B46\">");
           client.println("<br />");   
           client.println("<p><font color=\"white\">Temperatuur = </p>");  
           client.println("<p><font color=\"white\">Vochtigheid = </p>");  
           client.println("<br />"); 

           Temp = 0;


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

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
    for (uint8_t i = 0; i < numTabs; i++) {
    if (entry.isDirectory()) {
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.println(entry.size(), DEC);
  • Are Apple computers missing the function for copy pasting the code?
    – gre_gor
    May 30, 2017 at 18:30
  • Try a simpler file name e.g. ICON.PNG. The SD library might not support extended names. May 30, 2017 at 19:02
  • You have to write code that responds to the http request for the image and load the image (using the SD library) and pass it on to the web browser in the right format.
    – Majenko
    May 30, 2017 at 19:46
  • @gre_gor yeah sorry for the screenshot, i asked the question on my phone and had that screenshot. May 30, 2017 at 20:20
  • @Majenko Do yo have code? I don't find my way May 30, 2017 at 20:21

2 Answers 2


The Arduino uses the 8.3 File Format. meaning that your filename must not be more than 8 characters and the file extension must not be more than 3 characters.

eg: picture1.png 12345678.123

Hope that helps.

I have been toying with this for the last few days, and managed to find out that it uses the 8.3 format.

Also the index.html must also be in the 8.3 format. so index.htm

Hope that helps.


You are reading the HTTP request into readString. You need to parse that request to see what is actually being requested.

If the URL being requested is "icon.png" then you need to open the file on the SD card and send the data back as a properly crafted HTTP response - something in the form:

HTTP/1.1 200 OK
Content-type: image/png
Content-length: <file size here>
Connection: close

<Raw PNG data>

The first line of the readString will contain the request:

GET HTTP/1.1 /icon.png

You needt to split that up and find what the request is. You could trap specific entries (/, /index.html, etc) and serve those as specifically crafted responses, and all other unmatched requests you could forward on to your SD card reading code. You should, though, extract the file extension and match it to a MIME time so you can set the Content-Type header correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.