Category Archives: Linux

Raspberry Pi – Video loop

Here is a nice week-end project, useful for automatic presentations, restaurant menus and waiting room video entertainment/marketing/information (my case).

I used a 32″ TV with a Raspberry Pi B (512 Mb RAM), a Wifi Adapter and a 64 Gb SD card (40 $CND at Costco) to create a simple video looping device.

My goal is simple, I want to use SFTP to upload videos in a folder, and have a simple Debian service loop and play each video file one by one.

Since I am not always here to restart the service, a simple reboot of the Pi (by unplugging) should restart the whole thing. No technical knowledge required !

Here is how I done it:

  1. Create nice corporate information slide deck
    • I suggest creating a visually interesting Powerpoint Presentation, with FULLY automated transitions and animation.
    • Test the presentation in Powerpoint.
    • Once it is perfectly tuned, export the Powerpoint to a MP4 video (sadly, only possible on Windows, not MAC OS)
  2. Setup the system
    • Install Raspbian with NOOBS on my 64Gb SD Card
    • Log-in with the pi user
    • If needed, setup wifi
      • type : startx
      • In LXDE, use the “Wifi” tool to setup the network
      • Exit LXDE
      • Reboot (sudo shutdown -r 0)
    • As a principle, I always upgrade the debian package and install vim (both are optional)
      • sudo aptitude upgrade
      • sudo aptitude install vim ctags
    • As we will use the CLI based Raspberry Pi Video player, omxplayer, there is no need for other software.
  3. Create the looping “application” (2 scripts and a folder)
    • Create a /home/pi/movies folder
    • Use your favorite SFTP client (ex: Mozilla) to push the corporate and other movie files to the Pi
    • Create the loop script (mine is named ~/declicTV/videoplayer.sh):
  4. mkdir /home/pi/declicTV
    cd /home/pi/declicTV
    vi videoplayer.sh

The code is greatly inspired from here.
I have made a few improvements:

#!/bin/sh
#first version from http://www.cenolan.com/2013/03/looping-video-playlist-omxplayer-raspberry-pi/

# set here the path to the directory containing your videos
VIDEOPATH="/home/pi/movies" 

# you can normally leave this alone
SERVICE="omxplayer"
SERVICE_OPTS="-o hdmi -n 3 -b"

# now for our infinite loop!
while true; do
        if ps ax | grep -v grep | grep $SERVICE > /dev/null
        then
        sleep 1;
else
        for file in $VIDEOPATH/*
        do
                #debug
                echo $SERVICE $SERVICE_OPTS "$file"
                
                #Display Files
                $SERVICE $SERVICE_OPTS "$file"
        done
fi
done
  • Then, it is a simple matter of adding a script to init.d, just like explained here.
    • Don’t forget the update-rc.d part.
    • Here is my init.d declicTV script:
#! /bin/sh
# /etc/init.d/declicTV
# taken from http://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian

# Some things that run always
touch /var/lock/declicTV

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script declicTV "
    nohup /home/pi/declicTV/videoplayer.sh > /home/pi/declicTV/videoplayer.log &
    ;;
  stop)
    echo "Stopping script declicTV"
    killall -9 -r videoplayer.sh
    ;;
  *)
    echo "Usage: /etc/init.d/declicTV {start|stop}"
    exit 1
    ;;
esac

exit 0

I hope this will be helpful to you !

CentOS and VirtualBox NAT Port Forwarding

In my recent experiments, and while preparing for my next post, I stumbled on problems when trying to forward ports of my CentOS Guest VM to my Mac OS based browser. For some reason, even if Port forwarding was properly configured, like so :

Virtual Box Port NAT port forwarding on CentOS
Virtual Box Port NAT port forwarding on CentOS

…my Host system browser could not connect to services on my VM, with the exception of SSH. The solution was simple, CentOS comes with default netfilters rules built-in. These rules allow outgoing trafic, and incoming SSH requests only. The firewall configuration needed to be changed. The simplest way to do so is to disable the firewall completely:

# Run as root !
# Flush (discard) all rules
iptables -F
# Save configuration permanently
/sbin/service iptables save

While this may be very good for VM usage, I don’t like to disable a whole firewall (I feel unclean afterwards when I do). Here is a more sensible solution, that could be a starting point for a more solid security setup :

#Again... as root !
#See config
iptables -L
#save config
iptables-save > /root/iptables-save.txt
#edit config (see below for example)
vim /root/iptable-save.txt
# flush + load config
iptables-restore < /root/iptables-save.txt
# Validate
iptables -L
# Save for good
/sbin/service iptables save

For reference, here is my iptable-save.txt file:

# Generated by iptables-save v1.4.7 on Thu Jul 24 08:28:03 2014
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [471:1082248]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 7222 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 8777 -j ACCEPT 
-A INPUT -j REJECT --reject-with icmp-host-prohibited 
-A FORWARD -j REJECT --reject-with icmp-host-prohibited 
COMMIT
# Completed on Thu Jul 24 08:28:03 2014

It should work immediately, but to test the “iptables-restore”, you should reboot. Main reference: https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-iptables-saving.html http://wiki.centos.org/HowTos/Network/IPTables

Favorite Crunchbang admin commands

I found this script and made a menu shortcut to shutdown my netbook screen and fix the resolution for my external monitor. Here are both commands:

# Close my netbook screen and adjust resolution of ext. monitor
# Labels can be taken from "grandr" command
xrandr --output LVDS1 --off &
xrandr --output VGA1 --mode "1680x1050" &

Also, I often need to administrate the network connections as root (ex : to add a permanent static configuration to the wired card).

sudo nm-connection-editor


Map a USB drive to one specific location and solve the “S to Skip” bug

… in a few steps ! (On Debian based distros)

1 – Use disk-manager or manually add a line like this one to your /etc/fstab file

UUID=8d7548c6-a4c3-49b1-9c08-82c9b90cdc98 /media/BLUELINE ext3 defaults 0 2

2 – (optional) In my case, the hardrive is slow to boot compared to the computer. I need to replace this special line in /etc/defaults/grub. The “rootdelay” option leaves 15 seconds more to the system before trying to mount devices

GRUB_CMDLINE_LINUX_DEFAULT="rootdelay=15 quiet"

then run

update-grub

3 – Reboot

4 – Enjoy ! (Was this simple or what ?)

The state of Ubuntu as a Netbook OS

Remember netbooks ? Still have one ?

I my case, my Netbook is my primary home computer. This Atom “powerhouse” received HD and RAM upgrades… and the external monitor and wireless keyboard/mouse is really making it a decent workstation.

I find this setup is good for all my needs : Programming (Python, PHP), Web Surfing and MP4 watching.

My biggest problem with this rig is the graphic card. It is fine when the extra screen (1680×1050) is not plugged-in… But the problem comes when I try to find a Linux distribution able to correctly display on the extra screen, that is easy to setup, at that does not suck all the (somewhat limited) power in my setup.

In the last 3 weeks, I tried three : Debian Stable(Lenny), Debian Testing(Wheezy) and Ubuntu 11.10 (Oneiric Ocelot)

Lenny was great while it lasted, but is way too boring

I have great words for Lenny. As I always come back to “pure” Debian when Canonical push it too far (Unity introduction, anyone ?). I been with Lenny for the past 3 months with great results, but as always, the problems are :

  • Having to fight for last versions. (Backports, alternative apt sources)
  • Gnome 2 (almost) stock, nuff said.
  • Stable, vanilla, working, old, plain… (qualities for servers, not desktops)

Then I made a mistake. In my quest for trouble, I decided  the current “testing” version of Debian may feel sexier. I was very very wrong.

Wheezy is still working on is whistle

Wheezy is still very much a testing distribution. 3 hours after upgrading, I decided to give Ubuntu a new try. The bugs with Wheezy (this week) were:

  • Broken Wifi
  • Broken eclipse packages

I know it’s my fault. Expecting the “testing” version to be usable so near of the last stable release was madness… anyway, I’m glad if at least you don’t do the same.

Ubuntu, saving the day (for once ?)

Being tired, needing my wifi… I made a move that was maybe pushed on me by despair. I tried Ubuntu 11.10. Last Time I did, on the very same Netbook, I ended my “relationship” with Ubuntu for the following reasons :

  • They” introduced Unity, and took back the good netbook interface I loved (I assume I was the only one)
    • Unity was not ready, but it was made default for some reason.
  • “They” introduced Ubuntu One… And we were all lab rats. (Heavy integration, syncronisation was releasing odd messages when offline, program and/or website failing)
  • “They” changed the UI radically, going as far as removing nautilus. And while nautilus is not perfect, it is better that M$ explorer, and *WAY* better that the first Unity suggestion.

Boy, they made me hate that OS… And they drove me away for a year or so… But now I F$%@ up my Debian setup, and I am ready to give “Them” (Canonical) another chance.

I did the right thing.

Ubuntu 11.10, my comments so far

So far, I notice:

  • Canonical improved it’s own installer. (yet again)
  • The OS is working faster than before. (after some adjustments, see below)
  • I now have modern version of Firefox, and Libre office, by default. (Debian, this is why you fail me on the desktop)
  • Unity is still there, but nautilus is back. (I’m so grateful by the way)
  • As usual with Ubuntu, Wifi setup and encryption setups went very quickly and painlessly.
  • The new UI now feels simplified, and pure.
  • I still use Synaptic.

I’m overall very optimistic for the future, and can say I am slowly coming back on the orange side.

Small adjustment I had to make for my Netbook

Here is the things I had to do to make the Stock Ubuntu 11.10 more friendly:

  • This excellent list of things to do after 11.10 installation on sudubits.com
  • I installed “synaptic” (# sudo apt-get install synaptic)
  • I rebooted, and choose the “Gnome 2D” option before login. This allow for 2 things :
    • It removed “Compiz” from the picture entirely (see the picture below).
    • It allowed my (limited) graphic card to display at higher resolution.
This is the reason Compiz is no longer a "Netbook friendly" software. I made that screenshot by simply moving a nautilus window around.