Advertisement
Guest User

Untitled

a guest
May 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. //zoomkat 12-08-12
  2. //get submit box code
  3. //for use with IDE 1.0
  4. //open serial monitor to see what the arduino receives
  5. //use the \ slash to escape the " in the html or use a '
  6. //address will look like http://192.168.1.102:84 when submited
  7. //for use with W5100 based ethernet shields
  8. //note that the below bug fix may be required
  9. // http://code.google.com/p/arduino/issues/detail?id=605
  10.  
  11. #include <SPI.h>
  12. #include <Ethernet.h>
  13.  
  14. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  15. byte ip[] = { 192, 168, 1, 102 }; // ip in lan
  16. byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
  17. byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
  18. EthernetServer server(84);; //server port
  19.  
  20. String readString;
  21.  
  22. //////////////////////
  23.  
  24. void setup(){
  25.  
  26. pinMode(5, OUTPUT); //pin selected to control
  27. //start Ethernet
  28. Ethernet.begin(mac, ip, gateway, gateway, subnet);
  29. server.begin();
  30.  
  31. //enable serial data print
  32. Serial.begin(9600);
  33. Serial.println("server text box test1"); // so I can keep track of what is loaded
  34. }
  35.  
  36. void loop(){
  37. // Create a client connection
  38. EthernetClient client = server.available();
  39. if (client) {
  40. while (client.connected()) {
  41. if (client.available()) {
  42. char c = client.read();
  43.  
  44. //read char by char HTTP request
  45. if (readString.length() < 100) {
  46.  
  47. //store characters to string
  48. readString += c;
  49. //Serial.print(c);
  50. }
  51.  
  52. //if HTTP request has ended
  53. if (c == '\n') {
  54.  
  55. ///////////////
  56. Serial.println(readString); //see what was captured
  57.  
  58. //now output HTML data header
  59.  
  60. client.println("HTTP/1.1 200 OK");
  61. client.println("Content-Type: text/html");
  62. client.println();
  63.  
  64. client.println("<HTML>");
  65. client.println("<HEAD>");
  66. client.println("<TITLE>Arduino GET test page</TITLE>");
  67. client.println("</HEAD>");
  68. client.println("<BODY>");
  69.  
  70. client.println("<H1>HTML form GET example</H1>");
  71.  
  72. client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page
  73.  
  74. client.println("Pin 5 'on5' or 'off5': <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'><BR>");
  75.  
  76. client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Change Pin 5!'>");
  77.  
  78. client.println("</FORM>");
  79.  
  80. client.println("<BR>");
  81.  
  82. client.println("</BODY>");
  83. client.println("</HTML>");
  84.  
  85. delay(1);
  86. //stopping client
  87. client.stop();
  88.  
  89. /////////////////////
  90. if(readString.indexOf("on5") >0)//checks for on
  91. {
  92. digitalWrite(5, HIGH); // set pin 5 high
  93. Serial.println("Led On");
  94. }
  95. if(readString.indexOf("off5") >0)//checks for off
  96. {
  97. digitalWrite(5, LOW); // set pin 5 low
  98. Serial.println("Led Off");
  99. }
  100. //clearing string for next read
  101. readString="";
  102.  
  103. }
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement