Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1.  
  2. #include <SPI.h>
  3. #include <Ethernet.h>
  4.  
  5. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  6. byte ip[] = { 192, 168, 1, 188 }; // ip in lan
  7. byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
  8. byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
  9. EthernetServer server(8089); //server port
  10.  
  11. String readString;
  12.  
  13. const int ledPin = 28;
  14. int buttonState0 = 0;
  15. int buttonState1 = 0;
  16.  
  17. void setup(){
  18.  
  19.  
  20. pinMode(28, OUTPUT); //pin selected to control
  21. //start Ethernet
  22. Ethernet.begin(mac, ip, gateway, gateway, subnet);
  23. server.begin();
  24.  
  25. //enable serial data print
  26. Serial.begin(9600);
  27. Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
  28. }
  29.  
  30. void loop(){
  31. // Create a client connection
  32. EthernetClient client = server.available();
  33. if (client) {
  34. while (client.connected()) {
  35. if (client.available()) {
  36. char c = client.read();
  37.  
  38. //read char by char HTTP request
  39. if (readString.length() < 100) {
  40.  
  41. //store characters to string
  42. readString += c;
  43. //Serial.print(c);
  44. }
  45.  
  46. //if HTTP request has ended
  47. if (c == '\n') {
  48.  
  49. ///////////////
  50. Serial.println(readString); //print to serial monitor for debuging
  51.  
  52. client.println("HTTP/1.1 200 OK"); //send new page
  53. client.println("Content-Type: text/html");
  54. client.println();
  55.  
  56. client.println("<HTML>");
  57. client.println("<HEAD>");
  58. client.println("<TITLE>Arduino</TITLE>");
  59. client.println("</HEAD>");
  60. client.println("<BODY>");
  61.  
  62. client.println("<H1><center>ARDUINO WEB BUTTON</center></H1>");
  63.  
  64. client.println("<br>");
  65.  
  66. // custom buttons
  67.  
  68. client.print("<table align='center' border=10 bgcolor='green' ><th><h2><div onmousedown='mDown(this)' onmouseup='mUp(this)' style='background-color:'#D94A38';width:130px;height:30px;padding:10px;'>-0-</div></table>>");
  69.  
  70. client.println("<script>function mDown(obj){obj.style.backgroundColor='#1ec5e5';obj.innerHTML='ACESO';location.href='?ON'}function mUp(obj){obj.style.backgroundColor='#D94A38';obj.innerHTML='APAGADO';location.href='?OFF'}</script>>");
  71.  
  72. client.println("</BODY>");
  73. client.println("</HTML>");
  74.  
  75. delay(1);
  76. //stopping client
  77. client.stop();
  78.  
  79. buttonState0 = readString.indexOf('ON') >0;
  80. buttonState1 = readString.indexOf('OFF') >0;
  81.  
  82. if (buttonState0 == HIGH) {
  83. digitalWrite(ledPin, HIGH);
  84. }
  85. if (buttonState1 == HIGH){
  86. digitalWrite(ledPin, LOW);
  87. }
  88.  
  89. //clearing string for next read
  90. readString="";
  91.  
  92. }
  93. }
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement