-
Notifications
You must be signed in to change notification settings - Fork 0
/
ma_autolapse.sh
68 lines (52 loc) · 1.53 KB
/
ma_autolapse.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# this creates a folder of timelapse images
# by pulling a webcam snapshot
# every few seconds while the printhead temperature
# is above TRIGTEMP degrees
mkdir -p /home/pi/autolapses
chmod 777 /home/pi/autolapses
cd /home/pi/autolapses
TRIGTEMP=120
LAPSETIME=4
# NOTE: Octoprint 1.4+ differs from Octoprint 1.3. Make sure you un-comment the right version for your Octoprint
# Octoprint 1.3 syntax
re1="\"name\": \"(.*)\.gcode\""
re2="\"actual\": ([0-9]+)"
re3="\"tool0\""
# Octoprint 1.4 syntax
re1="\"name\":\"(.*)\.gcode\",\"origin"
re2="\"actual\":([0-9]+)"
re3="\"tool0\""
while :
do
jobstatus=$( curl --silent 'http://localhost/api/job?apikey=YOUR-API-KEY' )
thedirname="0"
while read -r oneLine; do
if [[ $oneLine =~ $re1 ]]; then
thedirname=${BASH_REMATCH[1]}
fi
done <<< "$jobstatus"
toolstatus=$( curl --silent 'http://localhost/api/printer/tool?apikey=YOUR-API-KEY' )
precond="0"
thefname="0"
while read -r oneLine; do
if [[ $oneLine =~ $re2 ]]; then
# echo "Tool:"${BASH_REMATCH[1]}
if [[ ${BASH_REMATCH[1]} -gt $TRIGTEMP ]]; then
thefname=$( date "+%Y-%m-%d_%H%M%S.jpg" )
fi
fi
done <<< "$toolstatus"
if [[ "$thefname" != "0" ]]; then
mkdir -p /home/pi/autolapses/"$thedirname"
curl --silent "http://localhost/webcam/?action=snapshot" -o "/home/pi/autolapses/$thedirname/$thefname"
# echo "Captured $thefname"
curlres=$?
if test "$curlres" != "0"; then
/home/pi/recam.sh
fi
chown pi /home/pi/autolapses/"$thedirname"
chown pi /home/pi/autolapses/"$thedirname"/"$thefname"
fi
sleep $LAPSETIME
done