Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mwvent/862091b4e6427f485dd6480ad8169fad to your computer and use it in GitHub Desktop.
Save mwvent/862091b4e6427f485dd6480ad8169fad to your computer and use it in GitHub Desktop.
Data collection scripts for ******'s homework - record images and sensor data from android phone running "ip webcam" and create timelapse and data spreadsheet where phone IP address is 192.168.1.25
set datafile separator ','
set key autotitle columnhead # use the first line as title
set xlabel 'Time Elapsed(Mins)' # label for the X axis
set format y "%0.0f"
set multiplot layout 3,1 rowsfirst
plot "data2.csv" using 1:3 with lines
plot "data2.csv" using 1:4 with lines
plot "data2.csv" using 1:5 with lines
unset multiplot
find ./anoframes/ -type f | grep jpg | sort | xargs cat | ffmpeg -f mjpeg -i - -c:v h264_nvenc -filter:v "setpts=0.15625*PTS" -r 160 -y jelly-timelapse-30s-160fps.mp4
#!/bin/bash
function annotateJPEG() {
INPUTJPG="$1"
START_TIME="2021-10-10 17:51:24"
JPGBASEFN="$(basename ${INPUTJPG} | cut -d "." -f 1)"
START_TIME_UNIXTIME="$(date -d "${START_TIME}" +%s)"
JPG_Y="$(echo $JPGBASEFN | cut -d "-" -f 1)"
JPG_M="$(echo $JPGBASEFN | cut -d "-" -f 2)"
JPG_D="$(echo $JPGBASEFN | cut -d "-" -f 3)"
JPG_H="$(echo $JPGBASEFN | cut -d "-" -f 4 | cut -d ":" -f 1)"
JPG_m="$(echo $JPGBASEFN | cut -d "-" -f 4 | cut -d ":" -f 2)"
JPG_S="$(echo $JPGBASEFN | cut -d "-" -f 4 | cut -d ":" -f 3)"
DATA_UNIXTIME="$(date -d "${JPG_Y}-${JPG_M}-${JPG_D} ${JPG_H}:${JPG_m}:${JPG_S}" +%s)"
SECONDS_ELAPSED=$((DATA_UNIXTIME - START_TIME_UNIXTIME))
TIME_ELAPSED="$(date -d "@${SECONDS_ELAPSED}" -u +%Hh%Mm%Ss)"
SENSORSTXT=""
anofn="./anoframes/${JPG_Y}-${JPG_M}-${JPG_D}-${JPG_H}-${JPG_m}-${JPG_S}.jpg"
if [ ! -f "$anofn" ]; then
DATA_SEARCH_STRING="${JPG_Y}-${JPG_M}-${JPG_D},${JPG_H}:${JPG_m}"
echo $DATA_SEARCH_STRING
DATA="$(cat data.csv | grep ${DATA_SEARCH_STRING} | head -n 1)"
DATA_DATE="$(echo $DATA | cut -d "," -f 1)"
DATA_TIME="$(echo $DATA | cut -d "," -f 2)"
DATA_TEMP="$(echo $DATA | cut -d "," -f 3)"
DATA_TEMP="$(printf "%.2f" ${DATA_TEMP})"
DATA_MBAR="$(echo $DATA | cut -d "," -f 4)"
DATA_HUMIDITY="$(echo $DATA | cut -d "," -f 5)"
DATA_HUMIDITY="$(printf "%.2f" ${DATA_HUMIDITY})"
DATA_BAT="$(echo $DATA | cut -d "," -f 6)"
SENSORSTXT="Ambient Temp: ${DATA_TEMP}°C Pressure: ${DATA_MBAR}mbar Humid: ${DATA_HUMIDITY}%"
if [ "$DATA" == "" ]; then SENSORSTXT=""; fi
convert \
-fill white -stroke black -draw "rectangle 0,650 1920,1080" \
-fill black -stroke grey \
-pointsize 38 -draw "text 850,690 \"ELAPSED: ${TIME_ELAPSED}\"" \
-pointsize 20 -draw "text 1000,715 \"TIME: ${JPG_Y}-${JPG_M}-${JPG_D} ${JPG_H}:${JPG_m}:${JPG_S}\"" \
-pointsize 25 -draw "text 10,695 \"${SENSORSTXT}\" " \
"$INPUTJPG" /dev/shm/annotjpg.jpg && cp "/dev/shm/annotjpg.jpg" "$anofn"
else
cp "$anofn" "/dev/shm/annotjpg.jpg"
fi
}
function makeCSV() {
echo "Date,Time,Temp C,Pressure mbar,Humidty %,BAT"
find ./data | grep json | sort | while read F; do
DT="$(basename $F | cut -d "-" -f 1-3)"
TIME="$(basename $F | cut -d "-" -f 4 | cut -d "." -f 1)"
VALUES="$(cat $F| jq ".ambient_temp.data[0][1][0], .pressure.data[0][1][0], .humidity.data[0][1][0], .battery_level.data[0][1][0]")"
TEMP="$(echo $VALUES | cut -d " " -f1)"
PRESSURE="$(echo $VALUES | cut -d " " -f2)"
HUMIDITY="$(echo $VALUES | cut -d " " -f3)"
BAT="$(echo $VALUES | cut -d " " -f4)"
echo $DT,$TIME,$TEMP,$PRESSURE,$HUMIDITY,$BAT
done
}
echo "Creating data.csv"
makeCSV > data.csv
mkdir -p anoframes
find ./images/ -type f | grep jpg | sort | while read FN; do
annotateJPEG "$FN"
done
find ./anoframes/ -type f | grep jpg | sort | xargs cat | ffmpeg -f mjpeg -i - -c:v h264_nvenc -y jelly-timelapse.mp4
#!/bin/bash
# Name this file cleanspreadsheet.sh
# run as ./cleanspreadsheet.sh > data2.csv
echo "Mins Elapsed,DateTime,Temp C,Pressure mbar,Humidty %,BAT"
START_TIME="2021-10-10 17:51:24"
START_TIME_UNIXTIME="$(date -d "${START_TIME}" +%s)"
tail -n +2 data.csv | awk -F',' '{printf "%s %s,%.2f,%.2f,%.2f,%s\n",$1,$2,$3,$4,$5,$6}' | while read LN; do
LINE_TIME="$(echo $LN | cut -d ',' -f 1)"
LINE_TIME_UNIXTIME="$(date -d "${LINE_TIME}" +%s)"
ELAPSED_SECONDS=$((LINE_TIME_UNIXTIME - START_TIME_UNIXTIME))
ELAPSED_MINS="$(echo "scale=2; $ELAPSED_SECONDS / 60" | bc)"
echo ${ELAPSED_MINS},${LN}
done
#!/bin/bash
mkdir -p data
cd ./data
while :; do
SEC=$(date +%s)
NXT=$((SEC+15))
curl 'http://192.168.1.25:8080/sensors.json?from=1633885515802&sense=proximity,rot_vector,ambient_temp,battery_temp,light,battery_level,gyro,accel,pressure,battery_voltage,gravity,humidity,lin_accel,mag' \
-H 'Connection: keep-alive' \
-H 'Accept: */*' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Referer: http://192.168.1.25:8080/sensors.html' \
-H 'Accept-Language: en-US,en;q=0.9' \
--compressed \
--insecure > "$(date +%Y-%m-%d-%H:%M:%S).json"
until [ "$NXT" -lt $(date +%s) ]; do sleep 1; done
done
#!/bin/bash
mkdir -p images
cd images
while :; do
SEC=$(date +%s)
NXT=$((SEC+15))
wget --timeout=14 "http://192.168.1.25:8080/photo.jpg" -O "$(date +%Y-%m-%d-%H:%M:%S).jpg"
until [ "$NXT" -lt $(date +%s) ]; do sleep 1; done
done
gnuplot -e "set terminal png size 400,800; set output 'data.png'" -p data2.gnuplot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment