[mythtv-users] New Upnp Channel Changer Script (Dish VIP 211 users definitely read)

Dan Wilga mythtv-users2 at dwilga-linux1.amherst.edu
Mon Mar 2 14:12:44 UTC 2015


On 2/25/15 11:26 AM, Karl Newman wrote:
> On Wed, Feb 25, 2015 at 6:54 AM, Dan Wilga 
> <mythtv-users2 at dwilga-linux1.amherst.edu 
> <mailto:mythtv-users2 at dwilga-linux1.amherst.edu>> wrote:
>
>     Ideally, there would be some way for the channel change script to
>     tell Myth, "I can't tune that" and have the recording marked as
>     "failed". Looking at the Myth source code, I don't think it does
>     anything with the script return value, so I guess there's nothing
>     to be done in this regard.
>
> It must do something with the channel change script return value, 
> because I just had some recordings fail because my channel change 
> script returned an error. They showed up in Myth as grayed out with 0 
> bytes, so it was obvious they had failed. It tripped me up, actually, 
> because the channel change script failure was only logged as an info 
> status under the channel logging group, so I didn't see the error in 
> the log. I submitted a patch to change a failure to be logged as an 
> error under general (so it will be seen with the default logging 
> options) and it's been incorporated into master.
>
> So, in your case, if the channel change script can detect the failure 
> and propagate that as a nonzero script exit code, it should be picked 
> up by Myth.
Hi Jon,

I'm attaching a revised version of your script which returns a non-zero 
status if tuning fails. In addition to the case where Myth is trying to 
tune to an unsubscribed channel, it also handles the case where the 
receiver is not working for some reason, since it relies on a specific 
return value from the upnp endpoint.

When Myth sees a non-zero return value it leaves behind a zero-byte 
recording. While this is less-than-great, at least it does reschedule 
the program to record again at another time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20150302/ac4e0178/attachment.html>
-------------- next part --------------
#!/usr/bin/env bash

# Basic Settings
HOST=$1
PORT='49200'
QUERY='upnp/control/EchoSTB2'
SERVICE='urn:schemas-echostar-com:service:EchoSTB:2'

#Action to wake up a sleeping STB
WAKE_ACTION='WakeUp'
WAKE_ARGS='<Tuner>0</Tuner>'

#Action to change the channel
CHANGE_ACTION='SetChannel'
CHANGE_ARGS="<Tuner>0</Tuner><Channel>$2</Channel>"

#Disable Inactivity Standby
INACTIVE_ACTION='InactivityStandby'
INACTIVE_ARGS='<Enable_disable>Disable</Enable_disable><hours_4_to_8>8</hours_4_to_8>'

upnp_send()
{
	local HOST=$1
	local ACTION=$2
	local UPNP_ARGS=$3

	# prepare SOAP message
	local CR=$'\r'
	local MESSAGE='<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:'${ACTION}' xmlns:u="'${SERVICE}'">'${UPNP_ARGS}'</u:'${ACTION}'>
</s:Body>
</s:Envelope>'

	exec 6<>/dev/tcp/$HOST/$PORT || {
		echo "error: can not connect to $HOST:$PORT" >&2
		return 1
	}

	cat <<EOF >&6
POST /$QUERY HTTP/1.0$CR
Host: $HOST:$PORT$CR
SOAPAction: "${SERVICE}#${ACTION}"$CR
Content-Type: text/xml; charset="utf-8"$CR
Content-Length: ${#MESSAGE}$CR
$CR
$MESSAGE
EOF

	recv=`cat <&6`

	exec 6<&-
	exec 6>&-
	#Uncomment to debug
	#echo $recv
}

#Wake the STB up
upnp_send $HOST $WAKE_ACTION $WAKE_ARGS

#Wait for it to wake up
sleep .7

#Change the channel
upnp_send $HOST $CHANGE_ACTION $CHANGE_ARGS
[[ $recv != *"<New_Channel>$2</New_Channel>"* ]] && exit 1
sleep .1

#Disable the inactivity timeout
upnp_send $HOST $INACTIVE_ACTION $INACTIVE_ARGS

#Sleep to allow the STB time to settle before the tuner tries to access (HD-PVR)
sleep .1


More information about the mythtv-users mailing list