Buenos dias, Inicialmente me gustaria agradecer a toda esta maravillosa comunidad por su gentileza al momento de compartir ideas y ayudar a otros y expresarles mi mas sincero agradecimiento.
El problema es el siguiente, estoy intentando experimentar sobre la creacion de un pequeño sistema domotico con control de acceso, he copiado un codigo desde internet, Anexo link del autor y he intentado reproducirlo, ya he adicionado la libreria externa WEBDUINO, sin embargo al momento de verificar el codigo el copilador me indica errores, seria de gran ayuda entender cual seria el problema ya que no soy muy experto en tramas de comunicacion HTTP ni del lengauje
#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
/* you can change the authentication realm by defining
* WEBDUINO_AUTH_REALM before including WebServer.h */
#define WEBDUINO_AUTH_REALM "Igua Private Site"
#define Host_name "Igua"
/* CHANGE THIS TO YOUR OWN UNIQUE VALUE. The MAC number should be
* different from any other devices on your network or you'll have
* problems receiving packets. */
byte mac[] = { 0x16, 0x16, 0x16, 0x16, 0x16, 0x01 };
/* CHANGE THIS TO MATCH YOUR HOST NETWORK. Most home networks are in
* the 192.168.0.XXX or 192.168.1.XXX subrange. Pick an address
* that's not in use and isn't going to be automatically allocated by
* DHCP from your router. */
IPAddress ip(192,168,0,5);
IPAddress gateway(192,168,0,5);
IPAddress subnet(255, 255, 255, 0);
/* This creates an instance of the webserver. By specifying a prefix
* of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 80);
boolean LED_status = 0; // state of LED, off by default
// ROM-based messages used by the application
// These are needed to avoid having the strings use up our limited
// amount of RAM.
P(Page_start) = "<html><head><title>ManchiHouse</title></head><body>\n";
P(Page_end) = "</body></html>";
P(Get_head) = "<h1>GET from ";
P(Post_head) = "<h1>POST to ";
P(Unknown_head) = "<h1>UNKNOWN request for ";
P(Default_head) = "unidentified URL requested.</h1>
\n";
P(Line_break) = "
\n";
P(Form_Inicio) = "<form method=\"get\">";
P(Form_Final) = "</form>";
#define NAMELEN 32
#define VALUELEN 32
String GetParam(String ParamName, WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
URLPARAM_RESULT rc;
char name[NAMELEN];
char value[VALUELEN];
String ReturnParam = "";
if (strlen(url_tail))
{
while (strlen(url_tail))
{
rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN);
if (rc != URLPARAM_EOS && String(name) == ParamName)
{
ReturnParam = value;
}
}
}
if (type == WebServer::POST)
{
while (server.readPOSTparam(name, NAMELEN, value, VALUELEN))
{
if (String(name) == ParamName)
{
ReturnParam = value;
}
}
}
return ReturnParam;
}
//Se mira la query para ver si se ha de activar o desactivar la linea
String ProcesarCheckbox(String Estado)
{
LED_status = 0;
if (Estado == "1")
{
LED_status = true;
}
if (LED_status) { // switch LED on
digitalWrite(2, HIGH);
// checkbox is checked
return "<input type=\"checkbox\" name=\"Luz\" value=\"1\" onclick=\"submit();\" checked>Apagar Luz";
}
else { // switch LED off
digitalWrite(2, LOW);
// checkbox is unchecked
return "<input type=\"checkbox\" name=\"Luz\" value=\"1\" onclick=\"submit();\">Encender Luz";
}
}
void indexCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
server.httpSuccess();
if (type != WebServer::HEAD)
{
P(Saludo) = "<h1>Bienvenido a IGUA!</h1><a href=\"control.html\">Acceder</a>";
server.printP(Saludo);
}
}
void controlCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
/* if the user has requested this page using the following credentials
* username = user
* password = user
* display a page saying "Hello User"
*
* the credentials have to be concatenated with a colon like
* username:password
* and encoded using Base64 - this should be done outside of your Arduino
* to be easy on your resources
*
* in other words: "YWRtaW46YWRtaW4=" is the Base64 representation of "admin:admin"
*
* if you need to change the username/password dynamically please search
* the web for a Base64 library */
if (server.checkCredentials("YWRtaW46YWRtaW4="))
{
server.httpSuccess();
String Estado = GetParam("Luz", server, type, url_tail, tail_complete);
if (type != WebServer::HEAD)
{
P(Control_Head) = "<h1>Bienvenido al control de IGUA</h1><p>Indica si deseas encender o apagar la luz</p>";
server.printP(Control_Head);
server.printP(Form_Inicio);
server.println(ProcesarCheckbox(Estado));
server.printP(Form_Final);
}
}
else
{
Serial.println("No valido");
/* send a 401 error back causing the web browser to prompt the user for credentials */
server.httpUnauthorized();
}
}
void failCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
//this line sends the "HTTP 400 - Bad Request" headers back to the browser
server.httpFail();
/* if we're handling a GET or POST, we can output our data here.
For a HEAD request, we just stop after outputting headers. */
if (type== WebServer::HEAD)
{
return;
}
server.printP(Page_start);
switch(type)
{
case WebServer::GET:
{
server.printP(Get_head);
break;
}
case WebServer::POST:
{
server.printP(Post_head);
break;
}
default:
{
server.printP(Unknown_head);
}
}
server.printP(Default_head);
server.print(url_tail);
server.printP(Page_end);
}
void setup()
{
Serial.begin(9600);
Serial.println("Iniciado");
/* initialize the Ethernet adapter */
//Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("Trying to get an IP address using DHCP");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// initialize the ethernet device not using DHCP:
Ethernet.begin(mac, ip, gateway, subnet);
}
// print your local IP address:
Serial.print("My IP address: ");
ip = Ethernet.localIP();
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(ip[thisByte], DEC);
Serial.print(".");
}
Serial.println();
/* setup our default command that will be run when the user accesses
* the root page on the server */
webserver.setDefaultCommand(&indexCmd);
/* setup our default command that will be run when the user accesses
* a page NOT on the server */
//webserver.setFailureCommand(&failCmd);
/* run the same command if you try to load /index.html, a common
* default page name */
webserver.addCommand("index.html", &indexCmd);
webserver.addCommand("control.html", &controlCmd);
/* start the webserver */
webserver.begin();
/*Indicamos que el PIN 2 será de salida
* para nosotros es donde estará el cable de Luz */
pinMode(2, OUTPUT);
}
void loop()
{
char buff[64];
int len = 64;
/* process incoming connections one at a time forever */
webserver.processConnection(buff, &len);
}
HTML.
Muchas gracias.