A digital picture frame with weather forecast
Updating Photos
The simplest way to update the Raspberry Pi might be to wait for some special trigger file to be generated. In this case, you would just list the files in a directory on Dropbox, and when the trigger file exists, you would transfer the files.
Although I might use this method to coordinate a file transfer at work, this solution doesn't exactly scream user friendly. A different method would be to copy over all the files periodically to the Raspberry Pi. In this case, the synchronization is just a matter of removing all existing photos, gathering a list of all images on Dropbox, iterating through that list, and copying over each file. In the future, I might revise the synchronization mechanism, but for now, I will do this once a week.
The first step is to gather up a list of files to be copied over and then to iterate through that list. A rather cute way of doing this is to use both head
and tail
to get a specific entry from the list:
NAME=`head -${IDX} $WORKFILE | tail -1`
Downloading the file from Dropbox is then just a matter of running dbxcli
with the name of the current file to retrieve.
Selecting and Displaying a Picture
Displaying a picture is as easy as running the feh
program with the name of the file to be displayed over the desktop. The entire goal of the picture frame is to allow for dynamic updating of photos, but even keeping that in consideration, the photos will remain fairly static most of the time; therefore, I maintain the current list of files to display, which is generated each time the files are copied from Dropbox.
Displaying all photographs is just a matter of looping through the list of existing files. Each photo should be displayed for at least a few minutes. I decided that the script shouldn't run continuously; instead, from the list of pictures, it should choose the current image, display it, and exit. The script, then, is run by a crontab file every few minutes. For this to work, the script will need to maintain its state between runs.
The pickpicture
method in Listing 2 retrieves the current item in the list to be displayed, advances the index, and then displays the current picture.
Listing 2
Display Bash Code
01 pickpicture() 02 { 03 IDXFILE=$PICDIR/index.dat 04 cd $PICDIR 05 06 IDX=`cat $IDXFILE` 07 CNT=`cat $PICLIST | wc -l` 08 NAME=`head -$IDX $PICLIST | tail -1` 09 10 IDX=$(($IDX + 1)) 11 12 if [ $IDX -gt $CNT ] 13 then 14 echo 1 > $IDXFILE 15 else 16 echo $IDX > $IDXFILE 17 fi 18 19 showpicture $NAME 20 21 cd $INSTDIR 22 }
Downloading Weather Data
Retrieving the weather for a given city is quite easy. The OpenWeather site does the authentication once at the beginning and gives you a time-unlimited key, so you only need to pass the key in with each call:
CMD="http://api.openweathermap.org/data/2.5/weather?id=${CITYID}&appid=${APPID}&units=metric" curl -s $CMD > $TODAY
The script simply makes a call to the OpenWeather URL with the appropriate parameters, and you receive a JSON object in return from the curl
utility. The returned weather structure is not overly complicated: Simply select each field of interest.
Extracting the values was straightforward except for sunrise and sunset, because these values are stored as a Unix UTC value. The good news is that this can easily be converted to a more user-friendly value with the date
command:
# parse out data from data file sunset=`cat $TODAY | jq -r '.sys' |jq -r '.sunset'` sunset=`date --date=@$sunset +'%H:%M:%S'`
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
Arch Linux 2023.12.01 Released with a Much-Improved Installer
If you've ever wanted to install Arch Linux, now is your time. With the latest release, the archinstall script vastly simplifies the process.
-
Zorin OS 17 Beta Available for Testing
The upcoming version of Zorin OS includes plenty of improvements to take your PC to a whole new level of user-friendliness.
-
Red Hat Migrates RHEL from Xorg to Wayland
If you've been wondering when Xorg will finally be a thing of the past, wonder no more, as Red Hat has made it clear.
-
PipeWire 1.0 Officially Released
PipeWire was created to take the place of the oft-troubled PulseAudio and has finally reached the 1.0 status as a major update with plenty of improvements and the usual bug fixes.
-
Rocky Linux 9.3 Available for Download
The latest version of the RHEL alternative is now available and brings back cloud and container images for ppc64le along with plenty of new features and fixes.
-
Ubuntu Budgie Shifts How to Tackle Wayland
Ubuntu Budgie has yet to make the switch to Wayland but with a change in approaches, they're finally on track to making it happen.
-
TUXEDO's New Ultraportable Linux Workstation Released
The TUXEDO Pulse 14 blends portability with power, thanks to the AMD Ryzen 7 7840HS CPU.
-
AlmaLinux Will No Longer Be "Just Another RHEL Clone"
With the release of AlmaLinux 9.3, the distribution will be built entirely from upstream sources.
-
elementary OS 8 Has a Big Surprise in Store
When elementary OS 8 finally arrives, it will not only be based on Ubuntu 24.04 but it will also default to Wayland for better performance and security.
-
OpenELA Releases Enterprise Linux Source Code
With Red Hat restricting the source for RHEL, it was only a matter of time before those who depended on that source struck out on their own.