Guest User

Untitled

a guest
Sep 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. So last year I wrote my own APRS tracker using Pythonista.
  2.  
  3. APRS stands for Automatic Packet Reporting System
  4.  
  5. Using a python library for it and pythonistas access to location and the internet I was able to write my own software to report into the system using my Call Sign and display my location of aprs.fi
  6.  
  7. The following is my code which I never really tided up at all.
  8.  
  9. ```
  10. import aprslib
  11. import location
  12. import livejson
  13. import time
  14. from math import sin, cos, sqrt, atan2, radians
  15.  
  16. last = None
  17. count = 0
  18.  
  19. location.start_updates()
  20.  
  21. aprs = aprslib.IS('CALLSIGN',aprslib.passcode('CALLSIGN'))
  22. aprs.connect()
  23. packet = aprslib.packets.PositionReport()
  24. packet.fromcall='CALLSIGN' #Insert your hamradio call sign
  25. packet.tocall='WIDE1'
  26. packet.comment=' '
  27. packet.symbol='>'
  28.  
  29. def dist(locA,locB):
  30. lat1 = radians(locA['latitude'])
  31. lon1 = radians(locA['longitude'])
  32. lat2 = radians(locB['latitude'])
  33. lon2 = radians(locB['longitude'])
  34.  
  35. dlon = lon2 - lon1
  36. dlat = lat2 - lat1
  37.  
  38. a = sin(dlat / 2.0)**2.0 + cos(lat1) * cos(lat2) * sin(dlon / 2.0)**2.0
  39. c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a))
  40.  
  41. return 6373.0 * c * 0.621371
  42.  
  43. def sendLoc(aprs,loc):
  44. packet.timestamp=loc['timestamp']
  45. packet.latitude=loc['latitude']
  46. packet.longitude=loc['longitude']
  47. aprs.sendall(packet)
  48.  
  49. print 'Location Updated!'
  50.  
  51.  
  52. def course(last,loc):
  53. old = last['course']
  54. new = loc['course']
  55. if old <0:
  56. return False
  57. if new < 0:
  58. return False
  59. delta = abs(new-old)
  60. if delta <= 180:
  61. delta = delta
  62. else:
  63. delta= 360-delta
  64. if delta > 60:
  65. print 'Course Changed!',new,old,delta
  66. return True
  67.  
  68. loc = location.get_location()
  69. sendLoc(aprs,loc)
  70. last=loc
  71. while True:
  72. loc = location.get_location()
  73. if (dist(last,loc) > 0.25 and count >= 4) or dist(last,loc) > 1 or count >24 or course(last,loc):
  74. count = 0
  75. last=loc
  76. try:
  77. sendLoc(aprs,loc)
  78. except:
  79. aprs.connect()
  80. sendLoc(aprs,loc)
  81. else:
  82. print count
  83. count +=1
  84. time.sleep(10)```
Add Comment
Please, Sign In to add comment