Cameronmale83
Posts: 2
Joined: Sun Jul 28, 2013 9:28 am

Wake on lan forwarder/tiggers

Sun Jul 28, 2013 9:43 am

Hi Pi-land,
First time posting on a forum for help, usually I'm okay with work arounds etc... this one has stumped me.

So, bought a new HTPC (windows 7, xbmc) that doesn't turn on via remote (Hibternate is playing nice, so need another option)...
To work around I want to remotely and automatically turn it on via WOL when my NAS (qnap-410) finishes it's boot cycle and registers on the network.

Why?
Well, the boot cycle takes ages so I physically turn the NAS on and 3 mins later it's ready to go... But if I manually turn the HTPC on at the same time, it won't recognize the drives as being mapped.

I have a raspberry pi and love it...

Here is want I want it to do with it:
Pi scans or sniffs the network constantly (24hrs if needs be) for when the NAS (mac address) comes online to the network (router)... When this occurs it automatically sends a Wake On Lan command to the HTPC which wakes it up from being off.

Any help with this would be great..

Vypr
Posts: 55
Joined: Tue Apr 09, 2013 2:02 am

Re: Wake on lan forwarder/tiggers

Mon Jul 29, 2013 1:33 pm

I think a simple bash script run under cron should do the trick

First you'll need the etherwake package installed to send the Wake On Lan signal. I don;t know if it's in the Raspbian depository but you can gibve it a try by running

Code: Select all

sudo apt-get install etherwake
then create a bash script with the following code:

Code: Select all

#!/bin/bash
if ping -c <ip address of NAS> &>/dev/null
then
	wakeonlan <MAC Address of HTPC>
fi
What this should do is ping the IP address of the NAS server, if it gets a reply then it sends a Wake On LAN signal to the HTPC via it's MAC Address.

Then set cron to run the script at suitable time intervals.
Last edited by Vypr on Mon Jul 29, 2013 1:39 pm, edited 1 time in total.

User avatar
rpdom
Posts: 11568
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Wake on lan forwarder/tiggers

Mon Jul 29, 2013 1:37 pm

I'd also add a test to see if the HTPC is already running and skip the rest of the script. No need to try and wake it if it is already running.

ghans
Posts: 7366
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Wake on lan forwarder/tiggers

Mon Jul 29, 2013 2:28 pm

Doesn't this model come with the QNAP QPKG package manager ?
You could use the NAS itself to wake the HTPC , if a Wake-on-LAN tool is
available via QPKG. QNAP does seem to run active community forums , too.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Vypr
Posts: 55
Joined: Tue Apr 09, 2013 2:02 am

Re: Wake on lan forwarder/tiggers

Mon Jul 29, 2013 3:18 pm

rpdom wrote:I'd also add a test to see if the HTPC is already running and skip the rest of the script. No need to try and wake it if it is already running.
Good point, don't want to flood the network with WOL requests.
How about:

Code: Select all

#!/bin/bash

#Ping the NAS to see if it responds
if ping -c <ip address of NAS> &>/dev/null
then
   #If the NAS responds, check to see if HTPC is already on
   if ping -c <ip address of HTPC> &>/dev?null
   then
      #if the HTPC responds then do nothing
      :
   else
       #IF the HTPC does not respond, send a WOL signal
      wakeonlan <MAC Address of HTPC>
   fi
fi

User avatar
rpdom
Posts: 11568
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Wake on lan forwarder/tiggers

Mon Jul 29, 2013 4:37 pm

Yes, that would work :)

but the -c option needs a parameter saying how many packets to transmit, like "-c 1".

Also, I'd consider adding a "-W 1" to make the ping time out after one second, which should be enough.

Vypr
Posts: 55
Joined: Tue Apr 09, 2013 2:02 am

Re: Wake on lan forwarder/tiggers

Mon Jul 29, 2013 5:57 pm

rpdom wrote:Yes, that would work :)

but the -c option needs a parameter saying how many packets to transmit, like "-c 1".

Also, I'd consider adding a "-W 1" to make the ping time out after one second, which should be enough.
<sigh> you're really making me work for this aren't you? :P

OK. How's this:

Code: Select all

#!/bin/bash

#Ping the NAS to see if it responds
if ping -c 1 -W 3 <ip address of NAS>  &>/dev/null
then
   #If the NAS responds, check to see if HTPC is already on
   if ping -c 1 -W 3 <ip address of HTPC> &>/dev?null
   then
      #if the HTPC responds then do nothing
      :
   else
       #IF the HTPC does not respond, send a WOL signal
      wakeonlan <MAC Address of HTPC>
   fi
fi
You know that the QNAP-410 supports WOL as well? Why not write a script that wakes up the NAS, waits for 3 mins then wakes up the PC?

Cameronmale83
Posts: 2
Joined: Sun Jul 28, 2013 9:28 am

Re: Wake on lan forwarder/tiggers

Wed Jul 31, 2013 3:25 am

I did investigate the qnap... making wol scripts permanent on the QNAP is not straight forward and each firmware update has messed with this function.

Thank you all for you support, I really appreciate it. Will give it a crack!

allen675
Posts: 4
Joined: Wed Jun 14, 2017 10:52 pm

Re: Wake on lan forwarder/tiggers

Wed Jun 14, 2017 10:55 pm

Hi,

I know this is an old post but I'm kind of hoping that someone can help? I have tried the above code and run into the following error: ./AutoWake.sh: line 7: syntax error near unexpected token `&>'
./AutoWake.sh: line 7: `if ping -c 1 -W 3 <192.168.1.173> &>/dev?null'

I am new to this and am hoping that some kind person can point me in the correct direction?

User avatar
DougieLawson
Posts: 29790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Wake on lan forwarder/tiggers

Thu Jun 15, 2017 12:11 am

Take a the angle brackets out.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

allen675
Posts: 4
Joined: Wed Jun 14, 2017 10:52 pm

Re: Wake on lan forwarder/tiggers

Thu Jun 15, 2017 7:48 am

So to confirm all angle brackets or must those containing the IP & MAC addresses?

ghans
Posts: 7366
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Wake on lan forwarder/tiggers

Thu Jun 15, 2017 12:07 pm

Only the angle brackets surrounding the IP. The others must remian.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

allen675
Posts: 4
Joined: Wed Jun 14, 2017 10:52 pm

Re: Wake on lan forwarder/tiggers

Thu Jun 15, 2017 11:46 pm

Okay,

So this is what I have so far:

Code: Select all

#!/bin/sh

if ping -c 1 -W 3 192.168.1.129 &> /dev/null
then
echo 'TV is on'
if ping -c 1 -W 3 192.168.1.173 &> /dev/null
then
echo 'HTPC already awake happy watching'
else
wakeonlan D0:17:C2:D4:90:49
fi
fi
But it seems to hang and not move onto wakeonlan and send magic packet if no ping response from HTPC. Any ideas?

User avatar
rpdom
Posts: 11568
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Wake on lan forwarder/tiggers

Fri Jun 16, 2017 6:06 am

allen675 wrote:Any ideas?
The example script has "#!/bin/bash" as the first line. Why have you used "#!/bin/sh" instead? That does make a difference. That line specifies the program that will run the script. There are differences between /bin/bash and /bin/sh which could affect the running of the script.

allen675
Posts: 4
Joined: Wed Jun 14, 2017 10:52 pm

Re: Wake on lan forwarder/tiggers

Fri Jun 16, 2017 6:19 pm

Hi,

Thank you for the prompt reply. I have been mucking around with the code so this is something that I had missed. After trying rpdom suggestion this is working perfectly, so a personal thank you to you. I would also like to say thank you for every other members suggestions. Thanks to your collaboration I have managed to get the code working.

The code I now have is as follows:

Code: Select all

#!/bin/bash

if ping -c 1 -W 3 192.168.1.129 &> /dev/null
then
echo 'TV is on'
if ping -c 1 -W 3 192.168.1.173 &> /dev/null
then
echo 'HTPC already awake!!'
else
wakeonlan D0:17:C2:D4:90:49
fi
fi
Kind regards,

Return to “Media centres”

Who is online

Users browsing this forum: No registered users and 6 guests