-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerpi.sh
More file actions
executable file
·39 lines (30 loc) · 1.18 KB
/
powerpi.sh
File metadata and controls
executable file
·39 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
DATE=$(date +%F)
SUBJECT_DATE=$(date +"%A %d %b %Y")
EMAIL_SUBJECT="Power left - $SUBJECT_DATE"
FILENAME="$DATE.jpg"
DIR="/home/pi/powerpi/"
# Email recipient(s) (Comma separated recipients)
RECIPIENTS="user@gmail.com"
# Check dependencies
command -v /usr/bin/raspistill >/dev/null 2>&1 || { echo >&2 "Requires raspistill but it's not installed. Aborting."; exit 1; }
command -v /usr/bin/mpack >/dev/null 2>&1 || { echo >&2 "Requires mpack but it's not installed. Aborting."; exit 1; }
command -v /usr/sbin/ssmtp >/dev/null 2>&1 || { echo >&2 "Requires ssmtp but it's not installed. Aborting."; exit 1; }
# Take photo of power left
echo "Taking photo... takes 7 seconds"
# Night mode, flip vertically and horizontally
raspistill --exposure night --vflip --hflip --width 650 --height 450 --timeout 7000 --brightness 57 --sharpness 75 --output "${DIR}${FILENAME}"
# Email the captured photo
mpack -s "$EMAIL_SUBJECT" -c image/jpeg ${DIR}${FILENAME} "$RECIPIENTS"
if [ "$?" -eq 0 ]
then
echo "Photo emailed successfully to $RECIPIENTS"
else
echo "Failed to send email to $RECIPIENTS"
fi
# Delete the photo
rm "${DIR}${FILENAME}"
if [ "$?" -eq 0 ]
then
echo "Photo deleted successfully"
fi