SHARE
TWEET

APRS telemetry to INET v3

a guest Jul 27th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #Define login info
  3. user=yourHAMSIGN
  4. password=passcode
  5.  
  6. #Define object user info
  7. senduser=yourHAMSIGN
  8.  
  9. #Define APRS-IS server
  10. server=poland.aprs2.net
  11. port=14580
  12.  
  13. #Define station location
  14. lat=4146.72N
  15. lon=01213.80E
  16.  
  17. #Define data
  18. comment="QTH"
  19. data="$senduser>APN100,TCPIP*:=${lat}/${lon}-${comment}"
  20.  
  21. #Authentication variable
  22. aprsauth="user $user pass $password"
  23.  
  24. #Read raspberry-pi CPU temperature
  25. tempraw=/opt/vc/bin/vcgencmd measure_temp #Read pi temperature
  26. tempfloat="$(echo "$tempraw" | awk -F= '{print $2}' | awk -F\' '{print $1}')" #Filter result to numbers only
  27.  
  28. #Aprs telemetry protocol accepts 3 whole (int) numbers only so we need
  29. #to convert the result (tempfloat) into 3 whole numbers. So if tempraw=40.3, it will
  30. #convert it to 403. If tempraw=8.5, it will convert it to 85 and we'll add the leading zero
  31. #to create 3 number format 085 later bellow.
  32. temp="$(echo "$tempfloat * 10" | bc | awk -F. '{print $1}')"
  33.  
  34. #Project comment
  35. projectcomment=Rpi temperature
  36.  
  37. #Generate telemetry strings
  38. #Read data and put it into variable
  39. #%s means string
  40. #%03d means prepend up to 3 zeroes, so if the value is 8, you'll get 008, if the value is 80, you'll get 080 etc.
  41. #This needs to be done or APRS will deny the packets as invalid. The other things is, everytime you send the telemetry
  42. #a sequence number has to change, it's defined as T# in a APRS protocol. We will automate this next.
  43.  
  44. #Check if file exist
  45. if [ ! -f "/tmp/sequence_number.txt" ]; then
  46.  touch /tmp/sequence_number.txt
  47. fi
  48.  
  49. #Read sequence number. Everytime the scripts runs, the number will rise by 1 until it comes
  50. #to 1000 and then returns back to 0. Everytime the script will run, a sequence number will change.
  51. read num < /tmp/sequence_number.txt
  52. num=$((num + 1))
  53. if (( num == 1000 )); then
  54.  num=0
  55. fi
  56.  
  57. #Finally, we can start assembling the data.
  58. #$senduser goes to %s, $num goes to first %03d and $temp goes to the last %03d in the string.
  59. printf -v t1 "%s>APN001,TCPIP*:T#%03d,%03d,000,000,000,000,00000000" "$senduser" "$num" "$temp"
  60.  
  61. #Define telemetry parameters
  62. t2="$user>APN001,TCPIP*::$senduser :PARM.CPU Temp"
  63.  
  64. #Define telemetry units
  65. t3="$user>APN001,TCPIP*::$senduser :UNIT.Deg.C"
  66.  
  67. #Add telemetry coefficient so the APRS protocol can convert your raw values into real value.
  68. #We get the value in 3 whole numbers and we need to define coefficient so the APRS protocol
  69. #will know how to display the value. We add 0.1 to the second field, means
  70. #if the value is 452, the temperature will be displayed as 45.2
  71. t4="$user>APN001,TCPIP*::$senduser :EQNS.0,0.1,0,0,0,0,0,0,0,0,0,0,0,0,0"
  72.  
  73. #Send bits and project comment
  74. t5="$user>APN001,TCPIP*::$senduser :BITS.00000000,$projectcomment"
  75.  
  76. #Another tricky part is, $senduser total lenght has to be 9 characters. For example
  77. #If my $senduser=S55MA-10 means it's only 8 characters long and we need to add 1 space to it. S55MA-10 :PARM
  78. #If my $senduser=S55MA means it's only 5 characters long and we need to add 4 spaces to it S55MA    :PARM
  79. #The same goes for UNIT, EQNS and BITS
  80.  
  81. #Send data to the server
  82. #For telemetry to work we need to have an object before, from previous script.
  83. #We'll only send an object and telemetry non value data every hour so we don't spam the network.
  84. #We need to compare dates to see if 1 hour is past.
  85.  
  86. #Check if file exist
  87. if [ ! -f "/tmp/date.txt" ]; then
  88.    echo 0 > /tmp/date.txt
  89. fi
  90.  
  91. #calculate time difference
  92. read olddate < /tmp/date.txt
  93. date="$(date +%s)"
  94. diff="$(echo "$date - $olddate" | bc)"
  95.  
  96. #If 3600 is past, execute the first command, else other
  97. if [ "$diff" -gt 3600 ]; then
  98.    printf "%s\n" "$aprsauth" "$data" | ncat --send-only $server $port #this is your QTH object from the first script
  99.    printf "%s\n" "$aprsauth" "$t1" "$t2" "$t3" "$t4" "$t5" | ncat --send-only $server $port
  100.    echo "$date" > /tmp/date.txt
  101. else
  102.    printf "%s\n" "$aprsauth" "$t1" | ncat --send-only $server $port
  103. fi
  104. #Write the last sequence number.
  105. echo "$num" > /tmp/sequence_number.txt
RAW Paste Data
Top