Buenas!
Veran... estoy haciendo un proyecto de domotica para la escuela y no encuentro la manera de conectar el ethernet shield a una pagina web ya en linea.
Lo que he encontrado en tutoriales y ejemplos es la conexion de manera local (en tu red) éste es mi codigo
#include <SPI.h>
#include <Ethernet.h>
#include <VirtualWire.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
int LEDpin = 9;
String readString = String(30);
String state = String(3);
char d = 0;
void setup()
{
vw_set_ptt_inverted(true);
vw_set_tx_pin(3);
vw_setup(1000);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
//Sets the LEDpin as an output
pinMode(LEDpin,OUTPUT);
digitalWrite(LEDpin,LOW);
state = "OFF";
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (readString.length() < 30) {
readString.concat(c);
}
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
int LED = readString.indexOf("LED=");
if (readString.substring(LED,LED+5) == "LED=T") {
digitalWrite(LEDpin,HIGH);
state = "ON";
d='3';
vw_send((uint8_t *) &d, strlen(&d));
vw_wait_tx();
}
else if (readString.substring(LED,LED+5) == "LED=F") {
digitalWrite(LEDpin,LOW);
state = "OFF";
d='1';
vw_send((uint8_t *) &d, strlen(&d));
vw_wait_tx();
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("LED is ");
client.print(state);
client.print("
");
if (state == "ON") {
client.println("<a href=\"./?LED=F\">Turn Off<a>");
}
else {
client.println("<a href=\"./?LED=T\">Turn On<a>");
}
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);
readString = "";
// close the connection:
client.stop();
}
}
De manera local funciona, pero no encuentro hacerlo funcionar con el servidor que tengo, ¿alguna idea?
Espero puedan ayudarme, gracias!