Skip to content

Instantly share code, notes, and snippets.

@BETLOG
Last active May 16, 2021 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BETLOG/7f7c0bac55f25ad6c44b0f3c81dd232c to your computer and use it in GitHub Desktop.
Save BETLOG/7f7c0bac55f25ad6c44b0f3c81dd232c to your computer and use it in GitHub Desktop.
/etc/rc.local - RPiCamWebInterface Annotation %a
# Description: use /etc/rc.local to initiate a loop-script which writes to the RPiCamWebInterface Annotation (%a) file.
#
# servicectl services/timers may not run a 1 second timer at anyhting like 1 second intervals
# Whereas a script running a simple loop will. Particualrly if the loops timing accounts for minor variations.
#
# you can activate this either:
# 1) by manually adding the path/filename of the script to /etc/rc.local
# or
# 2) like I do: (as part of another script that loops through all of my pizerocams)
scp -q \
/home/user/documents/scripts/raspberry/home/pi/piinfo.sh \
$targetHost:/home/pi
msg1="activating:" ;msg2="user annotation %a"; f_msg
ssh -q $targetHost bash <<'EOF'
[[ -f /etc/rc.local && -z $(grep -o '/home/pi/piinfo.sh' /etc/rc.local) ]] && sudo sed -Ei 's/exit\ 0/\/home\/pi\/piinfo.sh \# services do not run evenly at actual second precision repeats so just fork a looping script\n\nexit\ 0/' /etc/rc.local
EOF
#!/bin/bash
# for use with RPiWebCamInterface %a
# initiate this script via /etc/rc.local
# or run it as root
# if you run it non-root values print to console but RPCWI will not use it as annotiation (%a)
#
while :; do # services do not run evenly at actual second precision repeats, so just fork a looping script
startTime=$(date +%s.%3N)
degC="$(echo "scale=1;$(cat /sys/class/thermal/thermal_zone0/temp)/1000"|bc|sed -E 's/^\./0\./')C"
annotation="$HOSTNAME ${degC}"
# last="$(cat /dev/shm/mjpeg/user_annotate.txt|sed -E 's/.*(.)/\1/')"
# [[ "<" == "$last" || "C" == "$last" ]] && annotation+=" >" || annotation+=" <"
echo -ne "$annotation"
[[ "$EUID" -eq 0 ]] && echo -ne "$annotation" >/dev/shm/mjpeg/user_annotate.txt
sleep $(echo "scale=3; 1.000 - ( $(date +%s.%3N) - $startTime )"|bc)s
done
@zoldaten
Copy link

hi !
i have errors with sleep var and degC.
So just shorten the 2 - piinfo.sh :

while :; do 
    degC=$(vcgencmd measure_temp)
    annotation="$HOSTNAME ${degC}"
    echo -ne "$annotation"
    [[ "$EUID" -eq 0 ]] && echo -ne "$annotation" >/dev/shm/mjpeg/user_annotate.txt
    sleep 1
done

Can you fix ?

@BETLOG
Copy link
Author

BETLOG commented May 16, 2021

sudo apt install bc

@zoldaten
Copy link

sudo apt install bc

Working, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment