MySQL & WOL (wake on lan)

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
castortray Offline
Fan
Posts: 501
Joined: May 2009
Reputation: 0
Post: #1
Hi,

I use MySQL (to share and synchronize XBMC userdata profiles between multiple machines) which is installed on my Asrock 330HT on Windows 7 in living room.
I don't use it all the time, so it automatically go to "sleep".

But when is in "sleep" mode I can't (not able to connect to MySQL) run xbmc client on other laptop before I turn on Asrock. How I can send command "wake on lan" to my Asrock before or during start client on another PC/laptop ?
I can't launch addon from programs section of XBMC before Asrock (with MySQL) start before wake up from sleep mode.

[Image: 45YbA.png]

WOL has benn downloaded from official repository version 1.0.0

many thanks for any tips,
Regards
(This post was last modified: 2011-01-29 12:06 by castortray.)
find quote
jhsrennie Offline
Team-XBMC Developer
Posts: 7,236
Joined: Nov 2008
Reputation: 119
Location: Chester, UK
Post: #2
XBMC has a wake on lan function built in. See http://wiki.xbmc.org/?title=List_of_Built_In_Functions

If you create a Python script called default.py and put it in your userdata folder XBMC will execute this script when it starts, and you can have this script send a WOL signal.

JR
find quote
castortray Offline
Fan
Posts: 501
Joined: May 2009
Reputation: 0
Post: #3
wow, nice

I did not know about this earlier
I need to check it.

Many thanks.
Regards
find quote
castortray Offline
Fan
Posts: 501
Joined: May 2009
Reputation: 0
Post: #4
jhsrennie Wrote:XBMC has a wake on lan function built in. See http://wiki.xbmc.org/?title=List_of_Built_In_Functions

If you create a Python script called default.py and put it in your userdata folder XBMC will execute this script when it starts, and you can have this script send a WOL signal.

JR

unfortunatelly it's not working Sad

I've created default.py in C:\Users\%username%\AppData\Roaming\XBMC\userdata

Code:
# Wake-On-LAN
#
# Copyright (C) 2002 by Micro Systems Marc Balmer
# Written by Marc Balmer, marc@msys.ch, http://www.msys.ch/
# This code is free software under the GPL

import struct, socket

def WakeOnLan(ethernet_address):

  # Construct a six-byte hardware address

  addr_byte = ethernet_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))

  # Build the Wake-On-LAN "Magic Packet"...

  msg = '\xff' * 6 + hw_addr * 16

  # ...and send it to the broadcast address using UDP

  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  s.sendto(msg, ('<broadcast>', 9))
  s.close()

# Example use
WakeOnLan('aa:bb:cc:dd:ee:ff')    # Asrock

of course I replace aa:bb:ccBig Grind:ee:ff with my Asrock MAC address

do you know what could be wrong ?
find quote
jhsrennie Offline
Team-XBMC Developer
Posts: 7,236
Joined: Nov 2008
Reputation: 119
Location: Chester, UK
Post: #5
When you're trying to work out what's going wrong the first step is always to enable debug logging then look at xbmc.log to see if there are any clues. In this case you will see something like:

DEBUG: XBPython::Process - no profile autoexec.py (C:\Users\renniej\AppData\Roaming\XBMC\userdata\autoexec.py) found, skipping

which means that I gave you the wrong filename (oops, sorry) it should be autoexec.py.

Also you're doing things the hard way. The autoexec.py just needs to contain:

Code:
import xbmc
xbmc.executebuiltin("WakeOnLan(00-13-72-26-4d-cf)")

I've put in the MAC address of the PC I tested the script on. Obviously replace this with your own MAC address.

JR
find quote
castortray Offline
Fan
Posts: 501
Joined: May 2009
Reputation: 0
Post: #6
jhsrennie Wrote:When you're trying to work out what's going wrong the first step is always to enable debug logging then look at xbmc.log to see if there are any clues.

Also you're doing things the hard way. The autoexec.py just needs to contain:

Code:
import xbmc
xbmc.executebuiltin("WakeOnLan(00-13-72-26-4d-cf)")

I've put in the MAC address of the PC I tested the script on. Obviously replace this with your own MAC address.

JR

thanks for another tip,
but still not working, below my debug logs

Code:
19:59:20 T:5236 M:2161758208   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:21 T:5236 M:2167185408   ERROR: CRemoteControl::Connect - failed to connect
19:59:22 T:1500 M:2167332864   ERROR: Unable to open database: xbmc_video [2003](Can't connect to MySQL server on '192.168.2.3' (10060))
19:59:22 T:1500 M:2167332864   ERROR: Unable to open database at host: 192.168.2.3 db: xbmc_video (old version?)
19:59:24 T:5236 M:2167246848   DEBUG: CRemoteControl::Connect - connecting to: ::1:24000 ...
19:59:25 T:5236 M:2167373824   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:26 T:5236 M:2167390208   ERROR: CRemoteControl::Connect - failed to connect
19:59:29 T:5236 M:2167382016   DEBUG: CRemoteControl::Connect - connecting to: ::1:24000 ...
19:59:30 T:5236 M:2167402496   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:31 T:5236 M:2167148544   ERROR: CRemoteControl::Connect - failed to connect
19:59:34 T:5236 M:2167238656   DEBUG: CRemoteControl::Connect - connecting to: ::1:24000 ...
19:59:35 T:5236 M:2167218176   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:36 T:5236 M:2167496704   ERROR: CRemoteControl::Connect - failed to connect
19:59:39 T:5236 M:2167742464   DEBUG: CRemoteControl::Connect - connecting to: ::1:24000 ...
19:59:40 T:5236 M:2167758848   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:41 T:5236 M:2167934976   ERROR: CRemoteControl::Connect - failed to connect
19:59:43 T:1500 M:2166685696   ERROR: Unable to open database: xbmc_music [2003](Can't connect to MySQL server on '192.168.2.3' (10060))
19:59:43 T:1500 M:2166685696   ERROR: Unable to open database at host: 192.168.2.3 db: xbmc_music (old version?)
19:59:44 T:5236 M:2166157312   DEBUG: CRemoteControl::Connect - connecting to: ::1:24000 ...
19:59:45 T:5236 M:2166730752   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:46 T:5236 M:2166747136   ERROR: CRemoteControl::Connect - failed to connect
19:59:49 T:5236 M:2167652352   DEBUG: CRemoteControl::Connect - connecting to: ::1:24000 ...
19:59:50 T:5236 M:2167644160   DEBUG: CRemoteControl::Connect - connecting to: 127.0.0.1:24000 ...
19:59:51 T:5236 M:2167652352   ERROR: CRemoteControl::Connect - failed to connect


WakeOnLan - Magic packet from autoexec.py has been send after I turn on
manually my Asrock (with MySQL database)


Code:
19:59:53 T:1500 M:2166919168    INFO: Loading user windows, path C:\Users\Mario\AppData\Roaming\XBMC\addons\skin.customizableconfluence\720p
19:59:53 T:1500 M:2166222848   DEBUG: Load Skin XML: 72304.43ms
19:59:53 T:1500 M:2166222848    INFO:   initialize new skin...
19:59:53 T:1500 M:2166222848    INFO: Loading skin file: Pointer.xml
19:59:53 T:1500 M:2166099968    INFO: Loading skin file: DialogVolumeBar.xml
19:59:53 T:1500 M:2166079488    INFO: Loading skin file: DialogSeekBar.xml
19:59:53 T:1500 M:2166165504    INFO: Loading skin file: DialogKaiToast.xml
19:59:53 T:1500 M:2166161408    INFO: Loading skin file: DialogMuteBug.xml
19:59:53 T:1500 M:2166124544   DEBUG: CGUIAudioManager::Initialize
19:59:53 T:1500 M:2166120448   DEBUG: CAudioContext::SetActiveDevice - SetActiveDevice from 1 to 2
19:59:53 T:1500 M:2166120448   DEBUG: CAudioContext::RemoveActiveDevice - Removing device 1
19:59:53 T:1500 M:2165776384   DEBUG: CWDSound::direct_sound_enumerator_member_callback - found Device: Primary Sound Driver
19:59:53 T:1500 M:2165776384   DEBUG: CWDSound::direct_sound_enumerator_member_callback - found Device: Speakers (High Definition Audio Device)
19:59:53 T:1500 M:2165776384   DEBUG: CWDSound::direct_sound_enumerator_member_callback - found Device: Digital Audio (S/PDIF) (High Definition Audio Device)
19:59:53 T:1500 M:2165776384   DEBUG: CAudioContext::SetActiveDevice - (default playback device).
19:59:53 T:1500 M:2165563392    INFO: Loading C:\Users\Mario\AppData\Roaming\XBMC\addons\skin.customizableconfluence\sounds\so​unds.xml
19:59:53 T:1500 M:2165559296    INFO:   skin loaded...
19:59:53 T:1500 M:2165559296   DEBUG: Activating window ID: 12999
19:59:53 T:1500 M:2165555200   DEBUG: Checking if window ID 12999 is locked.
19:59:53 T:1500 M:2165555200   DEBUG: ------ Window Init (Startup.xml) ------
19:59:53 T:1500 M:2165555200    INFO: Loading skin file: Startup.xml
19:59:53 T:1500 M:2165547008    INFO: removing tempfiles
19:59:53 T:1500 M:2165542912   DEBUG: ADDON: Starting service addons.
19:59:53 T:1500 M:2165542912  NOTICE: initialize done
19:59:53 T:1500 M:2165542912  NOTICE: Running the application...
19:59:53 T:1500 M:2165534720   DEBUG: CApplication::ExecuteXBMCAction : Translating SetFocus(10)
19:59:53 T:1500 M:2165534720   DEBUG: CApplication::ExecuteXBMCAction : To SetFocus(10)
19:59:53 T:1500 M:2165522432    INFO: initializing python engine.
19:59:53 T:1500 M:2165522432   DEBUG: Win32DllLoader::Load(special://xbmcbin/system/python/python24.dll)
19:59:53 T:1500 M:2164027392   DEBUG: new python thread created. id=1
19:59:53 T:1500 M:2164019200   DEBUG: CNetwork::NetworkMessage - Starting network services
19:59:53 T:1500 M:2164011008  NOTICE: ES: Starting event server
19:59:53 T:6072 M:2164006912   DEBUG: thread start, auto delete: 0
19:59:53 T:6072 M:2164006912   DEBUG: Python thread: start processing
19:59:53 T:1500 M:2163998720    INFO: JSONRPC Server: Successfully initialized
19:59:53 T:1500 M:2163978240   DEBUG: CLastfmScrobbler: Clearing session.
19:59:53 T:1500 M:2163978240   DEBUG: CLibrefmScrobbler: Clearing session.
19:59:53 T:3564 M:2163970048   DEBUG: thread start, auto delete: 0
19:59:53 T:3564 M:2163970048  NOTICE: ES: Starting UDP Event server on 0.0.0.0:9777
19:59:53 T:3564 M:2163965952  NOTICE: UDP: Listening on port 9777
19:59:53 T:1500 M:2165309440 WARNING: CRenderSystemDX::BuildPresentParameters - xbmc compiled with an d3d sdk not supporting D3DSWAPEFFECT_FLIPEX
19:59:53 T:6956 M:2164617216   DEBUG: thread start, auto delete: 0
19:59:53 T:6072 M:2164609024  NOTICE: -->Python Interpreter Initialized<--
19:59:53 T:6072 M:2164609024   DEBUG: XBPyThread::Process - The source file to load is C:\Users\Mario\AppData\Roaming\XBMC\userdata\autoexec.py
19:59:53 T:6072 M:2164604928   DEBUG: XBPyThread::Process - Setting the Python path to C:\Users\Mario\AppData\Roaming\XBMC\userdata;C:\Users\Mario\AppData\Roaming\XBMC​\addons\script.module.simplejson\lib;C:\Users\Mario\AppData\Roaming\XBMC\addons\​script.module.beautifulsoup\lib;C:\Program Files (x86)\XBMC\addons\script.module.pil\lib;C:\Users\Mario\AppData\Roaming\XBMC\addo​ns\script.module.elementtree\lib;C:\Program Files (x86)\XBMC\addons\script.module.pysqlite\lib;C:\Program Files (x86)\XBMC\system\python\DLLs;C:\Program Files (x86)\XBMC\system\python\Lib;special://xbmcbin/system/python/python24.zip;C:\Program Files (x86)\XBMC\system\python\DLLs;C:\Program Files (x86)\XBMC\system\python\lib;C:\Program Files (x86)\XBMC\system\python\lib\plat-win;C:\Program Files (x86)\XBMC\system\python\lib\lib-tk;C:\Program Files (x86)\XBMC
19:59:53 T:6072 M:2164604928   DEBUG: XBPyThread::Process - Entering source directory C:\Users\Mario\AppData\Roaming\XBMC\userdata
19:59:53 T:6780 M:2163982336   DEBUG: thread start, auto delete: 1
19:59:53 T:1500 M:2156740608   DEBUG: CApplication::ExecuteXBMCAction : Translating ReplaceWindow(Home)
19:59:53 T:1500 M:2156740608   DEBUG: CApplication::ExecuteXBMCAction : To ReplaceWindow(Home)
19:59:53 T:1500 M:2156740608   DEBUG: Activating window ID: 10000
19:59:53 T:1500 M:2156740608   DEBUG: Checking if window ID 10000 is locked.
19:59:53 T:1500 M:2156740608   DEBUG: ------ Window Deinit (Startup.xml) ------
19:59:53 T:1500 M:2156740608   DEBUG: ------ Window Init (Home.xml) ------
19:59:53 T:3944 M:2155458560   DEBUG: thread start, auto delete: 1
19:59:53 T:3944 M:2155446272    INFO: WEATHER: Downloading weather
19:59:53 T:3944 M:2155433984   DEBUG: Win32DllLoader::Load(special://xbmcbin/system/libcurl.dll)
19:59:53 T:3944 M:2155175936   DEBUG: Win32DllLoader::Load(special://xbmcbin/system/libidn-11.dll)
19:59:53 T:3944 M:2155171840   DEBUG: Win32DllLoader::Load(special://xbmcbin/system/libeay32.dll)
19:59:53 T:3944 M:2155089920   DEBUG: Win32DllLoader::Load(special://xbmcbin/system/libssl32.dll)
19:59:53 T:3944 M:2154201088   DEBUG: Win32DllLoader::Load(ADVAPI32.DLL)
19:59:53 T:3944 M:2154192896   DEBUG: Win32DllLoader::Load(KERNEL32.DLL)
19:59:53 T:3944 M:2154184704   DEBUG: Win32DllLoader::Load(NETAPI32.DLL)
19:59:53 T:3944 M:2154024960   DEBUG: FreeLibrary(NETAPI32.DLL) -> 07145C90
19:59:53 T:3944 M:2154024960   DEBUG: Win32DllLoader::Unload NETAPI32.DLL
[b]19:59:53 T:1500 M:2153938944    INFO: CNetwork::WakeOnLan - Magic packet send to 'e0-cb-4e-65-21-8d'[/b]
19:59:53 T:4172 M:2153476096   DEBUG: thread start, auto delete: 1


My auteoxec.py file content:

Code:
import time, os
import xbmc
xbmc.executebuiltin("WakeOnLan(e0-cb-4e-65-21-8d)")

time.sleep(5)
xbmc.executebuiltin("XBMC.RunScript(%s/default.py,-startup)" % ( os.path.join( os.getcwd(), "../addons/script.autoupdate/" )))

Sad

maybe you know how to send WOL packet, before XBMC will try to connect with database ?
find quote
jhsrennie Offline
Team-XBMC Developer
Posts: 7,236
Joined: Nov 2008
Reputation: 119
Location: Chester, UK
Post: #7
I don't know whether autoexec.py is executed before or after XBMC connects to the MySQL server; actually I suspect it may run simultaneously in a separate thread.

You might be better off writing a batch file to send a WOL then pause then start XBMC. If you want to do this there are loads of command line WOL apps for Windows. I use wolcmd.exe, which I think is from Depicus.

JR
find quote
castortray Offline
Fan
Posts: 501
Joined: May 2009
Reputation: 0
Post: #8
ok,
I will try and let you know.

thanks
find quote
castortray Offline
Fan
Posts: 501
Joined: May 2009
Reputation: 0
Post: #9
it's working !! Smile
I'm using http://www.mediafire.com/?5n7vprm2d07b3pc

wol.bat
Code:
mc-wol.exe aa:bb:cc:dd:ee:ff
timeout 10
start xbmc.exe

thanks again for help
find quote
t4_ravenbird Offline
Senior Member
Posts: 177
Joined: Mar 2012
Reputation: 5
Post: #10
Have a look at my post here, maybe this would be what you are looking for ? ; http://forum.xbmc.org/showthread.php?tid=124340
find quote
zebraitis Offline
Donor
Posts: 361
Joined: Jan 2008
Reputation: 6
Location: NorthAm
Post: #11
All,

Just thought I would add my .02 ...

I went through this process today, independent of the notes in this thread.


In general, if your MYSQL is on a home server that sleeps, YOU MUST wake that server before XBMC can begin to run on your HTPC.


So... that is why the Wake-On-Lan plug-ins that are available in XBMC won't do the trick: The plug-in will never run if XBMC does not start, and XBMC will not start if it can't ping the MYSQL database.

Simple enough, right?


So, for me, running win7 64bit, I built a simple .bat file for a free WOL program available at:

http://www.gammadyne.com/cmdline.htm#wol

I put the WOL.EXE program into c:\program files\WOL (which I created on the HTPC).

And then I created a .bat file (that I chose to call "An XBMC WOL.bat") that contains:

C:\PROGRA~1\WOL\WOL 00235400c245

(where that last string of info is the MAC of your NIC in the server. Yours WILL be different.)


Then I placed that .bat file in startup of HTPC

... walla-walla washington, it works.


The way that my HTPC behaves is that windows boots, The WOL .bat runs in the background, XBMC starts, and there is a pause at the XBMC Boot screen while my MYSQL starts up.

Once it does, then it moves forward to display my profile choices. (if you have not enabled profiles, you won't see that).


In effect, it accomplishes that same effect that castortray did when he included a "timeout 10" command in his WOL program of choice.

(... but I get to look at the AWESOME XBMC 11 / Eden boot screen while waiting.)


Best regards,

v.


(Disclaimers: This assumes that your home server with MYSQL sleeps, and that you have S3 sleep and MYSQL set up correctly. The bat file discussed here would need to be loaded on every HTPC in your home environment. WOL usually only works via wired ethernet. I have not tested this wirelessly. This is WOL only, not wake over internet. Flying Monkeys may slow your progress, however you will likely still succeed.)
find quote