Last active
August 29, 2015 13:57
-
-
Save malambra/9853519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WString.h> | |
#include <Ethernet.h> | |
/* | |
Prueba de concepto: | |
Servidor web para control de interfaces de arduino via "get" | |
Copyright: Manolo | |
Licencia: Affero GPL V3 | |
2012 | |
*/ | |
/*Definicion del servidor web*/ | |
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; | |
byte ip[] = {192, 168, 1, 5}; | |
Server server(80); | |
/*Definicion de los puertos de arduino*/ | |
int LDR = 3; | |
int LZC = 2; | |
int LZJ = 4; | |
int LZD = 7; | |
int AAC = 8; | |
/*Definicion de variables*/ | |
String readString = String(100); | |
boolean _LZJ = false; | |
boolean _LZD = false; | |
boolean _AAC = false; | |
boolean _LZC = false; | |
/////////////////////// | |
String url = String(100); | |
String teststring = String(100); | |
String finalstring = String(100); | |
int guardo = 0; | |
int limiteLDR = 18; | |
////////////////////// | |
/*Configuracion Arrancamos el servidor web y definimos entras y salidas*/ | |
void setup() | |
{ | |
Ethernet.begin(mac, ip); | |
server.begin(); | |
pinMode(LDR, INPUT); | |
pinMode(LZJ, OUTPUT); | |
pinMode(LZD, OUTPUT); | |
pinMode(AAC, OUTPUT); | |
pinMode(LZC, OUTPUT); | |
} | |
/*Loop infinito. Se sirve la web se lee la entrada desde el "form" y se cambian los estados de los puertos de arduino*/ | |
void loop() | |
{ | |
Client client = server.available(); | |
if (client) | |
{ | |
while(client.connected()) | |
{ | |
if(client.available()) | |
{ | |
char c = client.read(); | |
if(readString.length() < 100) | |
{ | |
readString.append(c); | |
} | |
if(c == '\n') | |
{ | |
if(readString.contains("LuzDormitorio=1")) | |
{ | |
digitalWrite(LZD, HIGH); | |
_LZD = true; | |
} | |
if(readString.contains("LuzDormitorio=0")) | |
{ | |
digitalWrite(LZD, LOW); | |
_LZD = false; | |
} | |
if(readString.contains("LuzJardin=1")) | |
{ | |
digitalWrite(LZJ, HIGH); | |
_LZJ = true; | |
} | |
if(readString.contains("LuzJardin=0")) | |
{ | |
digitalWrite(LZJ, LOW); | |
_LZJ = false; | |
} | |
if(readString.contains("AireAcondicionado=1")) | |
{ | |
digitalWrite(AAC, HIGH); | |
_AAC = true; | |
} | |
if(readString.contains("AireAcondicionado=0")) | |
{ | |
digitalWrite(AAC, LOW); | |
_AAC = false; | |
} | |
if(readString.contains("LuzCocina=1")) | |
{ | |
digitalWrite(LZC, HIGH); | |
_LZC = true; | |
} | |
if(readString.contains("LuzCocina=0")) | |
{ | |
digitalWrite(LZC, LOW); | |
_LZC = false; | |
} | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println(); | |
client.println("<head>"); | |
client.println("<meta http-equiv=Content-Type content=text/html; charset=utf-8 />"); | |
client.println("<title>Eco-Home</title>"); | |
client.println("</head>"); | |
client.println("<body>"); | |
client.println("Luz Jardin<br>"); | |
client.print("<br>Estado: "); | |
if (_LZJ==true) | |
{ | |
client.println("<font color='green'>ON"); | |
client.println("<form method=get name=LZJ><input type=hidden name=LuzJardin value=0><input type=submit value=OFF></form>"); | |
} | |
if (_LZJ==false) | |
{ | |
client.println("<font color='grey'>OFF"); | |
client.println("<form method=get name=LZJ><input type=hidden name=LuzJardin value=1><input type=submit value=ON></form>"); | |
} | |
client.println("<hr><font color='black'>Aire Acondicionado<br>"); | |
client.print("<br>Estado: "); | |
if (_AAC==true) | |
{ | |
client.println("<font color='green'>ON"); | |
client.println("<form method=get name=AAC><input type=hidden name=AireAcondicionado value=0><input type=submit value=OFF></form>"); | |
} | |
if (_AAC==false) | |
{ | |
client.println("<font color='grey'>OFF"); | |
client.println("<form method=get name=AAC><input type=hidden name=AireAcondicionado value=1><input type=submit value=ON></form>"); | |
} | |
client.println("<hr><font color='black'>Luz Dormitorio<br>"); | |
client.print("<br>Estado: "); | |
if (_LZD==true) | |
{ | |
client.println("<font color='green'>ON"); | |
client.println("<form method=get name=LZD><input type=hidden name=LuzDormitorio value=0><input type=submit value=OFF></form>"); | |
} | |
if (_LZD==false) | |
{ | |
client.println("<font color='grey'>OFF"); | |
client.println("<form method=get name=LZD><input type=hidden name=LuzDormitorio value=1><input type=submit value=ON></form>"); | |
} | |
client.println("<hr><font color='black'>Luz Cocina<br>"); | |
client.print("<br>Estado: "); | |
if (_LZC==true) | |
{ | |
client.println("<font color='green'>ON"); | |
client.println("<form method=get name=LZC><input type=hidden name=LuzCocina value=0><input type=submit value=OFF></form>"); | |
} | |
if (_LZC==false) | |
{ | |
client.println("<font color='grey'>OFF"); | |
client.println("<form method=get name=LZC><input type=hidden name=LuzCocina value=1><input type=submit value=ON></form>"); | |
} | |
readString=""; | |
client.stop(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment