Backing up images with the Raspberry Pi
System Integration
In order for this to work automatically, there must be a clean connection between the HAT server and the system. Thanks to systemd, this can be done with just a few lines. Listing 9 shows the service definition that you can create in the /etc/systemd/system/hat-server.service file. Line 9 starts the server program with ExecStart. The following line triggers the Boot-Start event. As a result, the red LED flashes during start up.
Listing 9
hat-server.service
01 [Unit] 02 Description=Start HAT-server 03 DefaultDependencies=no 04 After=sysinit.target local-fs.target 05 Before=basic.target 06 07 [Service] 08 Type=simple 09 ExecStart=/usr/local/sbin/hat-server.py 10 ExecStartPost=/usr/local/sbin/hatctl.py BS 11 12 [Install] 13 WantedBy=basic.target
A second service switches off the light at the end of the boot process. The accompanying service definition is found in /etc/systemd/system/endofboot.service (Listing 10). The service triggers the Boot End event on line 8 in ExecStart. Since the services system stops in reverse order to the start, we use also use the service for the Stop-Start event. The ExecStop
command on line 9 does precisely this.
Listing 10
endofboot.service
01 [Unit] 02 Description=Change status of HAT-LEDs 03 After=multi-user.target 04 05 [Service] 06 Type=oneshot 07 RemainAfterExit=true 08 ExecStart=/usr/local/sbin/hatctl.py BE 09 ExecStop=/usr/local/sbin/hatctl.py HS 10 11 [Install] 12 WantedBy=multi-user.target
Both services require one time activation with the commands from Listing 11. After restarting, the system automatically loads the services. The LEDs should light up as planned. Alternatively the user can switch the LEDs manually as desired from the command line with the script hatctl.py. The function uses the copy script from listing 5, especially lines 5 and 9. These trigger the events Action-Start und Action-End. They also cause the yellow light to blink during the copy process.
Listing 11
Enabling hat-server.service, endofboot.service
$ sudo systemctl enable hat-server.service $ sudo systemctl enable endofboot.service
And with that, your image tank has acquired its basic functions. As previously mentioned, the process works a little more easily with the Display-O-Tron. This particular extension is also made by Pimoroni and, like Pibrella, has a dedicated Python library for conveniently controlling the attachment. This Display-O-Tron offers many more functions.
Conclusion
Your image tank is now ready to go. Three LEDs and a button are all that is needed to interact with the device. Even so, we have not optimized everything that we could. The copy script only copies modified data, i.e. new images from the SD card to the hard drive. If you use multiple cameras which co-incidentally assign the same name to images, these will overwrite previously saved ones. The same problem can arise when image numbering for your own camera is reset.
A wireless connection to the Raspberry Pi would also be helpful, as images could be saved from smartphones and tablets. A nice web interface would also let you do things like view your vacation pictures. Extensions like these do not pose any real challenges for the Raspberry Pi. The second part of the article will appear in the next issue and lay out the necessary steps.
Infos
- Berry-Clip Component: http://www.raspberrypi-spy.co.uk/berryclip-6-led-add-on-board/
- Fish-Dish Component: https://www.modmypi.com/raspberry-pi/breakout-boards/pi-supply/fish-dish-gpio-led-buzzer-board
- Pibrella HAT: http://pibrella.com/
- Display-O-Tron: https://shop.pimoroni.com/products/display-o-tron-hat
- The Display-O-Tron three-line display screen: Bernhard Balok, "Less is More", RPG 20/2016: http://www.raspberry-pi-geek.com/Archive/2016/20/The-Display-O-Tron-three-line-display-screen/
- Author project page: https://github.com/bablokb/pi-imgtank
- Python Library for Pibrella: https://github.com/pimoroni/pibrella
- Automate the Installation of Raspbian: Bernhard Bablok, "AutoPi", RPG 21/2017: http://www.raspberry-pi-geek.com/Archive/2017/21/Using-a-script-to-automate-a-Raspbian-installation/(language)/eng-US
« Previous 1 2 3 Next »
Buy this article as PDF
Pages: 6
(incl. VAT)