Advertisement
Guest User

hobolink APRS

a guest
Jul 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Read data from HOBOlink station and send it to APRS network via Xastir. Server ports option has to be enabled on Xastir.
  4.  
  5. #Create a temporary RAM disk (we don't want to write on a SD card too often).
  6. #You need to run this script as sudo (root) or create a temporary ramdisk at boot as root
  7. #and run this script as a normal user.
  8. if [ ! -d "/mnt/ramdisk/" ]; then
  9. mkdir -p /mnt/ramdisk; mount -t tmpfs tmpfs /mnt/ramdisk -o size=10m
  10. fi
  11.  
  12. #Check if file exist
  13. if [ ! -f "/mnt/ramdisk/sequence_numberjavornik.txt" ]; then
  14. touch /mnt/ramdisk/sequence_numberjavornik.txt
  15. fi
  16.  
  17. #Read sequence number
  18. read num < /mnt/ramdisk/sequence_numberjavornik.txt
  19. num=$((num + 1))
  20. if (( num == 1000 )); then
  21. num=0
  22. fi
  23.  
  24. #Error log file
  25. error=/var/log/wxdata.log
  26.  
  27. #Define login info
  28. user=S55MA-10
  29. password=passcode
  30.  
  31. #Insert the same as user. Insert other user sign if you want to put another station not owned by you on the map. Be aware that telemetry
  32. #requires 9 char long callsign so you need to add whitespaces after the callsign and telemetry, for example:
  33. #t2="$usersend>APN002,WIDE2-1::"$usersend" :PARM.Solar Radiation,Battery" #5 whitespaces between "$usersend" and :PARM because
  34. #S51Y is only 4 char long.
  35. usersend=S51Y
  36.  
  37. #Define xastir server
  38. server=192.168.0.140
  39. port=2023
  40.  
  41. #Define station location (Veliki Javornik, Postojna)
  42. lat=4545.48N
  43. lon=01417.72E_ #_ is a symbol for WX station
  44.  
  45. #Download weather data
  46. file=/mnt/ramdisk/wxdata.txt
  47. file1=/mnt/ramdisk/wxdata1.txt
  48. curl -s https://www.hobolink.com/p/d0a7b4f0dbc44b973b0a5cce75a0521d | grep nobr | awk -F\> '{print $6}' | sed 's/<\/nobr//g' > "$file"
  49. curl -s https://www.hobolink.com/p/d0a7b4f0dbc44b973b0a5cce75a0521d | grep "Wind Direction" -A 1 | grep "latest-conditions-info-reading" | awk -F\> '{print $5}' | awk '{print $2}' | grep -o '[0-9]\+' > "$file1"
  50.  
  51. if [ -s "$file" ] #If downloaded file is not empty, continue, else quit
  52. then
  53.  
  54. #Date in UTC
  55. zuludate="$(date -u +%d%H%M)"
  56.  
  57. #APRS needs temperature in F, data is fetched in degress C so we need to convert it.
  58. tempC="$(sed -n -e 1p "$file")"
  59. tempF="$(echo "((9/5) * $tempC) + 32" | bc -l | awk -F. '{print $1}')"
  60.  
  61. #Relative humidity
  62. rh="$(sed -n -e 2p "$file" | awk -F. '{print $1}')"
  63.  
  64. #APRS need windspeed in mph, data is fetched in meters per second so we need to convert it.
  65. windspeedms="$(sed -n -e 4p "$file")"
  66. windspeedmph="$(echo "(($windspeedms * 3.6) / 1.609344)" | bc -l | awk -F. '{print $1}')"
  67. gustsms="$(sed -n -e 5p "$file")"
  68. gustsmph="$(echo "(($gustsms * 3.6) / 1.609344)" | bc -l | awk -F. '{print $1}')"
  69.  
  70. rain1h="$(sed -n -e 7p "$file" | awk -F. '{print $1}')"
  71. winddirection="$(cat "$file1")"
  72. solarradiation="$(sed -n -e 6p "$file")" #For telemetry only
  73. batteryvoltage="$(sed -n -e 8p "$file" | tr -d '.' | head -c 3)" #For telemetry only
  74.  
  75. #Station comment
  76. aprscomment="Veliki Javornik 1268m asl"
  77.  
  78. #Xastir weather variable with padding zeros for correct APRS format
  79. printf -v xastirwx "%03d/%03dg%03dt%03dr%03dh%02d%s" "$winddirection" "$windspeedmph" "$gustsmph" "$tempF" "$rain1h" "$rh" "$aprscomment"
  80.  
  81. #Xastir user and WIDE path data
  82. xastirpath="$usersend>APN100,WIDE2-1:=$lat/$lon"
  83.  
  84. #Telemetry
  85. printf -v t1 "%s>APN002,WIDE2-1:T#%03d,%03d,%03d,000,000,000,00000000" "$usersend" "$num" "$solarradiation" "$batteryvoltage"
  86. t2="$usersend>APN002,WIDE2-1::$usersend :PARM.Solar Radiation,Battery"
  87. t3="$usersend>APN002,WIDE2-1::$usersend :UNIT.W/m2,Volts"
  88.  
  89. #Add coefficient in EQNS field to convert real data.
  90. t4="$usersend>APN002,WIDE2-1::$usersend :EQNS.0,1,0,0,0.01,0,0,0,0,0,0.0,0,0,0,0"
  91. t5="$usersend>APN002,WIDE2-1::$usersend :BITS.00000000,Weather station Veliki Javornik Postojna"
  92.  
  93. #Send data to Xastir
  94. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$xastirpath$xastirwx"
  95.  
  96. #Send telemetry data to Xastir
  97. #Send PARAMS, UNITS, EQNS and BITS every 2 hours.
  98. #Check if file exist
  99. if [ ! -f "/mnt/ramdisk/datejavornik.txt" ]; then
  100. echo 0 > /mnt/ramdisk/datejavornik.txt
  101. fi
  102.  
  103. #calculate time difference
  104. read olddate < /mnt/ramdisk/datejavornik.txt
  105. date="$(date +%s)"
  106. diff="$(echo "$date - $olddate" | bc)"
  107.  
  108. if [ "$diff" -gt 7200 ]; then
  109. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t1"
  110. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t2"
  111. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t3"
  112. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t4"
  113. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t5"
  114. echo "$date" > /mnt/ramdisk/datejavornik.txt
  115. else
  116. /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t1"
  117. fi
  118.  
  119. #Delete old data
  120. rm -f /mnt/ramdisk/wxdata.txt /mnt/ramdisk/wxdata1.txt
  121.  
  122. #Write sequence number
  123. echo "$num" > /mnt/ramdisk/sequence_numberjavornik.txt
  124.  
  125. else
  126. echo ["$(date -u)"] Error downloading data >> "$error"
  127. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement