Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <LiquidCrystal.h>
  4. #include <SD.h>
  5.  
  6. byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
  7. byte ip[] = { 192, 168, 0, 31};
  8. File myFile;
  9.  
  10. char current_char;
  11. Server server(80);
  12.  
  13. LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
  14. void setup()
  15. {
  16.   Serial.begin(9600);
  17.   pinMode(10, OUTPUT);
  18.   lcd.begin(16, 2);
  19.  
  20.   Ethernet.begin(mac, ip);
  21.  
  22.   delay(1000);
  23.   server.begin();
  24.   Client client = server.available();
  25.         myFile = SD.open("index.html");
  26.        
  27.         if (myFile) {              
  28.             while (myFile.available()) {
  29.                Serial.println(myfile.read());
  30.                client.write(myFile.read());
  31.             }
  32.         }
  33.  
  34.   Serial.println("setup finished");
  35. }
  36.  
  37. void loop()
  38. {
  39.   String buffer = "";
  40.   String requesturl = "";
  41.   String buffers = "";
  42.   Client client = server.available();
  43.   if (client) {
  44.     boolean currentLineIsBlank = true;
  45.     while (client.connected()) {
  46.       while(client.available()) {
  47.         char c = client.read();
  48.         if(requesturl == ""){
  49.           buffer += c;
  50.           if(c == '\n' && buffer.startsWith("GET")){
  51.             requesturl = buffer.substring(12,buffer.length()-11);
  52.             buffer = "";
  53.            
  54.             requesturl.replace('+',' ');
  55.             requesturl.replace('%3F','?');
  56.             requesturl.replace('%21','!');
  57.            
  58.             lcd.clear();
  59.             if (requesturl.length() > 16){
  60.                lcd.print(requesturl.substring(0,16));
  61.                lcd.setCursor(0,1);
  62.                lcd.print(requesturl.substring(16,requesturl.length()));
  63.             }else{
  64.               lcd.setCursor(0,0);
  65.               lcd.print(requesturl);
  66.             }
  67.           }
  68.         }
  69.  
  70.         if (c == '\n' && currentLineIsBlank) {
  71.          
  72.         } else if (c == '\n') {
  73.           currentLineIsBlank = true;
  74.         }
  75.         else if (c != '\r') {
  76.           currentLineIsBlank = false;
  77.         }
  78.       }
  79.     }
  80.   }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement