A few things, mostly technical notes...

Thursday, January 10, 2008

How to ensure Set-Top-Box (STB) is Powered On?

.

How to ensure Set-Top-Box (STB) is Powered On?



STB - in most cases, Set Top Boxes are the boxes the Cable/DishTV companies leave at your place with a remote control for you to flip channels. STBs are external, and in case of models like mine, there appeared to be no reliable method to ensure that it is powered on (Like in case of small power disruption. The computer would probably boot back up, but what about the dumb STB?. Read more about the uncertainity here in this thread. Or, here.)

I initially proposed something naive like this (alt link here) and went on to finalize this working script.

Requisites:
You will need ffmpeg and jp2a installed. On my Ubuntu 7.10, they were installed by running:

sudo apt-get install jp2a ffmpeg 


check_stb (link)

#! /bin/bash

# Authored by Evuraan_AT_gmail_DOT_com

# ABSOLUTELY NO WARRANTY, to the extent permitted by
# applicable law.

# YMMV.
# Use at your own risk.


pvr="/dev/video0"
t="$RANDOM-$RANDOM"
out="/tmp/$t.mpg"
mark="1727"
blank="0"
say="/usr/bin/logger -p info -t mythstb-check"
POWEROFF="0"
POWERON="0"
wakeup="/usr/local/bin/irsend SEND_ONCE blaster1 POWER"
info="/usr/local/bin/irsend SEND_ONCE blaster1 DISPLAY"



send_power_on() {
$say "`date` STB seems to be turned off, last count was $blank, attempting to Power it on" &
$wakeup 1>/dev/null 2>/dev/null || :
sleep 2
}

scan_images(){
for i in `echo /tmp/$t*.jpeg`
do
if [ -s "$i" ]
then
#blank="`jp2a $i --invert --size=72x24 | sed -e 's/./& \n/g'|grep -c "M"`"
blank="`jp2a $i --invert --size=72x24 | sed 's/W/M/g' | sed -e 's/./& \n/g'|grep -c "M"`"
 rm -f "$i" 1>/dev/null 2>/dev/null || :
else
 :
fi
[ "$blank" -gt "$mark" ] && export POWERON="100"
[ "$blank" -le "$mark" ] && export POWEROFF="100"
done
if [ "$POWERON" -eq "100" -a "$POWEROFF" -ne "100" ]
then
# its off
send_power_on
else
# power is on, non blank frames
$say "`date` STB seems to be turned on, last count was $blank"
:
fi

}

purge_stuff(){
[ -f "$out" ] && rm -f "$out" 1>/dev/null >/dev/null || :
}

#ivtv-tune -c 3 -d "$pvr" 1>/dev/null 2>/dev/null &

cd /tmp
$info &

dd if="$pvr" of="$out" bs=64K count=2  1>/dev/null 2>/dev/null

if [ -s "$out" ]
then
ffmpeg -i $out -f image2 -vcodec mjpeg /tmp/$t%d.jpeg 1>/dev/null 2>/dev/null
[ -s "/tmp/${t}1.jpeg" ] && scan_images
else
$say "`date` Unable to query $pvr, as it seems to be in use."
:
fi

purge_stuff &

The Idea:
The idea is pretty simple - read from your ivtv device using dd. ffmpeg then converts them into jpeg files (1 per frame). jp2a analyses each of those frames to check whether they're blank or not.


Implementation:
I placed this in my channel change script (example ), so mythtv ensures that the STB is powered on before changing channels. You can also cron it, but it is better to call this in the beginning of your channel change script, as that way, you have a higher chance of unhindered read access to $pvr.

This can be downloaded to your machine as:
wget http://evuraan.info/evuraan/check_stb.txt  -O /tmp/check_stb

To suite specific needs/situations, one may accordingly need to change the parameters pvr, mark and wakeup.

Feedbacks are welcome.

Tuesday, January 08, 2008

Living in Arverne NY, a bloggers review.

If you're considering living in Arverne (11692 NY) this review may be helpful.

Just don't. Just fucking don't.

Unless you work in Arverne itself, or are retired, or you work for Far Rockaway MTA, this is not the place to live.
Especially if you have to commute in Manhattan, you will have to either drive in, or depend on Public Transportation, aka MTA.


MTA subway A line comes this way, and is the longest route they have, with the oldest, dirtiest trains and slowest too.
Two express buses QM17 or QM16 and other local MTA routes does not make the commute any easier either. Reality is, MTA sucks ass.

Period.

Here's a better sounding analogy about living in Arverne - you live in the fucking boondocks, pay NY City taxes, and have a
two hour commute to the city, and on top of everything you pay the same for decent housing.


Labels: Living in Arverne, Commute from Arverne, Arverne to Manhattan.

Monday, January 07, 2008

How to use ATI REMOTE Wonder II Remote for MythTv Frontend?

How to use ATI REMOTE Wonder II Remote for MythTv Frontend?


Inspired by their wiki-page, I ended up buying ATI REMOTE WONDER II Remote for my new MythTv Front End system. Here's how I setup
this remote control using xmodmap.


Here's how it works: (1) Launch myth front end with a custom keymap. (2) When we finish and exit myth frontend, reset the keymap to
the normal (sane keymap)


Step 0: Disable gnome-screensaver


I added the following to root's crontab to prevent auto screen lock whenever I pressed the lock button:

* * * * * /usr/bin/killall gnome-screensaver 1>/dev/null 2>/dev/null || :


Step 1: Create default/sane keymap


Fire up a terminal window (xterm/gnome-terminal) and run:

xmodmap -pke > /somedir/sanekeys.txt


Step 2: Create a launcher for myth front end


Let us call it /usr/bin/wmyth. Here would be its content.

#! /bin/bash

/usr/bin/xmodmap /somedir/map.txt | /usr/bin/mythfrontend 2>/dev/null
/usr/bin/xmodmap /somedir/sanekeys.txt


Step 3: Create /somedir/map.txt


Place the following as /somedir/map.txt:

! power
keycode 222 = F1
! scan
keycode 229 = F2
! mute
keycode 160 = F3
! recall
keycode 133 = F4
! stop
keycode 232 = F5
! play
keycode 179 = p
! <<
keycode 152 = Q
! >>
keycode 233 = U
! vol+
keycode 176 = F10
! vol-
keycode 174 = F11
! options
keycode 41 = o
! options1
keycode 136 = o
! options2
keycode 56 = F8
! escape
keycode 232 = Escape
! pause
keycode 110 = p
! ff
keycode 102 = Right
! rew
keycode 100 = Left
! arippa
keycode 158 = Escape
! red
keycode 54 = d
! green
keycode 40 = i
keycode 119 = i
keycode 140 = w
! record
keycode 177 = z



Step 4: Launch wmyth, enjoy.

External Channel changer script which looks up channum against freqid

I had to use an external channel changer script as I moved to use the ir blaster of my Hauppauge PVR 150.   
Shortly thereafter I found that myth is calling the channel-changer script with some weird parameters. For instance, 
to change to channel 18, it would evoke the script with an argument of 34590 or so. (Now, try changing your STB  
to channel 34590, you will know how it was barfing.)

I am blaming my DB schema (2 years old). 

Anyways, here's the script that fixes this problem. Save this as /usr/local/bin/change-channel.sh, chmod it, and  
let mythtv-setup know. 

You can also wget this script:

wget http://evuraan.info/evuraan/change-channel.sh.txt -O /usr/local/bin/change-channel.sh

Lets cut the chase, here's the script:

#! /bin/bash

coin="$@"
REMOTE_NAME="blaster"
say="/usr/bin/logger -p info -t mythchannel"
user="mythtv" 
pass="mythpassword"



flip_it() {
for digit in $(echo $score | sed -e 's/./& /g'); do
 irsend SEND_ONCE $REMOTE_NAME "$digit"
 $say "`date` coin is $coin, score is $score, digit is $digit" 
done
sleep 2
}



if [ -z "$coin" ]
then
 RET="1"
else
 bb="`echo " mysql -u $user -p $pass -Ee 'select channum from channel where freqid="$coin" ' mythconverg"`" 
 [ ! -z "$bb" ] && score="`(echo "$bb")| sh|grep channum|awk {'print $2'}`"
fi




if [ -z "$score" ]
then
     RET="1"
else 
 flip_it
 RET="0"
fi

exit $RET

Saturday, January 05, 2008

How to get to use the IR Transmitter of PVR 150 on Ubuntu Gutsy (7.10) ?


How to get to use the IR Transmitter of PVR 150 on Ubuntu Gutsy (7.10) ?

Many many thanks to this post (http://ubuntuforums.org/showthread.php?t=587732) and this too, http://www.blushingpenguin.com/mark/blog/?p=24, here's how to:

  1. Add to /etc/apt/sources.lst:
    deb     http://ppa.launchpad.net/superm1/ubuntu gutsy main restricted universe multiverse

  2. As root, run,
    # apt-get update

  3. New linux-ubuntu-modules should be available at this point, pull them down to your machine:

    # apt-get upgrade

  4. Modify /etc/lirc/hardware.conf to call *only* lirc_pvr150

    # sed -i 's/^MODULES/#MODULES/g' /etc/lirc/hardware.conf
    # echo MODULES="lirc_pvr150" >> /etc/lirc/hardware.conf

  5. Place Firmware in /lib/firmware

    # cd /lib/firmware; wget http://malayalam.homelinux.net/evuraan/haup-ir-blaster.bin

    OR.

    # cd /lib/firmware; wget http://www.blushingpenguin.com/mark/lmilk/haup-ir-blaster.bin


  6. Reboot, dmesg should have these. GOOD LUCK..!

    # dmesg|grep pvr
    [   77.487264] lirc_pvr150: chip found with RX and TX
    [   77.631689] lirc_pvr150: firmware of size 302355 loaded
    [   77.631790] lirc_pvr150: 743 codesets loaded
    [   77.670058] lirc_pvr150: Hauppauge PVR-150 IR blaster: firmware version 1.3.


    At this point, you can go here to follow point 8 onwards, good luck..!

Followers


Creative Commons License
This work is licensed under a Creative Commons License.