XBMC on Pi: Add TV/monitor Power Save support when idle?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Milhouse Offline
Team-Kodi Member
Posts: 3,841
Joined: Jan 2011
Reputation: 89
Post: #46
(2014-03-06 22:22)vbat99 Wrote:  I'll check in about 3 hrs what "tvservice --status" says when
a) Raspbmc handles HDMI suspend
b) texturecache.py handles suspend.
c) I put the TV into suspend.

I figure It's something I'm missing in the procedure.

You should add some logging to your /home/pi/mytv.sh to make sure the calls are being received and handled correctly. I'm pretty sure they are, so I just need some clarity on what the actual problem is - is it XBMC exiting unexpectedly, or did none of your CEC commands work?

(2014-03-06 22:22)vbat99 Wrote:  BTW: When I type the command and press enter, I don't get the next command prompt. Have to Crtl-Z to get back to command prompt. (Above test I'll open an second PuTty window). And when we get this working, I'll need to figure out how to add running this on Raspbmc start-up, but figure their forum probably has info on how to do this.

Thanks for taking the time to look into this.

Rob

When you run the command at the command line it will never exit, it runs forever (it's a daemon, in that sense). You have to press ctrl-c to terminate it. Under normal circumstances it will be started automatically when your Pi starts (not sure how to do this on Raspbmc, on OpenELEC you just add an entry to autostart.sh) and will remain running until the Pi is shutdown. It doesn't really do much though, it's just listening for notifications and will be active only when it needs to do something which in the case of a Pi with virutal suspend support is only after receiving the OnSleep and OnWake notifications.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #47
That'll show you how much I know about Linux. Enough to be dangerous. LOL.

Do ya wanna hold my hand and show me how to add logging to that mytv.sh script (that I pinched from one of your earlier posts)?

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
Milhouse Offline
Team-Kodi Member
Posts: 3,841
Joined: Jan 2011
Reputation: 89
Post: #48
I've pushed a new version (v1.5.4) of texturecache.py that includes additional logging when calling bin.tvservice showing when it is called and the response received, that should help identify if there is a problem.

(2014-03-06 22:47)vbat99 Wrote:  That'll show you how much I know about Linux. Enough to be dangerous. LOL.

Do ya wanna hold my hand and show me how to add logging to that mytv.sh script (that I pinched from one of your earlier posts)?

Easiest thing to do is add some "echo" commands to your /home/pi/mytv.sh script so that any calls to it are logged to a file (which I've called /tmp/tvservice.log):
Code:
#!/bin/bash

/opt/vr/bin/tvservice $1

case "$1" in
  "--off")       echo "standby 0" | cec-client -s >/dev/null;;
  "--preferred") echo "on 0" | cec-client -s >/dev/null;;
esac
echo "$(date) called with $1 param" >> /tmp/tvservice.log

Now look in /tmp/tvservice.log to see if/when it is called, which I'm pretty sure it will be, hence why I'm not entirely clear on what the actual problem is! Smile

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #49
Noted, should be able to test in 1 1/2 hrs, if not, in 7 hrs when I get home.

Thanks again.

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
Milhouse Offline
Team-Kodi Member
Posts: 3,841
Joined: Jan 2011
Reputation: 89
Post: #50
Looks like "virtual suspend" on R-Pi is being dropped from future test builds due to problems (and there are more important issues to fix before Gotham final) so it looks like we're back with this hack restarting xbmc to re-enable HDMI.

@vbat99: rbphdmi will work automatically, choosing the best method depending on whether "virtual suspend" is supported or not, so it's still worth getting this bin.tvservice script working for you.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(This post was last modified: 2014-03-07 00:25 by Milhouse.)
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #51
(2014-03-07 00:11)MilhouseVH Wrote:  Looks like "virtual suspend" on R-Pi is being dropped from future test builds due to problems (and there are more important issues to fix before Gotham final) so it looks like we're back with this hack restarting xbmc to re-enable HDMI.

@vbat99: rbphdmi will work automatically, choosing the best method depending on whether "virtual suspend" is supported or not, so it's still worth getting this bin.tvservice script working for you.

Darn it. And it looked like a Win-Win too.

So alt method will be where we exit XBMC, and on power-on XBMC restarts? So I will have to remove that 10 second delay mentioned Here to have a speedier restart.?

So I should wait for a new build without the virtual suspend before commencing.

And one last question. What were the problems being reported? or links so I can read up.

(might have to see about building my own xbmc with virtual suspend....(that'll be a learning curve and a half!))

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
Milhouse Offline
Team-Kodi Member
Posts: 3,841
Joined: Jan 2011
Reputation: 89
Post: #52
(2014-03-07 00:37)vbat99 Wrote:  Darn it. And it looked like a Win-Win too.

I'm sure it will be back once more pressing matters are fixed.

(2014-03-07 00:37)vbat99 Wrote:  So alt method will be where we exit XBMC, and on power-on XBMC restarts? So I will have to remove that 10 second delay mentioned Here to have a speedier restart.?

Yes, the alternative method is for rbphdmi to toggle the HDMI status (via @bin.tvservice as outlined previously) but when enabling HDMI it also requires xbmc.bin to be restarted so yes, remove the 10 second delay.

(2014-03-07 00:37)vbat99 Wrote:  So I should wait for a new build without the virtual suspend before commencing.

Whatever you add to the bin.tvservice script for extra CEC control should hopefully work with or without virtual suspend, so carry on.

(2014-03-07 00:37)vbat99 Wrote:  And one last question. What were the problems being reported? or links so I can read up.

(might have to see about building my own xbmc with virtual suspend....(that'll be a learning curve and a half!))

Several issues were reported in the Raspbmc and OpenELEC test threads - inability to power off or reboot, some cases of HDMI switching off while playing back a video, also breaking CEC control.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #53
(2014-03-07 00:49)MilhouseVH Wrote:  Several issues were reported in the Raspbmc and OpenELEC test threads - inability to power off or reboot, some cases of HDMI switching off while playing back a video, also breaking CEC control.

Ok, those are kinda big issues to ignore just for little old me. LOL.

Looks like it'll be later tonight for me before I can do more testing.

Thanks for the quick replies btw.

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #54
Finally gotten around to doing some more tests.

I stayed on the first build from miappa with virtual suspend and did some tests

File 20140308.txt has putty commands and responses.
File t2 - new.txt has debug log from texturecache.py

Now, inbetween testing I had to kill XBMC and restart it, as I had a Black screen, not gui present.

Also one time, XBMC went to sleep, and woke itself up again, but my resolution was changed to 640x480 ( I have it at 1280x720, and gui at 720, as I don't play anything over 720p)

Next is to update to latest build which has virtual suspend removed (or disabled, not sure). WIll return with those results soon.

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #55
Second test completed and working as it should.

Putty log

t3.txt debug log of texturecache.py

I'll need to remove that 10 second restart delay that Raspbmc has, and figure where to put the command so it survives a reboot.

Any thing stick out in these logs?

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
Milhouse Offline
Team-Kodi Member
Posts: 3,841
Joined: Jan 2011
Reputation: 89
Post: #56
(2014-03-07 22:02)vbat99 Wrote:  Any thing stick out in these logs?

No not particularly, as it's working as it should! Smile

On your previous test, I have no idea why XBMC was exiting when it entered the suspend state, but that's probably a bug with virtual suspend in Raspbmc and one of the reasons why it has now been pulled - that's not how it should be operating, and not how it works/worked in OpenELEC (at least not in my setup).

So without broken virtual suspend confusing things, it's now just a matter of handling the CEC side of things in your /home/pi/mytv.sh script, telling your TV to do whatever you want it to do when HDMI is disabled (--off) and re-enabled (--preferred).

One post which may be worth a read is this one, as it has some useful links but does mention that using cec-client can break XBMC CEC control although I don't know how insurmountable that is likely to be longer term (it's not going to be a problem when XBMC is being restarted each time, which is the case without virtual suspend). It certainly would be nice if CEC was accessible via JSON which is something Montellese is/was looking at.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(This post was last modified: 2014-03-07 22:20 by Milhouse.)
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #57
@MillhouseVH

Thanks for the links, I'll have a read.

I'm thinking I can add this line to rc.local and it'll get fired up on each boot?
Code:
/home/pi/texturecache.py @logfile=/home/pi/t3.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi

Or else does it need to go into /etc/init.d/?
If so I'd have to make a new file, like texturech.sh containing
Code:
#!/bin/bash
/home/pi/texturecache.py @logfile=/home/pi/t3.txt @debug=yes @xbmc.host=localhost @bin.tvservice=/home/pi/mytv.sh rbphdmi
??

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
Milhouse Offline
Team-Kodi Member
Posts: 3,841
Joined: Jan 2011
Reputation: 89
Post: #58
Your second script looks OK, although as I say I've no experience of Raspbmc and unsure what the best method is for starting a script at boot. If you have cron enabled, you could try adding a "@reboot" job, but rc.local sounds like a good bet. Perhaps a Raspbmc expert can advise (or ask on their forum?) One thing you'll want to avoid is running the startup script as root - it should still work when started by root, but from a security standpoint you should try and run your startup script as user "pi" since you'll be writing to files in the /home/pi folder.

One thing to bear in mind is that that texturecache.py could be started before xbmc.bin, in which case texturecache.py will terminate with an error as it won't be able to establish communication with xbmc.bin, so you may need to add a delay of some duration ("sleep 20" seconds or whatever) to ensure that texturecache.py isn't started until there's a high probability that xbmc.bin now running.

Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(This post was last modified: 2014-03-07 22:36 by Milhouse.)
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #59
You may be right there.

I left in the debug and logfile info and I only get
Code:
2014-03-08 09:29:36.966533:MainThread: Command line args: ['/home/pi/texturecache.py', '@logfile=/home/pi/t4.txt', '@debug=yes', '@xbmc.host=localhost', '@bin.tvservice=/home/pi/mytv.sh', 'rbphdmi']
2014-03-08 09:29:36.977857:MainThread: Current version #: v1.5.5
2014-03-08 09:29:36.978600:MainThread: Current platform : linux2
2014-03-08 09:29:36.979355:MainThread: Python  version #: v2.7.3.0 (final)
so I'll add sleep 20 infront of /home/pi/texturecache.py', '@logfile=/home/pi/t4.txt', '@debug=yes', '@xbmc.host=localhost', '@bin.tvservice=/home/pi/mytv.sh

See what happens

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
vbat99 Offline
Posting Freak
Posts: 858
Joined: Aug 2009
Reputation: 20
Location: New Zealand
Post: #60
Seems it doesn't like calling my script if run from rc.local
Code:
2014-03-08 09:46:31.501013:Thread-1  : bin.tvservice response: [state 0x12001a [HDMI CEA (4) RGB lim 16:9], 1280x720 @ 60Hz, progressive]
2014-03-08 09:46:31.508035:Thread-1  : [DEBUG] HDMI is [on], Screensaver is [inactive], Player is [inactive], Library scan [inactive], Can Suspend [no]
2014-03-08 09:50:19.467932:MainThread: libListen.BUFFER RECEIVED (len 94)
2014-03-08 09:50:19.469338:MainThread: libListen.PARSING JSON DATA: {"jsonrpc":"2.0","method":"GUI.OnScreensaverActivated","params":{"data":null,"sender":"xbmc"}}
2014-03-08 09:50:19.470444:MainThread: libListen.PARSING COMPLETE, elapsed time: 0.001407 seconds
2014-03-08 09:50:19.471457:MainThread: libListen.PERFORMING CALLBACK: Name [rbphdmi_listen], with Id [None], Method [GUI.OnScreensaverActivated], Params [{u'data': None, u'sender': u'xbmc'}]
2014-03-08 09:50:19.486126:Thread-1  : [DEBUG] Screensaver has activated
2014-03-08 09:50:19.491771:MainThread: libListen.CALLBACK RESULT: [False] Name [rbphdmi_listen], Id [None], Method [GUI.OnScreensaverActivated], Params [{u'data': None, u'sender': u'xbmc'}]
2014-03-08 09:50:19.493616:MainThread: libListen.READING SOCKET UNTIL CALLBACK SUCCEEDS...
2014-03-08 09:50:19.496810:Thread-1  : [DEBUG] HDMI power off in 900 seconds unless cancelled
2014-03-08 10:05:19.498954:Thread-1  : bin.tvservice (checking if TV is powered on) calling subprocess [/home/pi/mytv.sh --status]
2014-03-08 10:05:19.748561:Thread-1  : bin.tvservice response: [state 0x12001a [HDMI CEA (4) RGB lim 16:9], 1280x720 @ 60Hz, progressive]
2014-03-08 10:05:19.755224:Thread-1  : bin.tvservice (enabling/disabling HDMI) calling subprocess [/home/pi/mytv.sh --off]
2014-03-08 10:05:19.837228:Thread-1  : bin.tvservice response: [Powering off HDMI
/home/pi/mytv.sh: line 6: cec-client: command not found]
2014-03-08 10:05:19.838171:Thread-1  : bin.tvservice (checking HDMI status) calling subprocess [/home/pi/mytv.sh --status]
2014-03-08 10:05:19.903657:Thread-1  : bin.tvservice response: [state 0x120002 [TV is off]]
2014-03-08 10:05:19.907932:Thread-1  : [DEBUG] HDMI is now off

Will remove from rc.local and reboot, then run manually, see if getting better results.

Media Companion Dev.
Media Companion - XBMC Media Companion
find quote
Post Reply