TMBTC Post

Raspberry Pi Slideshow


RASPBERRY PI AUTOMATION

Raspberry Pi Slideshow

2013-03-29
raspberry-pi-slideshow
Wanting to do something productive with my Raspberry Pi, I decided to at least get it showing me new art each day. As it turns out... its a little more challenging than I had originally expected. The main reason was resources on the Pi. Many image viewers, both command line and x windows based like to do some crazy things that tend to blow up the memory consumption on my Raspberry. As a result, the kernel will, in turn, enjoy killing the offending process. The following is how I overcame the challenges. The Equipment: Raspberry Pi running Raspbian "wheezy" on a 4GB SD Card HDMI Monitor An Internet connection The Overview: The idea is to get updated images from Deviantart nightly and display them via slide show over the course of the day. The Steps: With a fresh install of Raspbian I booted up the Pi. The initial wizard gives you a few options, here is what I did. 1. Expand the root partition to fill the SD Card 2. Changed the keyboard to the US layout 3. Changed the timezone to reflect where I live 4. Changed the boot into desktop to yes (meaning it will start the desktop after boot). 5. As a matter of security, I also updated the password for the pi user. Reboot the Pi and you should find yourself looking at the desktop once you log in. Add Auto Login: You can skip this part if you don't want to auto login, it wont affect the outcome unless you reboot your machine. Making this as automated as possible, we need to set up the Pi to auto login the pi user. Here's how we do that. Edit /etc/inittab using vi. Of course vi is just my preferred text editor, feel free to use your own favorite. I've heard quite a few people like nano.
sudo vi /etc/inittab
Scroll down till you see the following line:
1:2345:respawn:/sbin/getty --noclear 38400 tty1
Comment it out by adding a pound sign (#) in front of it. Insert a new line and add the following.
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1
Your file should now look something like this:
#1:2345:respawn:/sbin/getty --noclear 38400 tty1
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1
NOTE: If your using a user different than 'pi' you will want to change the user, pi, to your user. Close and save the file. Go ahead and reboot your Pi just to make sure your changes have properly taken affect.
sudo shutdown -r now
Update and Install pqiv Once the machine comes back up, it should automatically boot you into LXDE (the default desktop environment). Go ahead and open a terminal window and update the apt-get repository.
sudo apt-get update
Normally we would issue a simple apt-get install pqiv to install pqiv; however, due to issues with version in the raspbian repository we will need to download, fix, compile, and install pqiv manually. Don’t forget to remove pqiv if you've already installed it at some point.
sudo apt-get remove pqiv
Install git and the dependency gtk2 library for pqiv.
sudo apt-get install git libgtk2.0-dev
We have what we need to build the application, now we need to download the source.
cd
git clone https://github.com/phillipberndt/pqiv.git -b 0.12
Now that you've downloaded the pqiv source, you will notice a new directory in your home directory called pqiv. Go into this directory and run ./configure to validate all preconditions are met and create a platform specific make file.
cd pqiv
./configure
Now we need to fix the source code by replacing the gchar option; with gint option; in the main() function in the pqiv.c file. The line we are looking for is around 2233.
/*gchar option;*/
gint option;
Save and exit vi. Now you've fixed the bug, we will run make and install the application.
sudo make all install
You now have the fixed version of pqiv running on your Pi. Get the slide show images: Now we need to create the process to download the images from Deviant art. To do this, first create a directory in your home directory. Open a terminal session and type in the following commands.
cd
mkdir images
mkdir scripts
cd scripts
Now we need to create the script to get the images from DeviantArt. Create a new file in the scripts directory.
vi ~/scripts/get_images.sh
Inside the script copy and paste the following code. NOTE: Updated wget line to adapt to the change in RSS format from Deviantart.
#!/bin/bash

cd /home/pi/images

rm *.jpg *.png

# go get the files
#landscape files
wget -q -O- "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Adigitalart%2Fpaintings%2Flandscapes+max_age%3A72h&type=deviation" | grep -o '[^ ]*' | grep -o '[^"]*$' xargs wget -c files/home/pi/images/* count 0 one="1" for="" f="" in="" $files="" do="" file="" -b="" $f="" echo="" "checking="" number="" $count"="" +="" $one))="" if="" [="" "$(file="" $f|grep="" jpeg)"="" ];="" then="" mv="" ${f}="" $random.jpg="" elif="" png)"="" $random.png="" ascii)"="" ”skip="" script="" file”="" else="" "unknown="" type="" $f"="" fi="" done<=""
Once you've added the script, save your file and make it executable.
chmod +x ~/scripts/get_images.sh
Just to be sure your script is working execute it via the command line.
cd ~/scripts
./get_images.sh
So... whats this script do you might ask? For starters, using wget, it reaches out and pulls down images from DeviantArt via their RSS feeds. Using grep and sed we save the resulting downloaded file to the images directory. The second part of the script looks at all the files downloaded (some of them end up not being images) and gives them random file names. These random file names are what make the slide show seem a little more "random". But we want this pull to be a automated. To do this we add the script to cron. To edit cron:
crontab -e
And then add the following line at the end of the file.
00 01 * * * /home/pi/scripts/get_images.sh > /home/pi/get_images.log 2>&1
The line above kicks off your script every night at 1:00 am and outputs both output and error to a log file in the home directory of pi. (this is really only to help with troubleshooting if needed). Slide show Image Swapping Next we need to create a set of scripts to refresh the slide show file and make sure the slide show continues to run. First up is a really simple script to continually refresh the slide show image. Create a new script file in your scripts directory.
cd ~/scripts
vi update_slideshow_image.sh
Copy and paste this script into your new file.
#!/bin/bash

cd /home/pi/images
while true;
  do for i in *;
    do cp $i /home/pi/slideshow.jpg;
      echo $i;
      sleep 30;
    done;
  done
Save your file and make it executable.
chmod +x update_slideshow_images.sh
Here is a quick outline of what the above script does. It first changes its current directory to the images directory. Once there, it goes into an infinite loop. Once inside the loop it gets a list of files from your images directory. It then copies the first file to your home directory calling the file slideshow.jpg. The script then waits 30 seconds and then copies the second file, overwriting the existing slideshow.jpg with this new one. The script will do this for each file until it goes through all of them. Then it starts from the begging and does it all over again. At 1:00 am the get_images script will download a new set of images and because the update_slideshow_image get a new file list each time it loops, these new files will get added to the list to be displayed. This may not make much sense now, but it will after in a moment. Using pqiv to display images: Now we need to create the script to display the images.
cd ~/scripts
vi start_slideshow.sh
Copy and past this script into your new file.
#!/bin/bash

# Lets start and restart the slideshow if needed
until /usr/bin/pqiv -i -f -s -w /home/pi/slideshow.jpg; do
  echo "Slideshow crashed with exit code $?. Restarting..." >&2
  sleep 2
done
Save your script and make it executable.
chmod +x start_slideshow.sh
This script is really quite simple. Most of the actual slide show work is done by pqiv. This script's only duty is to kick off pqiv. If the program crashes the script will echo the reason it crashed and then wait a few seconds before restarting the slide show. Why do I do this you might ask? Memory resources on a Raspberry Pi are limited and image viewing software isn't all that great at being memory friendly, especially when trying to load larger files, scale them, and then display them. Do that over a hundred times and you will quickly get killed by the kernel. As a side note, I tried several other image viewing programs like fbi, fim, and feh. While they worked, they each had some small issues and more importantly, they were not fond of refreshing the image when the underlying file changed. Autostart the slide show: To have our slide show kick off automaticly once the Pi reboots. To do this we need to add two .desktop files to autostart. One file will run our update_slideshow_image script that the other will run the start_slideshow script. Here is how you create the first file.
cd /etc/xdg/autostart
sudo vi slideshow_image_changer.desktop
Inside this file add the following.
[Desktop Entry]
Type=Application
Name=Slideshow Image Changer
Comment=Slideshow Image Changer
Exec=/home/pi/scripts/update_slideshow_image.sh
Terminal=true
Save this file and create the second file.
sudo vi slideshow_start.desktop
Add the following to this new desktop file.
[Desktop Entry]
Type=Application
Name=Slideshow Image Changer
Comment=Slideshow Image Changer
Exec=/home/pi/scripts/start_slideshow.sh
Terminal=true
Save and close this file. Prevent the Raspberry from going to sleep: We are almost done... one thing that drove me nuts for a little while was how the Raspberry would occasionally turn off the monitor. I couldn't really narrow down what I did to fix the issue. I updated the following config settings and they seem to work as expected. Update the kbd config file.
sudo vi /etc/kbd/config
Scroll down till you see the BLANK_TIME setting and change it to 0.
# screen blanking timeout. monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
#BLANK_TIME=30
BLANK_TIME=0
Scroll down a little more till you see the POWERDOWN_TIME setting and change it to 0
# Powerdown time. The console will go to DPMS Off mode POWERDOWN_TIME
# minutes _after_ blanking. (POWERDOWN_TIME + BLANK_TIME after the last input)
#POWERDOWN_TIME=30
POWERDOWN_TIME=0
Save and close the config file. Next I ended updating the lightdm.conf file.
sudo vi /etc/lightdm/lightdm.conf
Scroll down till you see the [SeatDefault] section and add a line towards the end of it.
xserver-command=X -s 0 dpms
My screen no longer goes blank and I have the pleasure of having a dynamic slide show all day. Reboot your Raspberry Pi. Provided everything goes as planned, your slide show should start shortly after booting into the LXDE desktop... congratulations!

You might also like
simple-bash-script-to-email-server-status

Simple Bash Script To Email Server Status

2012-08-22

I didn't want to constantly have to log into my servers in order to check on key performance indicators so I decided to write a simple script that would do the checking for me. After collecting results, the script emails them to me. There are a few tools called within the script you might need to install. I also convert any tabs into spaces in order to make sure things line up nicely inside my email. #!/bin/bash SERVER="myserver001" TOEMAIL="admin@myservers.com" FROMEMAIL="myserver001@myserverscom" # Who is logged in and what are they up to WHO=`w` #


Read More...

how-to-fix-pagehandlerfactory-integrated-has-a-bad-module-when-setting-up-asp-net

How to fix: “PageHandlerFactory-Integrated” has a bad module when setting up ASP.NET

2012-08-22

I was recently setting up IIS 7.5 on Windows 2008 R2 for an ASP.NET site and came across the following 500 error: Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list. After a bit of searching, it turns out ASP.NET was not completely installed with IIS even though I checked that box in the "Add Feature" dialog. I found a number of suggestions but found this command. It fixed my issues and got rid of the error. %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i For a 32 bit system, use the


Read More...