Hola, tengo que hacer un proyecto de comunicación para comunicar un arduino nano por medio de un cable ethernet para recibir y mandar señales e información. El detalle es que cuando quiero hacer pruebas para detectar que este sirva correctamente no lo veo en el registro de un módem que estoy utilizando para conocer el módulo, el módem que estoy utilizando no tiene conexión a internet, pero no busco esta conexión solamente quiero mandar datos y recibirlos. Se necesita internet para que la ENC28J60 funcione correctamente?
Actualmente para conocer y probar este módulo estoy utilizando la libreria EtherCard con el ejemplo que esta misma trae llamado backSoon.
Tengo problemas en saber cual IP puedo cambiar y cuál no debería hacer, les dejo el código para que vean de que estoy hablando. Muchas gracias!!!
// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl>
//
// License: GPLv2
#include <EtherCard.h>
#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,15 };
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Service Temporarily Unavailable"
"</title></head>"
"<body>"
"<h3>This service is currently unavailable</h3>"
"<p><em>"
"The main server is currently off-line.<br />"
"Please try again later."
"</em></p>"
"</body>"
"</html>"
;
void setup(){
Serial.begin(57600);
Serial.println("\n[backSoon]");
// Change 'SS' to your Slave Select pin, if you arn't using the default pin
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}
SI lo que has hecho funciona y tu gateway esta en 192.168.0.1 entonces abre una consola con CMD si usas Windows y coloca
ping 192.168.0.15 y debería darte respuestas como estas
Mi red es diferente, como donde trabaja mi red?
colocas > ipconfig y recibes entre otras cosas la ip de tu PC y la del router/gateway
Muchas gracias por contestar!! El problema es que mi rúter no detecta la IP que le pongo a la ENC28J60, y la verdad todos los videos y guías que veo se ve super sencillo D:
La MAC de tu dispositivo tendria que ser medio parecida a la MAC de tu router.
La MAC de tu dispositivo es inventada. Hay algunos routers que rechazan ciertos comienzos de MAC. Lo recuerdo de las viejas placas Ethernet para el UNO/MEGA.
Prueba por ejemplo
Supongamos que la MAC de tu router es
Aunque se sale del tema, que despropósito que la MAC de un dispositivo de red no venga grabada a fuego en el dispositivo y se pueda cambiar, por poner ejemplos la MAC y el IMEI tienen que ser identificadores únicos a nivel mundial.
Ya me funcionó!! Muchas gracias, al final lo que hice fue cambiar la MAC como me comentaste y también modifique los baudios de comunicación (Pero creo que no afecta mucho esto). Muchísimas gracias por los comentarios!! Les dejo el código final por si lo quieren revisar:
// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl>
//
// License: GPLv2
#include <EtherCard.h>
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,200 };
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x48,0xE7,0xDA,0x2F,0x3E,0x1A };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"TAB NAME"
"</title></head>"
"<body>"
"<h3>Se logro la comunicacion!!</h3>"
"<p><em>"
"Muy bien!.<br />"
"Ahora viene lo complicado."
"</em></p>"
"</body>"
"</html>"
;
void setup(){
Serial.begin(9600);
Serial.println("\n[backSoon]");
// Change 'SS' to your Slave Select pin, if you arn't using the default pin
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}