Skip to content

Instantly share code, notes, and snippets.

@kareiva
Created February 4, 2024 19:27
Show Gist options
  • Save kareiva/2f13a01a3d0eda2b6e15dd7d53d6d771 to your computer and use it in GitHub Desktop.
Save kareiva/2f13a01a3d0eda2b6e15dd7d53d6d771 to your computer and use it in GitHub Desktop.
Simple Moon tracker for hamlib rotator control (rotctld)
import re
import time
import ephem
import telnetlib
# put your rotctld address and port here
rot_addr = "192.168.1.124"
rot_port = "4533"
home_lat = "54.687157"
home_lon = "25.279652"
moon = ephem.Moon()
rotctld = telnetlib.Telnet(rot_addr, port=rot_port, timeout=20)
while True:
homeloc = ephem.Observer()
# your home coordinates
homeloc.lat = home_lat
homeloc.lon = home_lon
moon.compute(homeloc)
altitude = int(re.split(":", str(moon.alt))[0])
azimuth = int(re.split(":", str(moon.az))[0])
if altitude > 0:
print("Rotating to {}, elevation {}".format(azimuth, altitude))
rotctld.write(
b"P "
+ bytes(str(azimuth), "utf-8")
+ b" "
+ bytes(str(altitude), "utf-8")
+ b"\n"
)
time.sleep(1)
rotctld.write(b"p\n")
ret = rotctld.read_eager()
time.sleep(1)
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment