// Modificacion 19-12-2012 // webserver #include <SPI.h> #include <Ethernet.h> //numero de MAC //numero de ip, depende de tu red byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,2, 177); String readString = String(20); byte bandera=0; byte z; char c; int sensorReading; EthernetServer server(80); void setup() { Serial.begin(9600); while (!Serial) { } Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { c = client.read(); Serial.write(c); if(c=='?' && bandera==0) { readString=""; for(z=0;z<14;z++) { c = client.read(); readString +=c; } Serial.println(readString); colocar(); bandera=1; } if (c == '\n' && currentLineIsBlank) { // Manda la cabecera del http client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connnection: close"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); // Refresca cada 3 segundos client.println("<meta http-equiv=\"refresh\" content=\"3\">"); client.println("<big><b>Seta43_Arduino</b></big><br>"); client.print("xsetaseta@gmail.com <br>"); client.print("Control de LEDS <br>"); client.println("<hr>"); client.print("<form method=get><input type=submit name=valor value=Encender_Todos>"); client.println("<input type=submit name=valor value=Apagar_todos></form>"); client.println("<hr>"); client.print("<form method=get><input type=submit name=valor value=1DIG2>"); client.println("<input type=submit name=valor value=0DIG2> DIG2="); client.println(digitalRead(2)); client.println("</form>"); client.print("<form method=get><input type=submit name=valor value=1DIG3>"); client.println("<input type=submit name=valor value=0DIG3> DIG3="); client.println(digitalRead(3)); client.println("</form>"); client.print("<form method=get><input type=submit name=valor value=1DIG5>"); client.println("<input type=submit name=valor value=0DIG5> DIG5="); client.println(digitalRead(5)); client.println("</form>"); client.print("<form method=get><input type=submit name=valor value=1DIG6>"); client.println("<input type=submit name=valor value=0DIG6> DIG6="); client.println(digitalRead(6)); client.println("</form>"); client.print("<form method=get><input type=submit name=valor value=1DIG7>"); client.println("<input type=submit name=valor value=0DIG7> DIG7="); client.println(digitalRead(7)); client.println("</form>"); client.print("<form method=get><input type=submit name=valor value=1DIG8>"); client.println("<input type=submit name=valor value=0DIG8> DIG8="); client.println(digitalRead(8)); client.println("</form>"); client.print("<form method=get><input type=submit name=valor value=1DIG9>"); client.println("<input type=submit name=valor value=0DIG9> DIG9="); client.println(digitalRead(9)); client.println("</form>"); client.println("<hr>"); for ( z = 0; z < 6; z++) { sensorReading = analogRead(z); client.print("Analog input "); client.print("<font color=red>"); client.print(z); client.print("</font>"); client.print(" is "); client.print("<font color=blue>"); client.print(sensorReading); client.print("</font>"); client.println("<br />"); } client.println("<hr>"); client.println("</html>"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); Serial.println("client disonnected"); } bandera=0; } void colocar() { if(readString.indexOf("1DIG2") >0){ digitalWrite(2, HIGH); goto salir;} if(readString.indexOf("0DIG2") >0){ digitalWrite(2, LOW); goto salir;} if(readString.indexOf("1DIG3") >0){ digitalWrite(3, HIGH);goto salir;} if(readString.indexOf("0DIG3") >0){ digitalWrite(3, LOW);goto salir;} if(readString.indexOf("1DIG5") >0){ digitalWrite(5, HIGH);goto salir;} if(readString.indexOf("0DIG5") >0){ digitalWrite(5, LOW);goto salir;} if(readString.indexOf("1DIG6") >0){ digitalWrite(6, HIGH);goto salir;} if(readString.indexOf("0DIG6") >0){ digitalWrite(6, LOW);goto salir;} if(readString.indexOf("1DIG7") >0){ digitalWrite(7, HIGH);goto salir;} if(readString.indexOf("0DIG7") >0){ digitalWrite(7, LOW);goto salir;} if(readString.indexOf("1DIG8") >0){ digitalWrite(8, HIGH);goto salir;} if(readString.indexOf("0DIG8") >0){ digitalWrite(8, LOW);goto salir;} if(readString.indexOf("1DIG9") >0){ digitalWrite(9, HIGH);goto salir;} if(readString.indexOf("0DIG9") >0){ digitalWrite(9, LOW);goto salir;} if(readString.indexOf("Encende") >0){ encender(); goto salir;} if(readString.indexOf("Apagar") >0){ apagar();goto salir;} salir: ; } void encender() { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(5, HIGH);digitalWrite(6, HIGH); digitalWrite(7, HIGH);digitalWrite(8, HIGH);digitalWrite(9, HIGH); } void apagar() { digitalWrite(2, LOW);digitalWrite(3, LOW);digitalWrite(5, LOW);digitalWrite(6, LOW); digitalWrite(7, LOW);digitalWrite(8, LOW);digitalWrite(9, LOW); } |
// Modificacion 19-12-2012 //webserver v2mini #include <SPI.h> #include <Ethernet.h> //numero de MAC //numero de ip, depende de tu red byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,2, 177); String readString = String(20); byte bandera=0; byte z; char c; int sensorReading; EthernetClient client; const byte PinOut[] = { 2, 3, 5, 6, 7, 8, 9}; EthernetServer server(80); void setup() { Serial.begin(9600); while (!Serial) { } Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); for(z=0;z<7;z++) pinMode(PinOut[z],OUTPUT); } void loop() { client = server.available(); if (client) { Serial.println("new client"); boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { c = client.read(); Serial.write(c); if(c=='?' && bandera==0) { readString=""; for(z=0;z<14;z++) { c = client.read(); readString +=c; } Serial.println(readString); colocar(); bandera=1; } if (c == '\n' && currentLineIsBlank) { // Manda la cabecera del http client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connnection: close"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); // Refresca cada 3 segundos client.println("<meta http-equiv=\"refresh\" content=\"3\">"); client.println("<big><b>Seta43_Arduino</b></big><br>"); client.print("xsetaseta@gmail.com <br>"); client.print("Control 6 salidas digitales y 6 entradas analogicas <br>"); client.println("<hr>"); FormSubmit(); client.print("Encender_Todos>"); PrintSubmit(); client.println("Apagar_todos></form>"); client.println("<hr>"); for(z=0;z<7;z++) { FormSubmit(); client.print("1DIG"); client.print(PinOut[z]); client.print(">"); PrintSubmit(); client.print("0DIG"); client.print(PinOut[z]); client.print(">"); client.print(" DIG");client.print(PinOut[z]); client.print("="); client.print(digitalRead(PinOut[z])); PrintForm(); } client.println("<hr>"); for ( z = 0; z < 6; z++) { sensorReading = analogRead(z); client.print("Analog input "); client.print("<font color=red>"); client.print(z); client.print("</font>"); client.print(" is "); client.print("<font color=blue>"); client.print(sensorReading); client.print("</font>"); client.println("<br />"); } client.println("<hr>"); client.println("</html>"); break; } if (c == '\n') currentLineIsBlank = true; else if (c != '\r') currentLineIsBlank = false; } } delay(1); client.stop(); Serial.println("client disonnected"); } bandera=0; } void FormSubmit() { PrintFormIn(); PrintSubmit(); } void PrintSubmit() { client.print("<input type=submit name=valor value="); } void PrintFormIn() { client.print("<form method=get>"); } void PrintForm() { client.println("</form>"); } void colocar() { if(readString.indexOf("1DIG2") >0){ digitalWrite(2, HIGH); goto salir;} if(readString.indexOf("0DIG2") >0){ digitalWrite(2, LOW); goto salir;} if(readString.indexOf("1DIG3") >0){ digitalWrite(3, HIGH);goto salir;} if(readString.indexOf("0DIG3") >0){ digitalWrite(3, LOW);goto salir;} if(readString.indexOf("1DIG5") >0){ digitalWrite(5, HIGH);goto salir;} if(readString.indexOf("0DIG5") >0){ digitalWrite(5, LOW);goto salir;} if(readString.indexOf("1DIG6") >0){ digitalWrite(6, HIGH);goto salir;} if(readString.indexOf("0DIG6") >0){ digitalWrite(6, LOW);goto salir;} if(readString.indexOf("1DIG7") >0){ digitalWrite(7, HIGH);goto salir;} if(readString.indexOf("0DIG7") >0){ digitalWrite(7, LOW);goto salir;} if(readString.indexOf("1DIG8") >0){ digitalWrite(8, HIGH);goto salir;} if(readString.indexOf("0DIG8") >0){ digitalWrite(8, LOW);goto salir;} if(readString.indexOf("1DIG9") >0){ digitalWrite(9, HIGH);goto salir;} if(readString.indexOf("0DIG9") >0){ digitalWrite(9, LOW);goto salir;} if(readString.indexOf("Encende") >0){ for(z=0;z<7;z++) digitalWrite(PinOut[z],HIGH); goto salir; } if(readString.indexOf("Apagar") >0) { for(z=0;z<7;z++) digitalWrite(PinOut[z],LOW); goto salir; } salir: ; } |