Módulo enc28j60 no funciona en red, arduino nano

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

image
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

image

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:

Has probado con 1?

EDICION:

Realmente es indistinto si se usa 0 ó 1, ya que en ambos casos el símbolo STATIC queda definido, que es lo que afecta el programa.

Habría que probar suprimiendo la directiva de modo que STATIC no se defina. Por ejemplo así:

//#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)

El tercer grupo de números puede ser 1, 88, 100, cualquier cosa.

No es 0 porque lo dice un tutorial, es lo que el router tiene configurado.

Mira como en mi caso el 3er grupo en mi caso es 100.

Entiendo ese punto, pero en este caso mi router si es 0. Una pregunta que tengo es, si mi router no tiene conexion a wifi afecta?

No lo he probado, lo voy a intentar de ese modo. Muchas gracias!

¿has mirado en la tabla arp si aparece la mac de tu dispositivo?

1 Like

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

static byte mymac[] = { 0x9C,0x87,0x80,0x2D,0xA0,0xE8 };

Bueno tu le pones por ejemplo

static byte mymac[] = { 0x9C,0x87,0x80,0x4D,0xEA,0x02 };

Cambias los ultimos 3 números hexa
Prueba a ver.

1 Like

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.

No lo había probado, en un momento lo pruebo y les comento. Gracias!!

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);
  }
}

Si me ayudó bastante esto ya que así pude definir la IP estática como yo quise, muchas gracias!!

Recordé justamente la respuesta de hace muchos años tal como te dije donde eso pasaba con las shield W5100, Veo que sigue ocurriendo.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.