Nevermind what I thought up below I have looked a bit further into network receiver/sender and setup a solution dependent on that, seems to do the job well so far I've tested (which is not a lot yet). Did find that when I set a password for the sender/receiver I had an MD5 checksum error (password was 100% correct, both sides), no password works.
--------------
Hi all,
I'm totally unfamiliar with python, so excuse my noobishness

What I'm trying to accomplish is the following scenario;
I have a NAS (well, just a desktop) that goes to sleep. I run MediaPortal on my HTPC and it loads stuff of the NAS but ofcourse can't while it's asleep. Now to overcome some issues with MP I would like to be able to ping my NAS when I press play. If I do not get an answer I (in a second or so) I want eventghost to send a wol to the nas first, then wait a couple seconds (I think 10 would be fine) and then fire play to MP.
If it receive a response to the ping it can play immediatly.
I have found some script that pings and looks for the response, seemed like a nice start. Can't get it to go though cause it's chokin' on re.search, no clue why. This does nothing else yet, just trying something first, if I can't get this to go myself it's kinda hopeless

Any help getting there would be awesome!
Code: Select all
import re
from subprocess import Popen, PIPE
from threading import Thread
print 'starting'
class Pinger(object):
def __init__(self, hosts):
for host in hosts:
pa = PingAgent(host)
pa.start()
class PingAgent(Thread):
def __init__(self, host):
Thread.__init__(self)
self.host = host
def run(self):
p = Popen('ping -n 1 ' + self.host, stdout=PIPE)
m = re.search('Gemiddelde = (.*)ms', p.stdout.read())
if m: print 'Round Trip Time: %s ms -', p.stdout.read(), self.host
else: print 'Error: Invalid Response -', self.host
hosts = [
'192.168.1.30'
]
Pinger(hosts)
I also though about not having the timeout for the NAS to wake but using the network sender/receiver, so the NAS will send an event to the HTPC when it's set to go.