Bugzilla – Bug 2746
Wake on LAN - PC returns to standby after Power Save period
Last modified: 2009-09-08 09:12:34 UTC
Setup: Ethernet to wireless router, then wireless to SB2. XP settings on the network card set to allow PC to be woken by WOL packet, and Admin Only checkbox also checked. Steps to reproduce: 1. Configure WOL on network card, as above. Set Power Saving settings on the PC to make the PC go into standby after 5 minutes (or whatever). 2. Put the computer into standby (either by automatically or manually will produce the same result). 3. Turn on the SB2. This will wake up the PC. Build a playlist (doesn't matter how - either using browse albums or random mix or whatever). Start listening to the music. Actual Results: After the pre-determined length of time set in Power Saving, the PC goes back to sleep. Once the buffer empties, the SB2 stops playing. Expected Results: The PC stays awake until the SB2 is turned "off" (by using the power button on the SB2 remote). Once the SB2 is turned off, the PC should then start the standby countdown as usual (dependant on whatever else is running on it, of course!). In other words, the SB2 should do something on the PC that keeps it awake. P.S I love my Squeezebox. After Xmas I'll be loving BOTH of my Squeezeboxes! Happy Christmas, and keep up the good work!
Just call in the windows dependent code of slimserver the SetThreadExecutionState function with the proper flags when a player is connected and playing. See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/setthreadexecutionstate.asp peter
This needs to be fixed in slimserver.
Does anybody know what has to happen to this fix in order to get it implemented into SlimServer. I contacted Kevin at slimdevices, and his response was as below Chris, Well, when a bug has a fix checked in, the author of the fix usually puts a note in the bug saying that they checked a fix in and citing the fix number. Then they mark the bug as fixed. Regarding this particular issue, honestly I really don't know. You could possibly put a note in the comments of the bug asking for more specifics, though. Regards, Kevin P.
it needs some perl function to reset the windows timeout. the suggestion above, using I assume C++, is not good because even the windows application is written in perl. Given a perl function, this could be added to slimserver, hopefully. Where exactly, and how to manage it, and the issues that may be caused by it are still unknown.
(In reply to comment #4) > it needs some perl function to reset the windows timeout. the suggestion > above, using I assume C++, is not good because even the windows application is > written in perl. Given a perl function, this could be added to slimserver, > hopefully. Where exactly, and how to manage it, and the issues that may be > caused by it are still unknown. Hi, I am new to the Squeezebox (going to buy one) and read about this bug. I�ve had a similar problem with a PC going to standby and I wrote a (very small) windows app very this, preventing the PC going to standby. The app responds to the windows message which is sent when the PC wants to go to standby and tells the OS that going to standby is not permitted. Now the app looks for a specific process in the process list. If the process is running, the app prevents the system from going to standby - if not the system is going to standby. Resetting the Windows timeout is not possible. However I could check if a specific file is located somewhere on the HD, and if not -> standby. Please contact me directly at rudolf@toad.de if this is useful for you. Cheers, Malte
From this thread: http://forums.slimdevices.com/showthread.php?p=99023 came this interesting snippet: The VB solution below may help to shed some light on whats needed to do it in Perl: http://www.freevbcode.com/ShowCode.Asp?ID=2596
I found this useful information, overview and some details. More info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/wm_powerbroadcast.asp also, from: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/wm_powerbroadcast_messages.asp [quote]WM_POWERBROADCAST Messages The system broadcasts a message to all applications and installable drivers whenever a power management event occurs or whenever an application calls the SetSystemPowerState function to suspend operation. The system broadcasts these events through the WM_POWERBROADCAST message, setting the wParam parameter to the appropriate power management event. For example, the PBT_APMPOWERSTATUSCHANGE event indicates a system power status change. You must ensure that your application responds to the WM_POWERBROADCAST message to properly stop activity when the system enters the sleeping state and to recover transparently when the system enters the working state. When the system enters the sleeping state, it closes network connections. The user can change the hardware configuration or power supply while the system is in the sleeping state. The system broadcasts a PBT_APMQUERYSUSPEND event to request permission to suspend system operation. The system expects each application and driver to determine whether the requested event should occur and to return TRUE if it occurs, or return BROADCAST_QUERY_DENY otherwise. Any application or driver can deny the request and prevent the event from occurring. The system broadcasts a PBT_APMSUSPEND event immediately before suspending operation. This gives applications and drivers one last chance to prepare for the event. In many cases, the system broadcasts these messages without requesting permission to do so. This happens, for example, if an application forces suspension with the SetSystemPowerState function. The system broadcasts the PBT_APMQUERYSUSPENDFAILED event whenever a requested event is denied. These events notify applications and drivers to continue operation as usual. The system broadcasts the PBT_APMRESUMESUSPEND or PBT_APMRESUMECRITICAL event when system operation has been restored. If an application received a PBT_APMSUSPEND event before the computer was suspended, it will receive the PBT_APMRESUMESUSPEND event. Otherwise, it will receive the PBT_APMRESUMECRITICAL event.[/quote]
Also of interest might be the mechanism for handling such events from windows services rather than interactive applications with a window handle. See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/handlerex.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/registerservicectrlhandlerex.asp Although on further reading it is doubtful that these can be used for the slimserver service.. because they need to be called from the services ServiceMain(..) function.
Well, WM_POWERBROADCAST applies to installable drivers too, and it's hard to see them having an interactive window. But maybe they have a deficient one or one they keep invisible all the time. I don't know enough about it.
Created attachment 1180 [details] Plugin to fix this problem for Windows ok.. Here's a plugin that fixed my problem.. I've never written any Perl before.. so be kind. I used the Win32::API module from CPAN to access the Windows function SetThreadExecutionState(). The plugin simply checks all clients every minute, and if any of them are playing it resets the standby timer using the Windows method above. Thanks to everyone for their input.
Thanks, Julian. This will solve my #1 issue with SlimServer. Forgive my ignorance of plugins -- how does it get installed? Which folders go where? Thanks, Drew
This is terrific, thanks Julian. Dan: can we get this included with 6.5/trunk?
Extract it all into the <slimserverInstall>/server/Plugins directory (extract using the pathnames in the zip). or if you really want you can put the Win32::API stuff in the CPAN tree.. but if you dont understand how to do that, then just extract it all to the Plugins directory. Then restart your slim server.. if an entry appears called "Prevent Standby ..." in the Server settings/plugins web page then it has worked. otherwise.. you're up the creek. If you want to put it into the 6.5 release I would recommend adding a few more safeguards. (like checking whether the Win32::API call linking into kernel32.dll succeeds -- I couldn't figure how to do this -- and it worked for me so I didn't bother).
I've commited a slightly updated version of this plugin as change 6837 for 6.5 and change 6838 for 6.2 Thanks!
Julian - I can't seem to get this to work -- it doesn't show up in the Server settings\Plugins page. I did a clean Slimserver 6.2.1 install, then moved the extracted PreventStandby folder into C:\Program Files\Slimserver\server\Plugins directory. So, PreventStandby is at the same level as DateTime, Favorites, Health, Live365, etc. Inside PreventStandby, one level down, is another PreventStandby folder and the auto & Win32 folders. Do I have this correct, or should everything be up a level (ie. auto, etc., would be at the level of Live365...)? Any other ideas? Maybe something needs to go into the CPAN tree? Thanks, Drew
For 6.2.1 extract the zip as is into the plugins folder. the auto and win32 directories need to be in the plugins folder, not in the plugins/PreventStandby folder. You should then have in your Plugins folder: PreventStandby/ auto/ win32/ as well as all your other plugins.
Julian -- This worked. Now I can set my PC sleep timer to 3 minutes instead of 5 hours. Can't tell you how much electricity this will save. You've done your part for global warming! Many thanks, Drew