FAQ  •  Register  •  Login

Prevent hibernate/standby/sleep

<<

Tigerix

Serviio newbie

Posts: 2

Joined: Sun May 06, 2012 11:36 pm

Post Sun May 06, 2012 11:47 pm

Re: Prevent hibernate/standby/sleep

After just watching a movie and being stopped in the middle by standby a few times, I am really frustrated.
So I wanted to give feedback and then realize with searching that its already been discussed here. :-)

Really glad, as I am really hoping for a solution and fix.

Either ways - great piece of software Serviio!!
Thanks and keep up the good work.

Tigerix
<<

TyrionBot

Serviio newbie

Posts: 1

Joined: Mon Jun 04, 2012 12:42 pm

Post Mon Jun 04, 2012 1:00 pm

Re: Prevent hibernate/standby/sleep

I think Serviio is a great piece of software. I'm amazed at how well it works, but I also would like this feature added. So, I did some searching to find out how this feature is supposed to be coded.

I found that the winapi call to tell the computer that a program requires the computer to not go to sleep/hibernate is explained here, http://msdn.microsoft.com/en-us/library ... 85%29.aspx.
As far as coding this in Java, ps3mediaserver already supports this feature and here is how they coded it, https://ps3mediaserver.googlecode.com/s ... Utils.java.

Overall, this seems like a pretty simple feature to add. At minimum, it seems like it would require, checking that you are running in windows, calling a function like ps3mediaserver's disableGoToSleep when streaming video or doing any other operation that should be considered active, and calling a function like ps3mediaserver's reenableGoToSleep when the activity is done.

You could also code a setting that allows the user to either have serviio disable the sleep function altogether or only disable sleep/hibernate while streaming content.

Also, as far as OSX, here is a example, but it seems like a kludge instead of the proper way, http://stackoverflow.com/a/53276
<<

Tigerix

Serviio newbie

Posts: 2

Joined: Sun May 06, 2012 11:36 pm

Post Mon Jun 04, 2012 2:12 pm

Re: Prevent hibernate/standby/sleep

Good news!

I have found an universal solution, which is doing exactly what I was looking for since a long time.
Made me so happy, that I really want to share it with you now. :-)

Whenever downloading / uploading with any Software - you usually don't want it to be interrupted by Standby or Hibernate.
And this is exactly what Coffee (certainly perfect suiting Name) is doing.

You can claim at which download / upload speeds you don't want your machine to become idle.
This means you can keep your Standby/Hibernate settings just as high/low as you want them to be,
with them being ignored as long as your traffic is higher than the thresholds.

Have nice day. :-)
Tigerix


Image
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Tue Jun 05, 2012 9:05 am

Re: Prevent hibernate/standby/sleep

great, thanks
<<

coalado

Serviio newbie

Posts: 7

Joined: Thu Aug 25, 2011 7:36 pm

Post Wed Jul 25, 2012 2:57 pm

Re: Prevent hibernate/standby/sleep

If you still want to implement this:
http://pastebin.com/7VtGNUUe
<<

hans

Serviio newbie

Posts: 8

Joined: Wed Feb 01, 2012 10:49 am

Post Thu Aug 02, 2012 6:20 am

Re: Prevent hibernate/standby/sleep

Is this implemented in version 1.0?
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Thu Aug 02, 2012 12:54 pm

Re: Prevent hibernate/standby/sleep

hans wrote:Is this implemented in version 1.0?

no
<<

Satjit

Serviio newbie

Posts: 10

Joined: Sat Jun 16, 2012 6:34 pm

Post Sat Feb 02, 2013 3:16 pm

Re: Prevent hibernate/standby/sleep

Wow! I've been looking for this as well. Thanks a ton :D
<<

Darkfalz

Serviio lover

Posts: 60

Joined: Fri Feb 22, 2013 10:50 am

Post Mon Mar 11, 2013 5:47 am

Re: Prevent hibernate/standby/sleep

Coffee works well but once the system standby period expires and Coffee is keeping it awake, if you pause for longer than a minute your PC will go into standby. I've made a feature request to the Coffee author to allow a configurable delay after network activity stops before sleeping. Would obviously be superb if Serviio had this natively, but all good things to those who wait :)
Sony KDL-55HX750 and BDV-N990W (Home Theatre)
Sony KDL-40D3100 and BDP-S390 (Loungeroom)
<<

J.M.

Serviio newbie

Posts: 4

Joined: Fri May 31, 2013 8:37 am

Post Fri May 31, 2013 10:10 am

Re: Prevent hibernate/standby/sleep

Hi All,

here is simple workaround for Windows :

1) search/run "Power Options" setting and create 2 power plans. For example one for sleep and one for never sleep etc.

2) Run "powercfg -list" in power shell to idendify GUID of your power plans. You need this in the script in step 3.
  Code:
PS C:\Users\user\Desktop> powercfg -list

Existing Power Schemes (* Active)
-----------------------------------
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e  (Balanced)
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c  (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a  (Power saver) *


3) create simple power shell script for example sleep.ps1. This script checks if there is ESTABLISTED connedtion to any IP 192.168.0.1??. You can change the condition if you know your TV ip is static or you have more TV and want to keep connection only to some of them or whatever reason you have. Command powercfg -s [Power Scheme GUID] sets active the choosen powerplan. So if connetion to TV is found than Power plan never sleep is used, when there is no connection than Power plan sleep is used (check every 5 mins from task scheduler). In my case script looks like this ->

  Code:
$str = netstat -a -n | select-string -pattern "ESTABLISHED" | select-string -pattern  "192.168.0.1\d{2}"
if ($str) {
   "$str"
   "String is not empty"
    POWERCFG -S 381b4222-f694-41f0-9685-ff5bb260df2e
} else {
   "$str"
   "String is null or empty"
    POWERCFG -S a1841308-3541-4fab-bc81-f71556f20b4a
}


4) search/run "Task Scheduler" and create new task triggered every 5 minutes which executes the script above.

5) thats all. If you have problem with running power shell scripts than google it or start it as I start it -> powershell.exe -noprofile -executionpolicy bypass -file C:\xxxxx\sleep.ps1

6) I forget about serviio service needs to be restarted after wake up from sleep. For this create new schedule in Task Scheduler triggered by event : Log=System; Source=Power-Troubleshooter; Event ID=1. This schedule is started every time your pc wakes up and it should execute simple script :
  Code:
net stop serviio
net start serviio


7) thats probably all you need to watch TV uninterupted and save some trees :-)

P.S. I think you can apply same logic of the workaround for Linux.
<<

blopa

Serviio newbie

Posts: 11

Joined: Sat Mar 30, 2013 1:30 am

Post Sat Jun 01, 2013 3:50 am

Re: Prevent hibernate/standby/sleep

J.M.: worked like a charm!
I've been looking for something like this since a few months ago
however, I had to remove the "\d{2}" or it won't work. what is that for? sorry I'm totally new to scripts :)

A big thanks for your contribution!!!

Pablo
<<

J.M.

Serviio newbie

Posts: 4

Joined: Fri May 31, 2013 8:37 am

Post Sat Jun 01, 2013 8:40 am

Re: Prevent hibernate/standby/sleep

Hi blopa,

\d{2} should be 2 decimal number. Because my TV receives ip from DHCP usually from 192.168.0.100 to 192.168.0.103 - depending on which network device starts fist and gets the lower ip from router. If 192.168.0.1 is working for you than your TV ip is probably 192.168.0.1 or there are no more ESTABLISHED connections to any other devices. You can test in power shell command
  Code:
netstat -a -n | select-string -pattern "ESTABLISHED"
before and after you play movie from serviio and see difference - new established connections are from your TV -> you have to change the if condition to filter only this connections.
<<

DenyAll

DLNA master

Posts: 2257

Joined: Fri Mar 08, 2013 11:16 pm

Location: Adelaide, Australia

Post Sat Jun 01, 2013 10:16 am

Re: Prevent hibernate/standby/sleep

Hi J.M.

Firstly, thanks for this. This is a great approach to the issue.
Secondly, I now have to blame you for a sleepless night last night ;). I spent most of last night using your method to try a slightly different approach. To be fair, most of my time was spent getting the task scheduler to work (finicky thing that is).

I have made some mods to your script - I have never programmed with Powershell before so if you see any potential enhancements (eg. not sure how to define constants) please let me know. What I have done is more complex than what you did, but it removes the requirement for steps 1 and 2 in your post. It also removes the (very slim) risk of your PC being left in the wrong power scheme state (eg. if someone turns the PC off before the scheme is reset).

My code for step 3 above uses a bit of C programming embedded in a powershell script:
  Code:
$code=@'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
  static extern void SetThreadExecutionState(uint esFlags);

public static void KeepSystemAwake(uint esFlag)
    {
        SetThreadExecutionState(esFlag);
    }
'@

$keepAwake=Add-Type -memberDefinition $code -name "SystemSleep" -namespace SleepFunctions -passThru
$ES_CONTINUOUS = [uint32]"0x80000000"
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040"
$ES_DISPLAY_REQUIRED = [uint32]"0x00000002"
$ES_SYSTEM_REQUIRED = [uint32]"0x00000001"

$str = netstat -a -n | select-string -pattern "ESTABLISHED" | select-string -pattern  "192.168.0.9\d{1}"
if ($str) {
   "$str"
   "String is not empty"
    $keepAwake::KeepSystemAwake($ES_CONTINUOUS -and $ES_AWAYMODE_REQUIRED)
} else {
   "String is null or empty"
    $keepAwake::KeepSystemAwake($ES_CONTINUOUS)
}
Instead of setting different power schemes as you have done, I have used the WIN API function SetThreadExecutionState (see MSDN page here for details) to tell your PC to enter an Away Mode state while a connection exists. The Away Mode state is a special state recommended for media streaming - your PC goes into a partial sleep mode (eg. screen is shut off) but full processor etc is available.

I have tested this and all works well so far. Any feedback most welcome.

Windows XP and Windows Server 2003 users: the above won't work as-is, as these OS's do not support Away Mode. You need to change the line $keepAwake::KeepSystemAwake($ES_CONTINUOUS -and $ES_AWAYMODE_REQUIRED) to $keepAwake::KeepSystemAwake($ES_SYSTEM_REQUIRED) in the above. This will simply stop the PC entering sleep (rather than entering Away Mode).

ps. @blopa: my code uses "192.168.0.9\d{1}". To illustrate J.M.'s answer to your post, my code matches any IP's in the range 192.168.0.90 to 192.168.0.99. This is where I have statically assigned all of my renderers (eg. my PS3 is on .90 and my Panasonic is on .95)
DenyAll
Panasonic Viera FX800A | Panasonic Viera CS610A | Sony PS4 | Sony PS3 | Panasonic DMP-BD79 | Yamaha RX-V500D | iPad | Windows 10 | Serviio 1.10.1 Pro
WinHelper | MediaInfo

Beta Tester, Moderator
Please do not PM me for support as any solution cannot be shared with others.
<<

J.M.

Serviio newbie

Posts: 4

Joined: Fri May 31, 2013 8:37 am

Post Sat Jun 01, 2013 3:46 pm

Re: Prevent hibernate/standby/sleep

Hi DenyAll,

sorry for sleepless night :-). I am also not familiar to power shell, the few commands I used I had to google. I was first also thinking about using SetThreadExecutionState but because I am not programmer I gave up :-).

P.S. If PC being left in the wrong power scheme state is not big problem because task is scheduled every 5 mins so it will be corrected in 5mins.
<<

DenyAll

DLNA master

Posts: 2257

Joined: Fri Mar 08, 2013 11:16 pm

Location: Adelaide, Australia

Post Sat Jun 01, 2013 11:54 pm

Re: Prevent hibernate/standby/sleep

....is not big problem because task is scheduled every 5 mins so it will be corrected in 5mins.
Of course it will, sorry didn't think that thru.
I am still testing all combinations (eg. pausing, multiple renderers playing) and so far all good. I have also added a for loop so that you can simply list all the ip addresses for the renderers you want to monitor. Will post that later today. If you are using this, let me know of any issues.
DenyAll
Panasonic Viera FX800A | Panasonic Viera CS610A | Sony PS4 | Sony PS3 | Panasonic DMP-BD79 | Yamaha RX-V500D | iPad | Windows 10 | Serviio 1.10.1 Pro
WinHelper | MediaInfo

Beta Tester, Moderator
Please do not PM me for support as any solution cannot be shared with others.
<<

blopa

Serviio newbie

Posts: 11

Joined: Sat Mar 30, 2013 1:30 am

Post Sun Jun 02, 2013 2:12 am

Re: Prevent hibernate/standby/sleep

J.M. and DenyAll, thanks for illustrating me about the option to add decimals to the IP number. My TV uses a static IP so I'm clear now that I don't need to add it.

zip, you probably want to keep an eye on this post, something good is going on here :). Maybe a link to the FAQs until a native solution can be developed?

Serviio rocks and its community too!
<<

DenyAll

DLNA master

Posts: 2257

Joined: Fri Mar 08, 2013 11:16 pm

Location: Adelaide, Australia

Post Sun Jun 02, 2013 7:01 am

Re: Prevent hibernate/standby/sleep

Hi again. In my last post I mentioned using a loop for all renderer IP addresses. While that was working fine, I have had a better thought... I changed the loop to work for TCP Ports.

This new code below searches the NETSTAT command output based on established sessions to TCP port's 8895 and 23424 (for streaming and Mediabrowser respectively). This has the advantage that it doesn't matter if IP addresses change due to dynamic allocation, or if you add a new renderer device. Its all catered for without changing the code.

  Code:
$code=@'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
  static extern void SetThreadExecutionState(uint esFlags);

public static void KeepSystemAwake(uint esFlag)
    {
        SetThreadExecutionState(esFlag);
    }
'@

$keepAwake=Add-Type -memberDefinition $code -name "SystemSleep" -namespace SleepFunctions -passThru
$ES_CONTINUOUS = [uint32]"0x80000000"
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040"
$ES_DISPLAY_REQUIRED = [uint32]"0x00000002"
$ES_SYSTEM_REQUIRED = [uint32]"0x00000001"

$str=""
$Ports = @("8895", "23424")  <# Monitored Serviio Ports #>

$NetStat = netstat -a -n | select-string -pattern "ESTABLISHED"
foreach ($element in $Ports) {
    $str = $str + ($NetStat | select-string -pattern (":" + $element))
}

if ($str) {
   "$str"
    $keepAwake::KeepSystemAwake($ES_CONTINUOUS -and $ES_AWAYMODE_REQUIRED)
} else {
   "String is null or empty"
    $keepAwake::KeepSystemAwake($ES_CONTINUOUS)
}
I have tested with three renders going simultaneously. Have tested pause (the failing of other approaches like coffee.exe).

@zip if you are monitoring this thread (or any others) - are there any other ports we should consider eg. for ServiiGo (will?). Note that we are limited to TCP sessions (not UDP ports).
ps. in case you saw my earlier post with the IP address loop - I deleted it in favour of this approach.
DenyAll
Panasonic Viera FX800A | Panasonic Viera CS610A | Sony PS4 | Sony PS3 | Panasonic DMP-BD79 | Yamaha RX-V500D | iPad | Windows 10 | Serviio 1.10.1 Pro
WinHelper | MediaInfo

Beta Tester, Moderator
Please do not PM me for support as any solution cannot be shared with others.
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Sun Jun 02, 2013 1:15 pm

Re: Prevent hibernate/standby/sleep

No, just these 2 re used for streaming
<<

DenyAll

DLNA master

Posts: 2257

Joined: Fri Mar 08, 2013 11:16 pm

Location: Adelaide, Australia

Post Sun Jun 02, 2013 1:46 pm

Re: Prevent hibernate/standby/sleep

Thanks. I think the above is in its final state pending any feedback from users.
DenyAll
Panasonic Viera FX800A | Panasonic Viera CS610A | Sony PS4 | Sony PS3 | Panasonic DMP-BD79 | Yamaha RX-V500D | iPad | Windows 10 | Serviio 1.10.1 Pro
WinHelper | MediaInfo

Beta Tester, Moderator
Please do not PM me for support as any solution cannot be shared with others.
<<

blopa

Serviio newbie

Posts: 11

Joined: Sat Mar 30, 2013 1:30 am

Post Fri Jun 07, 2013 1:48 am

Re: Prevent hibernate/standby/sleep

Guys, my smart TV is on 192.168.1.5 (static) but even when turned off, the TCP connection shows as "Established". This is from the netstat command:

"TCP 192.168.1.4:8895 192.168.1.5:46237 ESTABLISHED"

I left the computer alone for about 1hr but the "ESTABLISHED" status was still there. How is that possible? I even unplugged the TV but nothing.

In my testings, when I play a movie from TV and after a few mins I turn it off, the connection seems to be dropped correctly
Is seems to happen only when the TV is connected for +1hr (very inaccurate calculation).

I'running Windows 7 and my rendered is a Samsung SmartTV ES6800
Any experiencies or suggestions are very welcome

@DenyAll, would you please explain what your script does exactly? will it change the power plan if a something is connected to port 8895? if not, how/when a pc will enter in sleep mode? I can't read scripts...sorry about that!

@J.M., your script is still working great. The problem I described above seems to be from my side. If you faced something similar please let me know

Thanks in advance,

Blopa




Blopa
PreviousNext

Return to Feature requests

Who is online

Users browsing this forum: No registered users and 11 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.