Hola,
con una placa ethernet y dentro de la red de casa con la aplicacion NETIO o sin ella todo funciona , puedo encender led,etc.
Pero al hacerlo desde fuera problemas: he abierto el puerto, dicho que la ip para la placa sea siempre la misma, habilitado el DHCP para la mac e ip, tambien colocado direccion Dyndns expresa, pero no funciona.
todo esto es igual a una camara ip que tengo.
Las preguntas son
-notais que falte algo,
-al poner la direccion dyndns en el sketch no lo admite sino lo pongo entre comillas que si compila, estara bien.
-la direccion mac 0x55,0x54, etc equivaldra a 55:54: del router etc.
-en la ip pongo la ip publica y tampoco funciona
hay un ejemplo en
que explica todo pero al final en el progr. pone una ip interna
el ejemplo con NETIO es
he quitado el gateway y subnet pero no complicarme la vida funciona igual
/*
Simple Webserver sketch for NetIO Application
Tutorial on http://netio.davideickhoff.de
*/
#include <SPI.h>
#include <Ethernet.h>
// CONFIGURATION
byte mac[] = { 0x54, 0x55, 0x58, 0x10, 0x00, 0x24 }; // MAC address 84.85.88.16.0.36
byte ip[] = { 192, 168, 1, 50 }; // ip-address, please change to fit your network
//byte gateway[] = { 192, 168, 1, 1 }; // Gateway
//byte subnet[] = { 255, 255, 255, 0 };
// example has an RGB diode connected to three pins
int redLed = 5;
int greenLed = 6;
int blueLed = 7;
EthernetServer server(3200);
String readString = String(100); // string for fetching data from address
void setup(){
Ethernet.begin(mac, ip);
server.begin();
// configure LED pins
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
Serial.begin(9600);
}
void loop(){
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();
Serial.print(c);
if (readString.length() < 100) {
//store characters to string
readString = readString + c;
}
// 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 (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// conditions for get parameters
if(readString.indexOf("red=") > -1) {
digitalWrite(redLed, (readString.indexOf("=1") > -1) ? HIGH : LOW);
}
else if(readString.indexOf("green=") > -1) {
digitalWrite(greenLed, (readString.indexOf("=1") > -1) ? HIGH : LOW);
}
else if(readString.indexOf("blue=") > -1) {
digitalWrite(blueLed, (readString.indexOf("=1") > -1) ? HIGH : LOW);
}
if(readString.indexOf("status=") > -1 ) {
// status requests
if (readString.indexOf("red") > -1)
client.print(digitalRead(redLed));
else if (readString.indexOf("green") > -1)
client.print(digitalRead(greenLed));
else if (readString.indexOf("blue") > -1)
client.print(digitalRead(blueLed));
else
client.print("invalid parameter");
} else if(readString.indexOf("read=") > -1 ) {
//generic response according to incoming GET parameter
client.print(String(readString.substring(readString.indexOf("=")+1, readString.indexOf("_"))));
} else {
client.print("OK");
}
//clear string for next read
readString="";
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();
}
}