1

I am using a Raspberry Pi to power on a computer that is not capable of Wake on LAN. I want to send the already on Pi a WoL packet and trigger a relay with the GPIO pins. I am having a bit of trouble figuring out. Even if the WoL packet has to do something like set an environmental variable that a bash script keeps an eye on would work, but if I can do it all in the Python script that controls the GPIO, that would be ideal.

I am finding little information on detecting the packet outside using ngrep or netcat as shown on the arch wiki, however I can't get it to show anything on any of my systems. Any suggestions or a better way to do it?

2
  • 3
    Why use WOL? Why not just send the Pi a command if it is already powered up?
    – joan
    Commented Feb 18, 2023 at 20:35
  • 1
    Because I have an interface to use WoL which I can use for my other server, that actually works with WoL. Sending the pi a command is an option, but I would like to get the WoL packet working too
    – ZenRen
    Commented Feb 18, 2023 at 21:31

1 Answer 1

1

Check your network setup: Make sure that your Raspberry Pi and the computer you are trying to wake up are on the same network segment and that the WoL packet is being sent to the correct MAC address. Also, make sure that the network interface on the Raspberry Pi is in promiscuous mode so that it can detect the WoL packet. You can use the ifconfig command to check if the network interface is in promiscuous mode.

Use tcpdump: Instead of using ngrep or netcat, you can try using tcpdump to capture the WoL packet. You can use the following command to capture all packets on the network interface that the WoL packet is expected to arrive on:

sudo tcpdump -i -vvv 'ether proto 0x0842'

Replace with the name of the network interface that the WoL packet is expected to arrive on. The ether proto 0x0842 filter matches the Ethernet type used by Wake-on-LAN packets.

Use a Python library: There are several Python libraries that can be used to send and receive WoL packets. One such library is wakeonlan. You can install it using the following command:

pip install wakeonlan

You can then use the send_magic_packet function to send the WoL packet to the computer you want to wake up. In your Python script, you can check if a WoL packet has been received by continuously listening for incoming packets using the socket module. Once a WoL packet is received, you can trigger the relay using the GPIO pins.

1
  • Actually, it doesn't matter whether the PC and the Pi are on the same network, in fact, the PC can be not connected to the network at all. The Pi is the only possible destination of the WoL traffic. Commented Feb 20, 2023 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.