Advertisement
Guest User

Untitled

a guest
Apr 12th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.42 KB | None | 0 0
  1. /*
  2. A simple web server using an Arduino Wiznet Ethernet shield.
  3. For Arduino IDE V0022 only. IDE v1.0 require mods to this code.
  4.  
  5. Original code created 18 Dec 2009
  6.  by David A. Mellis
  7.  modified 4 Sep 2010
  8.  by Tom Igoe
  9.  modified 21 Jan 2012
  10.  by Tim Dicus
  11. */
  12.  
  13. #include <SPI.h>
  14. #include <Ethernet.h>
  15. #include <LiquidCrystal.h>
  16.  
  17. // Enter a MAC address and IP address for your controller below.
  18. // The IP address will be dependent on your local network:
  19. byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
  20. byte ip[] = { 192, 168, 0, 31};
  21.  
  22. // Initialize the Ethernet server library
  23. // with the IP address and port you want to use
  24. // (port 80 is default for HTTP):
  25. char returned_message[4];
  26. Server server(80);
  27.  
  28. LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
  29. void setup()
  30. {
  31.   Serial.begin(9600);
  32.   lcd.begin(16, 2);
  33.  
  34.   // start the SD interface here if you want.
  35.   // Add the SD.h library above
  36.   // SD.begin(4);
  37.  
  38.   // start the Ethernet connection and the server:
  39.   Ethernet.begin(mac, ip);
  40.  
  41.   delay(2000);
  42.   server.begin();
  43.  
  44.   Serial.println("setup finished");
  45. }
  46.  
  47. String Between(String input, String left, String right){
  48.   int l = input.indexOf(left) + left.length();
  49.   int r = input.indexOf(right,l);
  50.  
  51.   return(input.substring(l,r));
  52. }
  53.  
  54. void loop()
  55. {
  56.   String buffer = "";
  57.   String requesturl = "";
  58.   String buffers = "";
  59.   String quellcode = "";
  60.  
  61.   // listen for incoming clients
  62.   Client client = server.available();
  63.   char incoming_shits;
  64.   if (client) {
  65.     // an http request ends with a blank line
  66.     boolean currentLineIsBlank = true;
  67.     while (client.connected()) {
  68.       while(client.available()) {
  69.         char c = client.read();
  70.         // if you've gotten to the end of the line (received a newline
  71.         // character) and the line is blank, the http request has ended,
  72.         // so you can send a reply  
  73.        
  74.         if(requesturl == ""){
  75.           buffer += c;
  76.           if(c == '\n' && buffer.startsWith("GET")){
  77.             requesturl = buffer.substring(12,buffer.length()-11);
  78.             buffer = "";
  79.            
  80.             requesturl = requesturl.replace("+"," ");
  81.             requesturl = requesturl.replace("%3F","?");
  82.             requesturl = requesturl.replace("%21","!");
  83.            
  84.             lcd.clear();
  85.             if (requesturl.length() > 16){
  86.                lcd.print(requesturl.substring(0,16));
  87.                lcd.setCursor(0,1);
  88.                lcd.print(requesturl.substring(16,requesturl.length()));
  89.             }else{
  90.               lcd.setCursor(0,0);
  91.               lcd.print(requesturl);
  92.             }
  93.           }
  94.         }
  95.  
  96.         if (c == '\n' && currentLineIsBlank) {
  97.           // send a standard http response header
  98.           client.println(F("HTTP/1.1 200 OK"));
  99.           client.println(F("Content-Type: text/html"));
  100.           client.println();
  101.            client.println(F("<!DOCTYPE html>  <html lang=\"en\">  <head>     <meta name = \"viewport\" content = \"width = 320,user(-scalable = 1, 0)initial(-Scale() = 3,)maximum-scale = 3\"</meta>   <meta charset=\"utf-8\" />    <title>WebPanel</title>    <link rel=\"stylesheet\" href=\"css/accordionmenu.css\" type=\"text/css\" media=\"screen\" />    <style type=\"text/css\">/* Reset */  .accordion, .accordion ul, .accordion li, .accordion a, .accordion span {   margin: 0;  padding: 0;     border: none;   outline: none; }  .accordion li {   list-style: none; }  /* Layout & Style */  .accordion li > a {  display: block;     position: relative;     min-width: 110px;   padding: 0 10px 0 40px;     height: 50px;   padding-top: 1.5%;      color: #fdfdfd;     font: bold 15px/32px Arial, sans-serif;     text-decoration: none;  text-shadow: 0px 1px 0px rgba(0,0,0, .35);      background: #6c6e74;    background: -moz-linear-gradient(top,  #6c6e74 0%, #4b4d51 100%);   background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6c6e74), color-stop(100%,#4b4d51));  background: -webkit-linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);     background: -o-linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);  background: -ms-linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);     background: linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);     -webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);   -moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);  box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1); }  .accordion > li:hover > a, .accordion > li:target > a, .accordion > li > a.active {    color: #3e5706;     text-shadow: 1px 1px 1px rgba(255,255,255, .2);         /*background: url(../img/active.png) repeat-x;*/    background: #a5cd4e;    background: -moz-linear-gradient(top,  #a5cd4e 0%, #6b8f1a 100%);   background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cd4e), color-stop(100%,#6b8f1a));  background: -webkit-linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);     background: -o-linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);  background: -ms-linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);     background: linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);  }  /*.accordion li > a span {  display: block;     position: absolute;     top: 7px;   right: 0;   padding: 0 10px;    margin-right: 10px;         font: normal bold 12px/18px Arial, sans-serif;  background: #404247;        -webkit-border-radius: 15px;    -moz-border-radius: 15px;   border-radius: 15px;    -webkit-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);   -moz-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);  box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1); }  .accordion > li:hover > a span, .accordion > li:target > a span, .accordion > li > a.active span {     color: #fdfdfd;     text-shadow: 0px 1px 0px rgba(0,0,0, .35);  background: #3e5706; } */  /* Images */  .accordion > li > a:before {   position: absolute;     top: 23%;   left: 0;    content: '';    width: 24px;    height: 24px;   margin: 4px 8px;        /*  background-repeat: no-repeat;   background-image: url(../img/icons.png);    background-position: 0 0;   */ }  /* .accordion li.files > a:before { background-position: 0px 0px; } .accordion li.files:hover > a:before, .accordion li.files:target > a:before, .accordion li.files > a.active:before { background-position: 0px -24px; }  .accordion li.mail > a:before { background-position: -24px 0px; } .accordion li.mail:hover > a:before, .accordion li.mail:target > a:before, .accordion li.mail > a.active:before { background-position: -24px -24px; }  .accordion li.cloud > a:before { background-position: -48px 0px; } .accordion li.cloud:hover > a:before, .accordion li.cloud:target > a:before, .accordion li.cloud > a.active:before { background-position: -48px -24px; }  .accordion li.sign > a:before { background-position: -72px 0px; } .accordion li.sign:hover > a:before, .accordion li.sign:target > a:before, .accordion li.sign > a.active:before { background-position: -72px -24px; } */  /* Sub Menu */  .sub-menu li a {    color: #797979;     text-shadow: 1px 1px 0px rgba(255,255,255, .2);     background: #e5e5e5;    border-bottom: 1px solid #c9c9c9;   -webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);   -moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);  box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1); }  .sub-menu li:hover a { background: #efefef; }  .sub-menu li:last-child a { border: none; }  .sub-menu li > a span {    color: #797979;     text-shadow: 1px 1px 0px rgba(255,255,255, .2);     background: transparent;    border: 1px solid #c9c9c9;      -webkit-box-shadow: none;   -moz-box-shadow: none;  box-shadow: none; }  .sub-menu em {     position: absolute;     top: 0;     left: 0;    margin-left: 14px;  color: #a6a6a6;     font: normal 20px/32px Arial, sans-serif; }  /* Functionality */  .accordion li > .sub-menu {   display: none;  color: white; }  .accordion li:target > .sub-menu {     display: block;     color: white; } body{background:url(img/bg.png) repeat;width:960px;margin:0 auto;font-family:Calibri;font-size:20px;}.footer{margin-top:50px;text-align:center;color:#666;font:bold 14px Arial}.footer a{color:#999;text-decoration:none}#wrapper-250{width:100%;}</style> <meta name=\"robots\" content=\"noindex,follow\" /> </head>  <body>   <div id=\"wrapper-250\">      <ul class=\"accordion\">              <li id=\"one\" class=\"files\">          <a href=\"#one\">LCD</a>          <ul class=\"sub-menu\">           <form method=\"get\" name=\"text\"><input type=\"text\" name=\"fname\" /> <input type=\"submit\" value=\"Absenden\" /><br/>Aktuell angezeigter Text: "));
  102.          
  103.           if(requesturl == " HTTP/1"){
  104.             client.print("\"LCD leer");
  105.           }else{
  106.           client.print("\"");
  107.           client.print(F(requesturl));
  108.           }
  109.          
  110.           client.print(F("\"         </ul>        </li>              <li id=\"two\" class=\"mail\">          <a href=\"#two\">test2</a>          <ul class=\"sub-menu\">           test2         </ul>        </li>              <li id=\"three\" class=\"cloud\">          <a href=\"#three\">test3</a>          <ul class=\"sub-menu\">           test3         </ul>        </li>              <li id=\"four\" class=\"sign\">          <a href=\"#four\">test4</a>          <ul class=\"sub-menu\">           test4         </ul>        </li>          </ul>        </div>      <script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></script>   <script type=\"text/javascript\">      $(document).ready(function() {        // Store variables              var accordion_head = $('.accordion > li > a'),         accordion_body = $('.accordion li > .sub-menu');        // Open the first tab on load        accordion_head.first().addClass('active').next().slideDown('normal');        // Click function        accordion_head.on('click', function(event) {          // Disable header links                  event.preventDefault();          // Show and hide the tabs on click          if ($(this).attr('class') != 'active'){           accordion_body.slideUp('normal');           $(this).next().stop(true,true).slideToggle('normal');           accordion_head.removeClass('active');           $(this).addClass('active');         }        });      });    </script>  </body>  </html>"));
  111.           client.stop();
  112.         }
  113.        
  114.         else if (c == '\n') {
  115.           // you're starting a new line
  116.           currentLineIsBlank = true;
  117.         }
  118.         else if (c != '\r') {
  119.           // you've gotten a character on the current line
  120.           currentLineIsBlank = false;
  121.         }
  122.       }
  123.     }
  124.   }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement