Wake On LAN with the use of ENC28J60 does not work.

Hi guys. I’m trying to make WOL using Arduino.
I use the Arduino Nano and the HR911105A module, built on the ENC28J60 microchip.
I tried to use this code:

But it does not work. The controller is initialized successfully, but the packet is not sent.

I added the EtherCard.h library to the desired directory. The MAC target is replaced by the MAC address of my network card. The port speed was reduced to 9600 baud.

Moreover, as far as I understood, this example needs a DHCP server. I connected the Ethernet shield to the router distributing IP by DHCP (the router is configured correctly and works as expected), in conjunction with the computer that needs to be awakened.

Maybe I did not configure the port settings for the correct operation of the broadcaster = a broadcast request?

In the port monitor, I see that the IP, mask and gateway have been successfully issued, but in wireshark there is no necessary wol packet, after repeated pressing “w”. The computer also does not start from wol because the package does not come. In this case, the computer is configured correctly, I can wake it through an Android application running on WI-FI.
I also connected the system directly to the computer, without a router, but it also does not lead to anything either.

In my project, I just need to wake the computer on a magic packet using a local network, without external access. As far as I understand, for this I do not need to give out the IP address and other parameters to my module on ENC28J60, it only needs to send a broadcast packet, or am I wrong?
In any case, I want to use a static IP on my ENC28J60.

I noticed that there is an error in the library itself, it is indicated that the CS pin from the ENC28J60 controller must be connected to the 8 Arduino pin, but this is not the case, pin 10 should be used, otherwise the Ethernet controller will not be able to initialize.

The library itself is working, I checked it on this code:

void setup () {
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  ether.staticSetup(myip);
}

static word homePage() {
  long t = millis() / 1000;
  word h = t / 3600;
  byte m = (t / 60) % 60;
  byte s = t % 60;
  bfill = ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>$D$D:$D$D:$D$D</h1>"),
      h/10, h%10, m/10, m%10, s/10, s%10);
  return bfill.position();
}

void loop () {
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);

  if (pos)  // check if valid tcp data is received
    ether.httpServerReply(homePage()); // send web page data
}

I also found these options: http://www.megunolink.com/download/libraries/wake-on-lan/ but I do not understand how to work with it.
Another example: http://arduino.seesaa.net/article/134495683.html - there is a problem with one of the libraries, as far as I understand it is too old (those versions I found were old) for my arduino ide. In addition, here, apparently, you need to flush the port in the router.

What’s my mistake? I could not find anywhere a detailed example where the step-by-step implementation of WOL using Arduino is described, I really need this option for my project. I am hope for your help.

Sorry for my bad English.

Since you have tested the ability to wakeup the remote computer (Windows PC?) from an android device, then, unless there is specific firewall configuration which allows the android device in, but not the Arduino, then the problem is almost certainly on the Arduino side. I guess temporarily disabling any firewalls (wol is usually UDP port 7 or 9 ) would confirm that. I guess also, that when you use the android, it has obtained an IP address in the same network as the Arduino (e.g. 192.168.1.X) which is of course must be in the same network as the target computer.

The broadcast address is 255.255.255.255

If you believe there is a problem with the example code for sending a wol packet, you can construct your own:
It is simply a byte array with the first 6 bytes consisting of 0xFF, the next 6 bytes consisting of the target mac address, then 8 more repetitions of the target address.
This array you send to the broadcast address on say port 9.

Yes, my computer runs on Windows 7, but this operating system does not matter here, since the WOL package starts the computer without the OS, and as far as I understand, it is not at all necessary that the network card has an IP address at that moment (I'll try to check it on Another router).
WOL starts the desktop computer when it is turned off and only 5 V STB Power is supplied to the motherboard.

I can wake the computer from both the Android smarthophone and another computer, since all three devices (computer 1, computer 2, smartphone) on the same subnet and I know the MAC for the computer 1.

I do not know how to work with a library that would send the necessary packages to PHY, that would transfer them to the computer.
The simplest and most correct scheme is to send the package to a computer that is now connected directly to Arduino via the ENC28J60 PHY.

Yes, wol is a very low level function of the network card and it looks only for the 'magic packet' in its input stream to waken the computer.

Naturally, you are not sending the packets directly to the target computer's ip address (which it may not even have at the time of waking), you are sending these to a broadcast address 255.255.255.255 and the target computer looks to see if its own mac address is in the packet.

If you are simply trying to send anything just to test, you may be able to use this as a basis to see what you see in wireshark with a broadcast address of 255.255.255.255:

alter dstPort to say 9, drop the website code and replace ether.hisip in the call to sendUdp with a correctly formatted version of 255.255.255.255 maybe something like IPAddress broadcastIp(255, 255, 255, 255);

I can't test any of this because I have no ethernet card.

One other thing you could possibly try doing is temporarily disabling IPv6 on the target computer's network card.

6v6gt Thank you for your reply.

This code: enc28j60_tutorial/_4_WOL.ino at master · lucadentella/enc28j60_tutorial · GitHub works!!!

It can work as with DHCP (then it's initialized very quickly, because the router quickly gives IP, the packet comes from IP), or without DHCP (then it thinks for a long time, since it waits for an IP, as I understand, it does not receive it as a result, and the package arrives With the source 0.0.0.0).

Packages I caught on the TRENDNET router, there is an option to collect packets from the WAN and LAN, fished accordingly with the LAN and then watched the wireshark. The computer turns on with hurray (it turns on, since it's off). As already written above, if you do not give DHCP, ie simply connect the cable from Arduino to the computer, it will start in about 3 minutes (in the code made autostart, removed the manual pressing w).