OpenWrt Forum Archive

Topic: [HowTo] have OpenWrt auto detect MAC address and start NAS with wol

The content of this topic has been archived on 30 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

So I had an issue with a PS3 not being able to wake up a Buffalo NAS in order to see pictures and media and then shut back down to save energy. It took a week of on and off gathering but here it is.

After the installation of OpenWrt, change passwd, ssh in as root:

First install the wol package (wol stands for Wake-On-LAN):

opkg install wol

Create a script file in etc using the text editor vi:

vi /etc/autoWOL.sh

vi is funky, once you type the code above you'll have a blank document, but in order to be able to type, you first must press i. more on vi
For me if I have copied something and want to paste it in a terminal, I press shift-Insert. Paste the script below.

#!/bin/ash

PS3="no:te:ll:in:gy:ou"
var="FourLetterWord"

while [ $var != $PS3 ]
do
        var=`grep -o 'no:te:ll:in:gy:ou' /proc/net/arp`           
        if [ -z $var ]; then
                exit
        fi
        if [ $var == $PS3 ]; then
                /usr/bin/wol -p 9 -i 192.168.1.255 na:sm:ed:ia:dr:ve
                exit
        fi
done

hit Esc key to exit typing mode, then type:

:wq

and then hit Enter to quit. To just look at files you can use less /path/to/file, or if it's a small file (fits on the screen) just use cat /path/to/file.

I loaded var with "FourLetterWord" because the while command didn't like a null variable for some reason. Be sure to put the correct MAC addresses in there right spots (first two are what you want to detect, second is your NAS). Thanks jow for the /proc/net/arp. That file seems to update every couple of minutes which is fine for my use.

Next make the script executable:

chmod a+x /etc/autoWOL.sh

Now edit the root crontab:

crontab -e

you'll be in vi, so remember to hit i before typing. Insert and edit to your needs:

*/1 * * * * /etc/autoWOL.sh

A simple cron tutorial is here

You need to enable cron to have it start up every time the router reboots

/etc/init.d/cron enable

now reboot the router and you should be all set to detect and wol!

reboot

(Last edited by KryoFrk on 8 May 2009, 03:33)

Nice. But why not use UCI for the WOL configuration?

The discussion might have continued from here.