Go Down

Topic: SD card website controlling output pins (Read 519 times) previous topic - next topic

jmsgarton

Hello guys, I am trying to put an index.htm onto an SD card for the Arduino to run from but within the index.htm document i want it to be able to turn pins on and off. So far I have got it to work without the SD card, please see below for code. I am wanting to take the website page coding out of the arduino code and put it onto an SD card. can someone help with this?

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 100 };
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(84);

String readString;

void setup(){

 pinMode(7, OUTPUT);
 Ethernet.begin(mac, ip, gateway, subnet);
 server.begin();
 Serial.begin(9600);
 Serial.println("servertest1");
}

void loop(){
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100) {
         readString += c;
       }

       if (c == '\n') {

         Serial.println(readString);

           if(readString.indexOf('?') >=0) {
              client.println("HTTP/1.1");
              client.println();
              client.println();  
            }
            else {
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();

         client.println("<HTML>");
         client.println("<HEAD>");
         client.println("<TITLE>Arduino Game Setup Menu</TITLE>");
         client.println("<style type=\"text/css\"/>");
         client.println("body {");
         client.println("background-color: #CCC;");
         client.println("}");
         client.println("</style>");
         client.println("</HEAD>");
         client.println("<BODY>");

         client.println("<H1>Arduino Game Setup Menu</H1>");
         
         client.println("<p>LED");
         client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>");
         client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>");
         client.println("<hr>");

         client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
         client.println("</IFRAME>");

         client.println("</BODY>");
         client.println("</HTML>");
            }

         delay(1);
         client.stop();

         if(readString.indexOf("on") >0)
         {
           digitalWrite(7, HIGH);
           Serial.println("Led On");
         }
         if(readString.indexOf("off") >0)
         {
           digitalWrite(7, LOW);
           Serial.println("Led Off");
         }
         readString="";

       }
     }
   }
 }
}


The index.htm code would look like this

Code: [Select]
<HTML>
<HEAD>
<TITLE>Arduino Game Setup Menu</TITLE>
<style type="text/css"/>
body {
background-color: #CCC;
}
</style>
</HEAD>
<BODY>
<H1>Arduino Game Setup Menu</H1>
<p>LED
<a href="/?on" target="inlineframe">ON</a>
<a href="/?off" target="inlineframe">OFF</a>
<hr>
<IFRAME name=inlineframe style="display:none" >
</IFRAME>
</BODY>
</HTML>


I am just trying to keep it simple for now using hyperlinks rather than scripts on the websites like previously found on youtube videos. can someone please help me convert my arduino code into something which would work via the SD card.

PaulS

Quote
I am wanting to take the website page coding out of the arduino code

Good idea.

Quote
and put it onto an SD card.

Also a good idea.

Quote
can someone help with this?

Send me the SD card, and I'll create the index.htm file on it.

Now, really, what is it you need help with? The Arduino sill has to detect that the GET request is a request for index.htm. If it is, then the Arduino has to open the file on the SD card, read it's contents (using a buffer) and send the data to the client that made the request. When the end of the file is reached, you need to close the file.

Go Up