Taking mundane objects and connecting them to one another is one of the key intentions of the whole IoT phenomenon. In our next recipe, we will create a digital picture frame. However, ours is is not the typical off-the-shelf version where you load images from an SD card. Instead, we will use a combination of web services that are commonly used in IoT together with a wireless image player to update the digital picture frame dynamically and seamlessly from a smartphone.
The materials needed are as follows:
You will also need to set up two web service accounts:
Using IFTTT
For this recipe, we will incorporate the If This Then That (IFTTT) web service. Although not perfect, IFTTT is a fun, rapid development tool for prototyping IoT scenarios and use cases. There are other ways to perform what I will outline later; you could hook up other popular third-party apps, such as Instagram, Flickr, and Twitter. However, I prefer to keep the additional installations at a minimum and establish more of a least common denominator environment that provides a simpler development path.
For long-term serious product builds, IFTTT is not a good choice because it is too "black box", too opaque in its functionality to rely on for final designs. However, for rapid protoyping and idea generating, it is highly useful. With IFTTT, you can iterate quickly and nimbly using a host of different web services that will always lead to new ideas and directions for your development.
Part one: The smartphone setup
Perform the following steps:
Setting up and testing the Dropbox script on the BBB
$ cd
$ git clone https://github.com/andreafabrizi/Dropbox-Uploader/
$ cd Dropbox-Uploader
$chmod +x dropbox_uploader.sh $./dropbox_uploader.sh
~/Dropbox-Uploader$ ./dropbox_uploader.sh
You should see the screen output with a set of instructions:
This is the first time you run this script.
Back to your desktop client
Before responding to the terminal prompts, you will now need to set up a Dropbox App via your desktop client (PC or Mac). This app will hook to the Dropbox Uploader script.
Perform the following steps:
Can your app be limited to its own folder?
No
What type of files does your app need access to?
Specific file types—My app only needs access to certain file types, like text or photos.
Last question, what type of files will your app use?
Images
NowPix
to remain consistent with the directory/album name that we set up on the iPhone. Then, finish by clicking on the Create App button.Back to the BBB
The next series of steps continue with the verification/authentication process using Dropbox. Perform the following steps:
# App Key: YOUR_API_KEY_HERE
Now, App Secret has been generated. Cut and paste that string from the Dropbox to the terminal window, as shown in the following code:
# App secret abcdefghijklmnop1234 Permission type, App folder or Full Dropbox [a/f]: App folder (f) App key is abcdefghijklmnop1234, App secret isabcdefghijklmnop1234 and Access level is Full Dropbox. Looks ok? [y/n]: [y/n]: y
Hit return and you are finished at least with the installation.
Testing and running the script
We now need to verify that the script operates as expected: downloading images from Dropbox and placing them in a specified directory.
$ cd Dropbox-Uploader $ ./dropbox_uploader.sh list /IFTTT/iOS_Photos/NowPix
$ ./dropbox_uploader.sh download -s /Apps/NowPix /home/debian/NowPix
We added the -s
option that skips the already existing files when you download/upload; otherwise, the default parameter is to overwrite the files in the target directory.
$ cd NowPix $ ls
cron
job that automatically runs the script at specified intervals. We will begin this part by opening crontab
in our default editor with the following command:$ crontab -e
The -e
option tells the shell to open our default editor, which in our case is nano
.
You should take note of these comments from the original script developer:
## Running as cron
job
Dropbox Uploader relies on a different configuration file for each system user. The default configuration file location is HOME_DIRECTORY/.dropbox_uploader
. This means that if you do the setup with your user and then try to run a cron
job as root, it will not work.
So, when you run this script using cron
, keep the following things in mind:
Remember to set up the script that the user used to run the cron
job.
Always use the -f
option to specify the full configuration file path because sometimes in the cron
environment, the home folder path is not detected correctly.
For security reasons, I recommend you to not share the same configuration file with different users.
*/3 * * * * /home/debian/Dropbox-Uploader/dropbox_uploader.sh -s download /IFTTT/iOS_Photos/NowPix /home/debian/
The number 3
is the frequency in which the cron
job will run, which in our case is every 3 minutes. We have it set for such a high frequency only for testing purposes. When we are finished with our testing, you should change this number to a higher one, perhaps every few hours or longer, depending on how often you plan to add photos to your NowPix
digital picture frame.
The rest of the line with all the asterisks corresponds to the following layout for a cron
job:
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command
cron
, it is a good idea to verify that the job has run as expected. You can perform this easily with the following command that checks an e-mail file that crontab
automatically runs once a cron
job has been set up:$ tail -f /var/mail/debian
You should see a log of the system e-mails that crontab
will send, including the output from the downloader.sh
script. This output should mirror the kind of output you saw when you were running the earlier bash script in the terminal window.
feh
, a lightweight and powerful image viewer, as shown in the following code:$ sudo apt-get update $ sudo apt-get install feh
feh
requires -x
so that you can run the app remotely via vnc as follows:$ feh -x
$ feh -FD10 /home/debian/NowPix
FD is the command to run a slideshow, whereas the number after FD is an adjustable play duration for the image.
The program must also point to the directory with the images that will run as a slideshow. Use the Esc button on your desktop to exit from the slideshow.
You may see another permissions-related error when you try to execute the feh
program. The error may say something similar to the following code:
Invalid MIT-MAGIC-COOKIE-1
If so, run the following command to delete the .Xauthority
file:
$ rm .Xauthority*
$ sudo -i
# cd /lib/systemd/system
# sudo nano nowpix.service
[Unit] Description=Run NowPix images using Feh on boot [Service] Type=simple ExecStart=/usr/bin/feh -FD10 /home/debian/NowPix Environment=DISPLAY=:0 SyslogIdentifier=fehslideshow Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target
# systemctl start nowpix.service
# systemctl enable nowpix.service
3.144.189.177