Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
- byte ip[] = { 192, 168, 1, 188 }; // ip in lan
- byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
- byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
- EthernetServer server(8089); //server port
- String readString;
- const int ledPin = 28;
- int buttonState0 = 0;
- int buttonState1 = 0;
- void setup(){
- pinMode(28, OUTPUT); //pin selected to control
- //start Ethernet
- Ethernet.begin(mac, ip, gateway, gateway, subnet);
- server.begin();
- //enable serial data print
- Serial.begin(9600);
- Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
- }
- void loop(){
- // Create a client connection
- EthernetClient 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;
- //Serial.print(c);
- }
- //if HTTP request has ended
- if (c == '\n') {
- ///////////////
- Serial.println(readString); //print to serial monitor for debuging
- client.println("HTTP/1.1 200 OK"); //send new page
- client.println("Content-Type: text/html");
- client.println();
- client.println("<HTML>");
- client.println("<HEAD>");
- client.println("<TITLE>Arduino</TITLE>");
- client.println("</HEAD>");
- client.println("<BODY>");
- client.println("<H1><center>ARDUINO WEB BUTTON</center></H1>");
- client.println("<br>");
- // custom buttons
- 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>>");
- 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>>");
- client.println("</BODY>");
- client.println("</HTML>");
- delay(1);
- //stopping client
- client.stop();
- buttonState0 = readString.indexOf('ON') >0;
- buttonState1 = readString.indexOf('OFF') >0;
- if (buttonState0 == HIGH) {
- digitalWrite(ledPin, HIGH);
- }
- if (buttonState1 == HIGH){
- digitalWrite(ledPin, LOW);
- }
- //clearing string for next read
- readString="";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement