raspberry pi magic

Raspberry Pi is magic!

So far it does:
– MPD server (using my media center as SMB share) connected to my speakers (the audio is not that great)
– DNS resolver (http://blueeyedcreature.net/blog/?p=901)
– home automation server (using fhem)
– Airport style music receiver (shairport)
DLNA renderer (for plex?)
– I even used it as a status screen but I didn’t like the giant screen in my home – http://blueeyedcreature.net/blog/?p=811

but I want more!

My plex server goes to sleep nicely 15 minutes after no movie is playing but I need the SMB data for MPD and I can Wake-on-LAN only from the Internet, not when I use the device in the LAN

so we need to use some tricks here :)

1) prevent idling to sleep when SMB share is used
2) prevent idling to sleep when someone is using plex (like.. from an iPad or other transcoding is going on)

Step one:

server has MAC BC:5F:F4:E5:B4:F7 and IP 192.168.178.128
I can wake it using the FritzBox or the “awake” command (fedora) or “etherwake” on ubuntu
just send a magic packet and it wakes up :)

now how to do this?

simple script:

#!/bin/bash

pingInterval=60 #time interval, in seconds, between checks that the server is still awake.
target=192.168.178.128 #WOL target ip address
targetMAC=BC:5F:F4:E5:B4:F7 #WOL target MAC

wake () {
tcpdump -i eth0 -c 1 -p host $target
etherwake $targetMAC
#echo WOL sent to $target at $targetMAC
return
}

while sleep $pingInterval; do
varPing=`ping -s 1 -c 2 $target > /dev/null; echo $?`
if [ $varPing -eq 0 ]; then
#echo ping success
else
#echo ping fail
wake
fi
done

this wakes the PC if there is an ARP request

how about preventing it from going to sleep at all as long as the smb share is used?

ubuntu used to have a command that would –poke the gnome-screensaver but its gone…

to be continued…

references:
1)

Raspberry Pi Remote Wake/Sleep-On-LAN Server

sudo chmod +x /home/pi/wol.sh
sudo crontab -e

add this to the bottom

@reboot sh /home/pi/wol.sh > /dev/null