Advertisement
Guest User

Untitled

a guest
Apr 10th, 2011
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Client.h>
  3. #include <Ethernet.h>
  4. #include <Server.h>
  5. #include <Udp.h>
  6. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  7. byte ip[] = { 192, 168, 1, 200 }; // ip in lan
  8. byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
  9. byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
  10. Server server(80); //server port
  11. byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
  12.  
  13. int ledPin = 5; // LED pin
  14. int ledPin2=6;
  15. int ledPin3=7;
  16.  
  17.  
  18.  
  19. char link[]="http://www.scienceprog.com/"; //link data
  20. String readString = String(30); //string for fetching data from address
  21.  
  22.  
  23. boolean LEDON = false; //LED status flag
  24. boolean LED2ON=false;
  25. boolean LED3ON=false;
  26.  
  27.  
  28.  
  29. void setup(){
  30. //start Ethernet
  31. Ethernet.begin(mac, ip, gateway, subnet);
  32. //Set pin 4 to output
  33.  
  34. pinMode(ledPin, OUTPUT); //Set pin 5 to output
  35. pinMode(ledPin2, OUTPUT); //Set pin 6 to output
  36. pinMode(ledPin3, OUTPUT); //Set pin 7 to output
  37.  
  38. //enable serial datada print
  39. Serial.begin(9600);
  40. }
  41. void loop(){
  42. // Create a client connection
  43. Client client = server.available();
  44. if (client) {
  45. while (client.connected()) {
  46. if (client.available()) {
  47. char c = client.read();
  48. //read char by char HTTP request
  49. if (readString.length() < 100)
  50. {
  51. //store characters to string
  52. readString += c; //replaces readString.append(c);
  53. }
  54. //output chars to serial port
  55. Serial.print(c);
  56. //if HTTP request has ended
  57. if (c == '\n') {
  58. //dirty skip of "GET /favicon.ico HTTP/1.1"
  59. if (readString.indexOf("?") <0)
  60. {
  61. //skip everything
  62. }
  63. else
  64. //lets check if LED should be lighted
  65. if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
  66. {
  67. //led has to be turned ON
  68. digitalWrite(ledPin, HIGH); // set the LED on
  69. LEDON = true;
  70.  
  71.  
  72. }else{
  73. //led has to be turned OFF
  74. digitalWrite(ledPin, LOW); // set the LED OFF
  75. LEDON = false;
  76.  
  77. }
  78.  
  79. if(readString.indexOf("M=1")>=0)
  80. {
  81. //led has to be turned ON
  82. digitalWrite(ledPin2, HIGH); // set the LED on
  83. LED2ON = true;
  84.  
  85. }else{
  86. //led has to be turned OFF
  87. digitalWrite(ledPin2, LOW); // set the LED OFF
  88. LED2ON = false;
  89.  
  90.  
  91.  
  92. }
  93.  
  94.  
  95. if(readString.indexOf("N=1")>=0)
  96. {
  97. //led has to be turned ON
  98. digitalWrite(ledPin3, HIGH); // set the LED on
  99. LED3ON = true;
  100.  
  101.  
  102. }else{
  103. //led has to be turned OFF
  104. digitalWrite(ledPin3, LOW); // set the LED OFF
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. // now output HTML data starting with standart header
  113. client.println("HTTP/1.1 200 OK");
  114. client.println("Content-Type: text/html");
  115. client.println();
  116. //set background to yellow
  117. client.print("<body style=background-color:White>");
  118. //send first heading
  119. client.println("<font color='red'><h1>Group 10 Server</font></h1>");
  120. client.println("<hr />");
  121. client.println("<hr />");
  122.  
  123.  
  124.  
  125.  
  126. //testprog by me
  127. // <input type="checkbox" name="team" value="team" checked>Spurs<br>
  128.  
  129. client.println("<h2>LED ALL</h2>"); //......................
  130.  
  131. client.println("<font color='red'><h3>Which all you want to ON</font></h3>");
  132. client.println("<hr />");
  133. client.println("<hr />");
  134.  
  135. client.println("<h3>LED 1</h3><form method=get name=LED><input type=checkbox name=L value=1>ON<br><input type=checkbox name=L value=0>OFF<br><h3>LED 2</h3><input type=checkbox name=M value=1>ON<br><input type=checkbox name=M value=0>OFF<br><h3>LED 3</h3><input type=checkbox name=N value=1>ON<br><input type=checkbox name=N value=0>OFF<br><input type=submit value=submit></form>");
  136. // client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED1<br><input type=checkbox name=M value=1>LED2<br><input type=checkbox name=N value=1>LED3<br><input type=submit value=submit></form>");
  137. client.println("<br />");
  138. // client.println("<form method=get name=LED><input type=checkbox name=L value=0>OFF<br><input type=submit value=submit></form>");
  139. //client.println("<br />");
  140.  
  141. readString="";
  142.  
  143.  
  144.  
  145.  
  146.  
  147. //stopping client
  148. client.stop();
  149. }
  150. }
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement