Last active
February 19, 2021 22:10
-
-
Save wgaylord/3b149fc3cfe723ec971184e73b957272 to your computer and use it in GitHub Desktop.
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
import aprslib | |
import location | |
import time | |
from math import sin, cos, sqrt, atan2, radians | |
last = None | |
count = 0 | |
location.start_updates() | |
aprs = aprslib.IS('CALLSIGN',aprslib.passcode('CALLSIGN')) | |
aprs.connect() | |
packet = aprslib.packets.PositionReport() | |
packet.fromcall='CALLSIGN' #Insert your hamradio call sign | |
packet.tocall='WIDE1' | |
packet.comment=' ' | |
packet.symbol='>' | |
def dist(locA,locB): | |
lat1 = radians(locA['latitude']) | |
lon1 = radians(locA['longitude']) | |
lat2 = radians(locB['latitude']) | |
lon2 = radians(locB['longitude']) | |
dlon = lon2 - lon1 | |
dlat = lat2 - lat1 | |
a = sin(dlat / 2.0)**2.0 + cos(lat1) * cos(lat2) * sin(dlon / 2.0)**2.0 | |
c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a)) | |
return 6373.0 * c * 0.621371 | |
def sendLoc(aprs,loc): | |
packet.timestamp=loc['timestamp'] | |
packet.latitude=loc['latitude'] | |
packet.longitude=loc['longitude'] | |
aprs.sendall(packet) | |
print 'Location Updated!' | |
def course(last,loc): | |
old = last['course'] | |
new = loc['course'] | |
if old <0: | |
return False | |
if new < 0: | |
return False | |
delta = abs(new-old) | |
if delta <= 180: | |
delta = delta | |
else: | |
delta= 360-delta | |
if delta > 60: | |
print 'Course Changed!',new,old,delta | |
return True | |
loc = location.get_location() | |
sendLoc(aprs,loc) | |
last=loc | |
while True: | |
loc = location.get_location() | |
if (dist(last,loc) > 0.25 and count >= 4) or dist(last,loc) > 1 or count >24 or course(last,loc): | |
count = 0 | |
last=loc | |
try: | |
sendLoc(aprs,loc) | |
except: | |
aprs.connect() | |
sendLoc(aprs,loc) | |
else: | |
count +=1 | |
time.sleep(10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment