Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Client.h>
- #include <Ethernet.h>
- #include <Server.h>
- #include <Udp.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
- byte ip[] = { 192, 168, 1, 200 }; // ip in lan
- byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
- byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
- Server server(80); //server port
- byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
- int ledPin = 5; // LED pin
- int ledPin2=6;
- int ledPin3=7;
- char link[]="http://www.scienceprog.com/"; //link data
- String readString = String(30); //string for fetching data from address
- boolean LEDON = false; //LED status flag
- boolean LED2ON=false;
- boolean LED3ON=false;
- void setup(){
- //start Ethernet
- Ethernet.begin(mac, ip, gateway, subnet);
- //Set pin 4 to output
- pinMode(ledPin, OUTPUT); //Set pin 5 to output
- pinMode(ledPin2, OUTPUT); //Set pin 6 to output
- pinMode(ledPin3, OUTPUT); //Set pin 7 to output
- //enable serial datada print
- Serial.begin(9600);
- }
- void loop(){
- // Create a client connection
- Client client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- //read char by char HTTP request
- if (readString.length() < 100)
- {
- //store characters to string
- readString += c; //replaces readString.append(c);
- }
- //output chars to serial port
- Serial.print(c);
- //if HTTP request has ended
- if (c == '\n') {
- //dirty skip of "GET /favicon.ico HTTP/1.1"
- if (readString.indexOf("?") <0)
- {
- //skip everything
- }
- else
- //lets check if LED should be lighted
- if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
- {
- //led has to be turned ON
- digitalWrite(ledPin, HIGH); // set the LED on
- LEDON = true;
- }else{
- //led has to be turned OFF
- digitalWrite(ledPin, LOW); // set the LED OFF
- LEDON = false;
- }
- if(readString.indexOf("M=1")>=0)
- {
- //led has to be turned ON
- digitalWrite(ledPin2, HIGH); // set the LED on
- LED2ON = true;
- }else{
- //led has to be turned OFF
- digitalWrite(ledPin2, LOW); // set the LED OFF
- LED2ON = false;
- }
- if(readString.indexOf("N=1")>=0)
- {
- //led has to be turned ON
- digitalWrite(ledPin3, HIGH); // set the LED on
- LED3ON = true;
- }else{
- //led has to be turned OFF
- digitalWrite(ledPin3, LOW); // set the LED OFF
- }
- // now output HTML data starting with standart header
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- //set background to yellow
- client.print("<body style=background-color:White>");
- //send first heading
- client.println("<font color='red'><h1>Group 10 Server</font></h1>");
- client.println("<hr />");
- client.println("<hr />");
- //testprog by me
- // <input type="checkbox" name="team" value="team" checked>Spurs<br>
- client.println("<h2>LED ALL</h2>"); //......................
- client.println("<font color='red'><h3>Which all you want to ON</font></h3>");
- client.println("<hr />");
- client.println("<hr />");
- 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>");
- // 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>");
- client.println("<br />");
- // client.println("<form method=get name=LED><input type=checkbox name=L value=0>OFF<br><input type=submit value=submit></form>");
- //client.println("<br />");
- readString="";
- //stopping client
- client.stop();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement