#include #include #define MaxHeaderLength 47 //maximum length of http header required #include #include #include Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x35, 0x70 }; //physical mac address byte ip[] = { 10,0,0, 26 }; byte gateway[] = { 10,0,0, 1 }; byte subnet[] = { 255, 255, 255, 0 }; EthernetServer server(76); //arduino server port String HttpHeader = String(MaxHeaderLength); String displayText1 = "1"; String displayText2 = "2"; void setup(){ //enable serial monitor Serial.begin(9600); //start Ethernet Ethernet.begin(mac, ip, gateway, subnet); //initialize variable HttpHeader=""; displayText1=""; displayText2=""; lcd.begin(16,2); lcd.print("SystemOnline"); Serial.print("System Online"); } void loop(){ // Create a client connection EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); //read MaxHeaderLength number of characters in the HTTP header //discard the rest until \n if (HttpHeader.length() < MaxHeaderLength){ //store characters to string HttpHeader = HttpHeader + c; HttpHeader.replace("HTTP/1.1"," "); HttpHeader.replace("+", " "); if (HttpHeader.startsWith("GET /?text")){ displayText1 = HttpHeader.substring(11,27); displayText2 = HttpHeader.substring(28,44); } } lcd.clear(); lcd.print(displayText1); lcd.setCursor(1,1); lcd.print(displayText2); //if HTTP request has ended if (c == '\n') { // show the string on the monitor Serial.println(HttpHeader); // start of web page client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); client.println(); client.print("
"); client.print("Enter in a 16 character string"); client.print("
"); client.print("
"); client.print(""); //clearing string for next read HttpHeader=""; //stopping client client.stop(); } } } } }