Categorie: Raspberry Pi

Capturing SAT24 satellite images to create an animation

During the solar eclipse on March 20th 2015 it was nothing but clouds over here in The Netherlands.
So besides following the eclipse on TV I also watched the satellite images on the SAT24 site to track the Moon’s shadow over the continent.
I got the idea to create a small bash script that downloads the satellite images every X minutes in a separate directory.
Those images can be stitched together to create a nice movie.

So, here’s the code:

CURRENTIMAGE=$(date +"%Y%m%d%H%M")

wget -O $TMPDIR/temp.jpg "$INFRARED"

MD5NEW=`/usr/bin/md5sum $TMPDIR/temp.jpg | cut -d ' ' -f 1`
MD5OLD=`/usr/bin/md5sum $TMPDIR/prev.jpg | cut -d ' ' -f 1`

if [ "$MD5NEW" != "$MD5OLD" ]; then
cp $TMPDIR/temp.jpg $TMPDIR/prev.jpg

It’s pretty straight forward.
The image file name is the current date and time and a new image is downloaded using wget.

The only thing that needs an explanation is the md5sum stuff.
Sometimes it happens that the script downloads a image from a few minutes ago and not the current one.
That means that most of the time it’s an image you already have.
I guess this has something to do on the Sat24 side: web servers not in sync or load balancers that don’t balance load.
With md5sum you create a MD5 hash which is ‘unique’.
If the new image has the same MD5 has as the previous image, this new image can be discarded because you’ve already downloaded it.

To make this script run automatically, simply add it to the crontab (I’m using the cron of user pi on my Raspberry Pi here):

<code>*/4 * * * * /home/pi/sat24/</code>

I use intervals of 4 minutes but you can tune that if you like.
Oh, and do not for get to turn on the execute bit of your script.

Okay, you’ve been running this script for a couple of days and you’ve collected hundreds of images.
Now it’s time to stitch them together and make an animation!

Thanks to a great command line tool called avconv (previously known as ffmpeg), you can create a movie file using separate images:

cat images/*.jpg | avconv -f image2pipe -c:v mjpeg -i - -r 25 -map 0 -s 1280x780 -filter:v "setpts=4.0*PTS" out.mp4

Err…yes! It’s that simple!
Just cat the files and pipe them into avconv.
The -s 1280×780 parameter creates a 720p HD video file.
The -filter:v “setpts=4.0*PTS” parameter slows the playback rate down because 0therwise the animation goes a bit too fast. You can fiddle with the number to your taste.
The video created is called out.mp4 which you can rename if you want, of course.

And this is the result:

Some double images might be downloaded once in a while, which you can delete by yourself by wading through the images directory.
Or you could write a script that checks and deletes duplicates for you.

Remote control your GoTo telescope mount using a Raspberry Pi and SkySafari

SkySafari is a great astronomy app for smart devices like the iPhone, iPad and Android.
The SkySafari Plus and Pro versions add the possibility to remote control your GoTo telescope mount using the special SkyFi adapter.
This adapter sends serial (RS-232) commands, received with a wireless connection, to the handset of the GoTo mount.
Using SkySafari in combination with SkyFi increases the number of objects you can observe and current events in the sky (like comet PANSTARRS at the moment) are found easily this way.

I was wondering if it would be possible to create something like SkyFi using the Raspberry Pi.
And yes, it is possible. Quite easy actually!

What do you need?

  • Raspberry Pi configured with a working network connection (wifi preferred, of course).
  • USB to Serial cable.
  • GoTo telescope mount
  • PC Serial to GoTo handset cable. Shipped with your GoTo mount.
  • SkySafari Plus or Pro
  • Basic Linux knowledge

Now how are we to receive the commands from SkySafari?
This is done by the Serial To Network Proxy (ser2net).

Install ser2net:

sudo apt-get install ser2net

Add the following line, using your favorite text editor, at the end of the ser2net configuration file (/etc/ser2net.conf) which contains the port where ser2net is listening on:

4000:raw:0:/dev/ttyUSB0:9600 NONE 1STOPBIT 8DATABITS

In this case, I chose port 4000. You may choose another port but be sure it is between 1024 and 65535 and does not conflict with any other daemons listening on the same port.

Restart the ser2net service with the new configuration:

sudo /etc/init.d/ser2net restart

Next, configure your telescope in SkySafari.
My setup has a SkyWatcher SynScan GoTo on a EQ3-2 equatorial mount.
Be sure to enter your setup and don’t copy my settings bluntly 😉


The IP address in the picture above corresponds with my Raspberry Pi. Of course, you should enter the IP address of your Raspberry Pi.
Same goes for the listening port. I’m using port 4000.
If you configured a different one for ser2net, enter that one.

After that is done, you should try to connect SkySafari with your mount in the Scope menu and you’re off to go!

Using the Raspberry Pi for camera surveillance using Motion and cloud storage

February, 16th 2014
A fully updated post using BoxFS2 with oauth2 authentication.
The previous version of this post used an old version of BoxFS which is now obsolete because changed their API.

If you are looking for a cheap camera surveillance setup, the Raspberry Pi is a great solution.
It is small, easy to install and, most important, has low energy usage.
I own Model B (see the Raspberry Pi Wikipedia page for detail about the models) which uses 3.5 Watts.

There are several open source motion detection applications for Linux such as ZoneMinder and Motion.
Both programs are available through the Rasbian repository.
ZoneMinder looks like a real security control center with all those nice cam screens, but it’s too bloated and too CPU heavy for the Raspberry Pi.
Motion is more lightweight and doesn’t stress the CPU too much when processing 320×200 camera data.
With 2 IP camera’s my average load is less than 0.50 on my RasPi, which also serves as an caching DNS server.

For storage of the AVI video files which contain the captured motion frames, I use a free account. provides the same service as the popular Dropbox.
The reason for choosing is because Dropbox has no open source client. The Dropbox Linux client is closed source and has, at the moment, no support for ARM devices like the Raspberry Pi.
Furthermore the free account gives you 10 GB of free storage. Way enough to store home camera data for a couple of months.

is the weapon of choice to mount your account as a drive partition on your Raspberry Pi.
Some basic Linux knowledge is preferred.

Setting up BoxFS2
First, read the README file on the BoxFS2 site carefully for the needed dependencies 🙂

Install the needed libraries from the command prompt:

sudo apt-get install libxml2-dev libfuse-dev libcurl4-gnutls-dev

Besides some libraries from the Raspbian repository, you’ll also need libapp and libjson.
Get the latest commits from boxfs2, libapp and libjson:

git clone
git clone
git clone

Compile libapp first, then libjson and boxfs2 last using make and sudo make install.
After installing make sure you run the command ldconfig to update links to the libraries for the operating system.
Forgetting this might give you some error messages about not found libraries.

The BoxFS2 binary will be installed in /usr/local/bin.

Creating a BoxFS2 config file
With the command boxfs-init you can create a config file for BoxFS2.
The configuration file will be placed in the directory .boxfs2.

Open an editor and the configuration file would look something like this:

# Conf file for boxfs
# edit to fit your needs.

# Put oauth2 tokens here:
token_file = /home/pi/.boxfs/token

# Set a valid mount point
mountpoint = /home/pi/
verbose = no
largefiles = no

# Configure the cache
cache_dir = /home/pi/.boxfs/cache
expire_time = 1440

# Configure your uid and gid below:
uid = 1000
gid = 1000
fperm = 644
dperm = 755

The mountpoint must be provided in either way. This can be an empty directory called /motion for example.

Also check the user id (uid) and the group id (gid) of the user you are using.
You can check this in the passwd file which is located in /etc.
In my case I’m using user pi which has user id 1000 and group id 1000.

To let Boxfs2 run as a non-root user you have to add your user to the fuse group:

sudo gpasswd -a fuse

If you won’t do this, the following error message will be shown:
fuse: failed to open /dev/fuse: Permission denied

Also the execute bit of the fusermount binary should be set:

sudo chmod +x /bin/fusermount

Forgetting this will cause mounting to fail with this error message:
fuse: failed to exec fusermount: Permission denied

Mounting your account using BoxFS
To start the BoxFS2 client, simply run this command from the home directory of your user:

boxfs -f .boxfs/boxfs.cfg

The first time you run boxfs, you will need to complete the authentication (oauth2) process and grant access to your account. It’s easy, just follow the instructions on the terminal and on your browser.

When the mount is successful, set the right permissions with the command chmod -r 755 <mountpoint>.

To check if everything is doing what it should be doing, go to your BoxFS mount point and try to create or copy some files.
For debugging I recommend to be logged in to your account with your browser to see if things are actually written in to the cloud storage.

Installing and configuring Motion

To install Motion just run this command:

sudo apt-get install motion

Be sure that your camera’s and/or webcams output a 320×200 (or 240) image and Motion is configured with the same resolution.
I’ve tried a resolution like 640×400 pixels, but the CPU load went sky high on the RasPi, so I’ve settled for a lower resolution.
The images generated by my camera’s are quite clear and useful, so I’m happy.
I have no experience over clocking the Pi in combination with Motion, but if you do, please share your findings in the comments.
Same goes for solving the above resolution problem 🙂

Further configuring Motion is something you have to do on your own.
The on line manual is quite clear about the numerous settings which can be done.
Mailing an image snapshot or a simple message when motion is detected is just one of the many possibilities.
Oh, and don’t forget to set the path to your BoxFS2 mount point to store your videos 😉

When you’ve got an mobile device, you can use the app to download an AVI file and watch it using a movie player which supports the file format.
Great when you’re on holiday for example, and want to know what’s going on at home.
And all of this without tampering  your firewall, keeping your home network closed and secure.

I hope this post helps you to set up your own budget camera surveillance system.
For less than 180 euro (that’s 2 decent IP camera’s and a RasPi) you’re all set to go.