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. String displayText3 = "3";
  25.  
  26. void setup(){
  27. //enable serial monitor
  28. Serial.begin(9600);
  29. //start Ethernet
  30. Ethernet.begin(mac, ip, gateway, subnet);
  31.  
  32. //initialize variable
  33. HttpHeader="";
  34. displayText1="";
  35. displayText2="";
  36. displayText3="";
  37.  
  38. lcd.begin(16,2);
  39. lcd.print("SystemOnline");
  40. Serial.print("System Online");
  41. }
  42.  
  43. void loop(){
  44. // Create a client connection
  45. EthernetClient client = server.available();
  46. if (client) {
  47. while (client.connected()) {
  48. if (client.available()) {
  49.  
  50. char c = client.read();
  51. //read MaxHeaderLength number of characters in the HTTP header
  52. //discard the rest until \n
  53. if (HttpHeader.length() < MaxHeaderLength){
  54. //store characters to string
  55. HttpHeader = HttpHeader + c; //As I understand it, it's reading the characters one by one and adding them to the string as it goes.
  56. }
  57.  
  58. //if HTTP request has ended
  59. if (c == '\n') {
  60. HttpHeader.replace("HTTP/1.1"," "); //This appears at the end of the string, so removing it doesn't mess with the character count
  61. HttpHeader.replace("+", " "); //Replacing + signs with actual spaces
  62. HttpHeader.replace("%2B", "+"); //Replacing character codes with the actual symbols
  63. HttpHeader.replace("%2F", "/");
  64. HttpHeader.replace("%21", "!");
  65. HttpHeader.replace("%3F", "?");
  66. if (HttpHeader.startsWith("GET /?text")){
  67. displayText1 = HttpHeader.substring(11,27); //Splitting the text among the two lines
  68. displayText2 = HttpHeader.substring(27,43);
  69. }
  70. lcd.clear();
  71. lcd.print(displayText1);
  72. lcd.setCursor(0,1);
  73. lcd.print(displayText2);
  74. // show the string on the monitor
  75. Serial.println("displayText1:" + displayText1);
  76. Serial.println("displayText2:" + displayText2);
  77. // start of web page
  78. client.println("HTTP/1.1 200 OK");
  79. client.println("Content-Type: text/html");
  80. client.println("<html><head></head><body>");
  81. client.println();
  82. client.print("<form method=get>");
  83. client.print("Enter in a 16 character string");
  84. client.print("<input type='text' name=text><br>");
  85. client.print("<input type=submit value=submit></form>");
  86. client.print("</body></html>");
  87.  
  88. //clearing string for next read
  89. HttpHeader="";
  90. //stopping client
  91. client.stop();
  92. }
  93. }
  94. }
  95.  
  96. }
  97. }