Skip to content

Instantly share code, notes, and snippets.

@DaneGardner
Last active November 26, 2018 00:34
Show Gist options
  • Save DaneGardner/41c0b02fcdea013519c87cb96b916257 to your computer and use it in GitHub Desktop.
Save DaneGardner/41c0b02fcdea013519c87cb96b916257 to your computer and use it in GitHub Desktop.
Setting Celestron hand controller location via IP geolocation
#!/bin/bash
readonly serial=/dev/ttyS0
latlon="$(curl -s ipinfo.io | jq -r '.loc')"
lat=$(cut -d, -f1 <<< ${latlon})
lon=$(cut -d, -f2 <<< ${latlon})
location=$(./latlon2celestron.py "${lat}" "${lon}")
if [ ${?} != 0 ]; then exit; fi
stty -F ${serial} 9600
HEX="\\\\x%02X"
unset FORMAT
for i in {1..8}; do
FORMAT="${FORMAT}${HEX}"
done
hex_text="$(printf "W${FORMAT}" ${location})"
echo -ne "${hex_text}" > ${serial}
#!/usr/bin/env python
import sys
lat = float(sys.argv[1])
lon = float(sys.argv[2])
def dms(deg):
m = (abs(deg) - int(abs(deg))) * 60.0
s = (abs(m) - int(abs(m))) * 60.0
return (int(deg), int(m), int(s))
def celestron(deg):
c = dms(deg)
return "{0:d} {1:d} {2:d} {3:d}".format(abs(c[0]), c[1], c[2], 0 if(c[0] >= 0) else 1)
print "{0} {1}".format(celestron(lat), celestron(lon))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment