Want more features on Pastebin? Sign Up, it's FREE!
Guest

Textual Display Over Network

By: a guest on Dec 23rd, 2013  |  syntax: C++  |  size: 2.51 KB  |  views: 516  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. #define MaxHeaderLength 47    //maximum length of http header required
  5.  
  6. #include <Wire.h>
  7. #include <Adafruit_MCP23017.h>
  8. #include <Adafruit_RGBLCDShield.h>
  9. Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
  10.  
  11. byte mac[] = {
  12.   0x90, 0xA2, 0xDA, 0x0D, 0x35, 0x70 }; //physical mac address
  13. byte ip[] = {
  14.   10,0,0, 26 };
  15. byte gateway[] = {
  16.   10,0,0, 1 };
  17. byte subnet[] = {
  18.   255, 255, 255, 0 };
  19. EthernetServer server(76); //arduino server port
  20.  
  21. String HttpHeader = String(MaxHeaderLength);
  22. String displayText1 = "1";
  23. String displayText2 = "2";
  24.  
  25. void setup(){
  26.   //enable serial monitor
  27.   Serial.begin(9600);
  28.   //start Ethernet
  29.   Ethernet.begin(mac, ip, gateway, subnet);
  30.  
  31.   //initialize variable
  32.   HttpHeader="";
  33.   displayText1="";
  34.   displayText2="";
  35.  
  36.   lcd.begin(16,2);
  37.   lcd.print("SystemOnline");
  38.   Serial.print("System Online");
  39. }
  40.  
  41. void loop(){
  42.   // Create a client connection
  43.   EthernetClient client = server.available();
  44.   if (client) {
  45.     while (client.connected()) {
  46.       if (client.available()) {
  47.  
  48.         char c = client.read();
  49.         //read MaxHeaderLength number of characters in the HTTP header
  50.         //discard the rest until \n
  51.         if (HttpHeader.length() < MaxHeaderLength){
  52.           //store characters to string
  53.          HttpHeader = HttpHeader + c;
  54.          HttpHeader.replace("HTTP/1.1"," ");
  55.          HttpHeader.replace("+", " ");
  56.           if (HttpHeader.startsWith("GET /?text")){
  57.             displayText1 = HttpHeader.substring(11,27);
  58.             displayText2 = HttpHeader.substring(28,44);
  59.           }
  60.         }
  61.         lcd.clear();
  62.         lcd.print(displayText1);
  63.         lcd.setCursor(1,1);
  64.         lcd.print(displayText2);
  65.  
  66.         //if HTTP request has ended
  67.         if (c == '\n') {
  68.           // show the string on the monitor
  69.           Serial.println(HttpHeader);
  70.           // start of web page
  71.           client.println("HTTP/1.1 200 OK");
  72.           client.println("Content-Type: text/html");
  73.           client.println("<html><head></head><body>");
  74.           client.println();
  75.           client.print("<form method=get>");
  76.           client.print("Enter in a 16 character string");
  77.           client.print("<input type='text' name=text><br>");
  78.           client.print("<input type=submit value=submit></form>");
  79.           client.print("</body></html>");
  80.  
  81.           //clearing string for next read
  82.           HttpHeader="";
  83.           //stopping client
  84.           client.stop();
  85.         }
  86.       }
  87.     }
  88.  
  89.   }
  90. }
clone this paste RAW Paste Data