This week:

  • project check-ins
  • Glue code and Scripting!

Script 1

Methodology:

  1. Trigger (Bash) script every time we take photo
  2. Create filename based on date and time
  3. Take a photo and save under that filename with .jpg suffix
  4. Pause
  5. Print to receipt
#!/bin/bash

FILENAME=$(echo $(date -I"seconds").jpg)
echo $FILENAME

libcamera-still -o $FILENAME

sleep 5

#code for receipt printer goes here

Programmatically adding to website

A “hack” to write to server where we can’t deploy node or backend.

#!/bin/sh

name=$(date '+%Y-%m-%d-%H-%M-%S')
libcamera-still -o $name.jpg

echo "<img src='$name.jpg'>">>index.html
  • Will save photos by date-time
  • Appends html code for the image to our index page, taking advantage that the ‘broken’ html code will still load fine.
  • This is a hack! It can be refined and refactored.

Python script

A starter code recipe

#!/usr/bin/python

from picamera2 import Picamera2

picam2 = Picamera2()

# take a photo
picam2.start_and_capture_file("test.jpg")

Python script with date-time filenaming

#!/usr/bin/python

import time
from picamera2 import Picamera2

picam2 = Picamera2()

#create name with YYYY-MM-DD-HH-MM-SS.jpg format
time_date_name = time.strftime("%Y-%m-%d-%H-%M-%S")+".jpg"

#take photo
picam2.start_and_capture_file(time_date_name)

#print("photo capture: " + time_date_name)

Example output

test photo of professor gesticulating wildly
A successful photo