Created
May 9, 2021 08:44
-
-
Save kyontan/66be1478a7c3ed524b2721d1ed360e2f to your computer and use it in GitHub Desktop.
GoPro interval photo taker (Hero5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tmpfile=$(mktemp) | |
while true; do | |
curl --silent http://10.5.5.9/gp/gpMediaList > $tmpfile | |
grep "busy" $tmpfile > /dev/null | |
if [ $? -eq 1 ]; then break; fi | |
sleep 1 | |
done | |
# Format: | |
# {"id":"1155632757213017663","media":[..., {"d":"100GOPRO","fs":[..., {"n":"GOPR0001.JPG","mod":"1620260578","s":"3267875"}]}]} | |
d=$(cat $tmpfile | jq -r ".media[-1].d") | |
n=$(cat $tmpfile | jq -r ".media[-1].fs[-1].n") | |
echo http://10.5.5.9/videos/DCIM/$d/$n | |
rm $tmpfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MACADDR=SET_MAC_ADDRESS_HERE | |
MAX_RETRY=20 | |
echo "Turning on GoPro..." | |
retry=0 | |
while true; do | |
sudo gatttool -t random -b $MACADDR --char-write-req -a 0x2f -n 03170101 | |
if [ $? -eq 0 ]; then echo " OK."; break; fi | |
retry=$((retry + 1)) | |
if [ $retry -ge $MAX_RETRY ]; then | |
echo " retrying count exceeded max retry count (${MAX_RETRY})" | |
exit 1 | |
fi | |
echo " retrying (${retry} tried / ${MAX_RETRY})" | |
done | |
echo "Waiting Wi-Fi connection... (iw link)" | |
retry=0 | |
while true; do | |
iw wlan0 link | grep "Not connected" > /dev/null | |
if [ $? -eq 1 ]; then echo " OK."; break; fi | |
retry=$((retry + 1)) | |
if [ $retry -ge $MAX_RETRY ]; then | |
echo " retrying count exceeded max retry count (${MAX_RETRY})" | |
exit 1 | |
fi | |
echo " retrying (${retry} tried / ${MAX_RETRY})" | |
sleep 2 | |
done | |
echo "Waiting Wi-Fi connection... (ip addr)" | |
retry=0 | |
while true; do | |
ip addr show dev wlan0 | grep "NO-CARRIER" | |
if [ $? -eq 1 ]; then echo " OK."; break; fi | |
retry=$((retry + 1)) | |
if [ $retry -ge $MAX_RETRY ]; then | |
echo " retrying count exceeded max retry count (${MAX_RETRY})" | |
exit 1 | |
fi | |
echo " retrying (${retry} tried / ${MAX_RETRY})" | |
sleep 2 | |
done | |
echo "Waiting Wi-Fi connection... (REST API)" | |
retry=0 | |
while true; do | |
curl --silent http://10.5.5.9/gp/gpControl/status > /dev/null | |
if [ $? -eq 0 ]; then echo " OK."; break; fi | |
retry=$((retry + 1)) | |
if [ $retry -ge $MAX_RETRY ]; then | |
echo " retrying count exceeded max retry count (${MAX_RETRY})" | |
exit 1 | |
fi | |
echo " retrying (${retry} tried / ${MAX_RETRY})" | |
sleep 2 | |
done | |
echo "Connected over Wi-Fi." | |
echo | |
echo "Set photo mode" | |
# mode 1 is only for Hero 5 | |
# sub_mode: 1 (photo), 2 (night photo) | |
curl --silent "http://10.5.5.9/gp/gpControl/command/sub_mode?mode=1&sub_mode=1" > /dev/null | |
[ $? -ne 0 ] && echo " Failed" && exit 1 | |
echo " OK." | |
echo "Setting resolution" | |
RESOLUTION_12MP_WIDE=http://10.5.5.9/gp/gpControl/setting/17/0 | |
RESOLUTION_12MP_LINEAR=http://10.5.5.9/gp/gpControl/setting/17/10 | |
RESOLUTION_12MP_MEDIUM=http://10.5.5.9/gp/gpControl/setting/17/8 | |
RESOLUTION_12MP_NARROW=http://10.5.5.9/gp/gpControl/setting/17/9 | |
curl --silent $RESOLUTION_12MP_LINEAR > /dev/null | |
[ $? -ne 0 ] && echo " Failed" && exit 1 | |
echo " OK." | |
echo "Waiting to get stable (3sec) ..." | |
sleep 3 | |
echo "Trigger shutter..." | |
curl --silent "http://10.5.5.9/gp/gpControl/command/shutter?p=1" > /dev/null | |
[ $? -ne 0 ] && echo " Failed" && exit 1 | |
echo " OK." | |
sleep 1 | |
url=$(./gp_latest_photo_url) | |
echo "Taken photo url: ${url}, downloading..." | |
if [[ $DEBUG = "" ]]; then | |
wget -P /tmp $url | |
else | |
echo " Enabled debug mode, set destination to /dev/null" | |
wget -O /dev/null $url | |
fi | |
echo " OK." | |
echo "Fetch status" | |
curl --silent http://10.5.5.9/gp/gpControl/status | jq -c '.status | {"BattPercent": ."70", "PhotosTaken":."38"}' | tee -a /tmp/gopro_bench | |
[ $? -ne 0 ] && echo " Failed" && exit 1 | |
echo " OK." | |
echo "Turning off" | |
curl --silent "http://10.5.5.9/gp/gpControl/command/system/sleep" | |
[ $? -ne 0 ] && echo " Failed" && exit 1 | |
echo " OK." | |
# sudo gatttool -t random -b $MACADDR --char-write-req -a 0x2f -n 0105 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment