Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script to post your location automatically on the allsky map #1073

Merged
merged 15 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion config_repo/settings_RPiHQ.json.repo
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@
"autofocus":"0",
"darkframe":"0",
"debuglevel":"1",
"alwaysshowadvanced":"0"
"alwaysshowadvanced":"0",
"showonmap":"0",
"location":"",
"owner":"",
"websiteurl":"",
"imageurl":"",
"camera":"",
"lens":"",
"computer":""
}
10 changes: 9 additions & 1 deletion config_repo/settings_ZWO.json.repo
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@
"locale":"en_US.UTF-8",
"debuglevel":"1",
"newexposure":"0",
"alwaysshowadvanced":"0"
"alwaysshowadvanced":"0",
"showonmap":0,
"location":"",
"owner":"",
"websiteurl":"",
"imageurl":"",
"camera":"",
"lens":"",
"computer":""
}
6 changes: 6 additions & 0 deletions scripts/endOfNight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ if [[ ${AUTO_DELETE} == "true" ]]; then
done
fi

SHOW_ON_MAP=$(jq -r '.showonmap' "$CAMERA_SETTINGS")
if [[ ${SHOW_ON_MAP} == "1" ]]; then
echo -e "${ME}: ===== Posting camera details to allsky map"
"${ALLSKY_SCRIPTS}/postToMap.sh"
fi

exit 0
66 changes: 66 additions & 0 deletions scripts/postToMap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# shellcheck disable=SC2034
ME="$(basename "${BASH_ARGV0}")"

# Allow this script to be executed manually, which requires several variables to be set.
if [ -z "${ALLSKY_HOME}" ] ; then
ALLSKY_HOME=$(realpath "$(dirname "${BASH_ARGV0}")"/..)
export ALLSKY_HOME
fi

# This script uploads various information relative to the camera setup to the allsky map.
# https://www.thomasjacquin.com/allsky-map/
# Information is gathered automatically from the settings file

# Disabling shellcheck to force CI to compile - May need to find a better way to deal with this
# shellcheck disable=SC1090
source "${ALLSKY_HOME}/variables.sh"
# shellcheck disable=SC1090
source "${ALLSKY_CONFIG}/config.sh"

LOCATION=$(jq -r '.location' "$CAMERA_SETTINGS")
OWNER=$(jq -r '.owner' "$CAMERA_SETTINGS")
LATITUDE=$(jq -r '.latitude' "$CAMERA_SETTINGS")
LONGITUDE=$(jq -r '.longitude' "$CAMERA_SETTINGS")
WEBSITE_URL=$(jq -r '.websiteurl' "$CAMERA_SETTINGS")
IMAGE_URL=$(jq -r '.imageurl' "$CAMERA_SETTINGS")
CAMERA=$(jq -r '.camera' "$CAMERA_SETTINGS")
LENS=$(jq -r '.lens' "$CAMERA_SETTINGS")
COMPUTER=$(jq -r '.computer' "$CAMERA_SETTINGS")
MAC_ADDRESS="$(sudo cat /sys/class/net/"$(ip route show default | awk '/default/ {print $5}')"/address)"

generate_post_data()
{
cat <<EOF
{
"location": "$LOCATION",
"owner": "$OWNER",
"latitude": "$LATITUDE",
"longitude": "$LONGITUDE",
"website_url": "$WEBSITE_URL",
"image_url": "$IMAGE_URL",
"camera": "$CAMERA",
"lens": "$LENS",
"computer": "$COMPUTER",
"mac_address": "$MAC_ADDRESS"
}
EOF
}

# Extract last character of mac address and find its parity
digit="${MAC_ADDRESS: -1}"
decimal=$(( 16#$digit ))
parity="$(( decimal % 2 ))"

# Only upload every other day to save on server bandwidth
if (( $(date +%d) % 2 == parity ))
then
echo "Week day matches Mac Address ending - upload"
curl -i \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--data "$(generate_post_data)" "https://www.thomasjacquin.com/allsky-map/postToMap.php"
else
echo "Week day doesn't match Mac Address ending - don't upload"
fi
Loading