2014-05-20, 12:51
Hey.
I want to wake up my server, with WOL and update the library, from my Raspberry PI. I found a script here:
http://forum.xbmc.org/showthread.php?tid=135074&page=2
But the script is not waking my server and giving me a permission error. The thread is dead so i was hoping some of you great python coders could help me out with a simple thing.
I suspect it is because of the way magic packages is being sent. I can wake up my server by doing:
etherwake "MAC-ADDRESS"
And i tried switching the above command instead of this:
But im getting this error:
Here is the script im talking about:
What are my options?
Thanks alot for the help!
I want to wake up my server, with WOL and update the library, from my Raspberry PI. I found a script here:
http://forum.xbmc.org/showthread.php?tid=135074&page=2
But the script is not waking my server and giving me a permission error. The thread is dead so i was hoping some of you great python coders could help me out with a simple thing.
I suspect it is because of the way magic packages is being sent. I can wake up my server by doing:
etherwake "MAC-ADDRESS"
And i tried switching the above command instead of this:
Code:
#Send wakeup packet
msg = '\xff' * 6 + hw_addr * 16
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(msg, ("255.255.255.255", 9))
But im getting this error:
Code:
root@raspberrypi:/opt# python wol2.py
File "wol2.py", line 83
etherwake 44:1e:a1:3e:bc:30
^
SyntaxError: invalid syntax
Here is the script im talking about:
Code:
#!/usr/bin/env python
settings = {
'hostname': '192.168.1.50',
'port': '8080',
'username': '',
'password': '',
'mac_address': '44:1e:a1:3e:bc:30'
}
http_address = 'http://%s:%s/jsonrpc' % (settings['hostname'], settings['port'])
username = settings['username']
password = settings['password']
try:
import json
except ImportError:
import simplejson as json
import urllib2, base64, time, socket, struct
class XBMCJSON:
def __init__(self, server):
self.server = server
self.version = '2.0'
def __call__(self, **kwargs):
method = '.'.join(map(str, self.n))
self.n = []
return XBMCJSON.__dict__['Request'](self, method, kwargs)
def __getattr__(self,name):
if not self.__dict__.has_key('n'):
self.n=[]
self.n.append(name)
return self
def Request(self, method, kwargs):
data = [{}]
data[0]['method'] = method
data[0]['params'] = kwargs
data[0]['jsonrpc'] = self.version
data[0]['id'] = 1
data = json.JSONEncoder().encode(data)
content_length = len(data)
content = {
'Content-Type': 'application/json',
'Content-Length': content_length,
}
request = urllib2.Request(self.server, data, content)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
f = urllib2.urlopen(request)
response = f.read()
f.close()
response = json.JSONDecoder().decode(response)
try:
return response[0]['result']
except:
return response[0]['error']
xbmc = XBMCJSON(http_address)
mac_address = settings['mac_address']
addr_byte = mac_address.split(':')
hw_addr = struct.pack('BBBBBB',
int(addr_byte[0], 16),
int(addr_byte[1], 16),
int(addr_byte[2], 16),
int(addr_byte[3], 16),
int(addr_byte[4], 16),
int(addr_byte[5], 16)
)
#Send wakeup packet
msg = '\xff' * 6 + hw_addr * 16
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(msg, ("255.255.255.255", 9))
#Sleep for 2 minutes
time.sleep(120)
#Send scan request
xbmc.VideoLibrary.Scan()
#Sleep for 5 minutes
time.sleep(300)
#Shutdown
xbmc.System.Shutdown()
What are my options?
Thanks alot for the help!