Advertisement
Guest User

La Crosse WS2300 2307

a guest
May 2nd, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #This script reads weather data via fetch program which is part of Open2300 suite written by Kenneth Lavrsen (http://www.
  4. #lavrsen.dk/foswiki/bin/view/Open2300/WebHome).
  5. #It outputs the right data needed to feed Xastir for APRS weather reports. The scripts utilizes Ncat utility as server to
  6. #serve the fetched output to Xastir.
  7. #Fetched Data is pushed to Ncat server and then to Xastir. (Fetched data -> Ncat server -> Xastir)
  8. #Ncat is part of Nmap, get it by installing Nmap.
  9. #This script should work for LaCrosse weather stations, WS23xx series. Testing was done with WS2307.
  10. #Written by S55MA and S56IUL, May 2016
  11.  
  12. #DEFINE VARIABLES
  13. host="127.0.0.1"
  14. port="1234"
  15.  
  16. #Start the Ncat server
  17. chkncat=$(netstat -ant | grep $host:$port | grep -c LISTEN)
  18. if [ "$chkncat" -ge "1" ]
  19.     then
  20.         echo "ncat already running, nothing to do"
  21.     else
  22.         nohup ncat -k -l --broker $host $port &>/dev/null &
  23. fi
  24.  
  25. #Start while loop
  26. while true; do
  27.  
  28. echo "start `date`"
  29.  
  30. datetime=$(date '+%Y%m%d%H%M%S')
  31. ws2300config="/etc/open2300/open2300.conf"
  32. /usr/local/bin/fetch2300 $ws2300config > /tmp/wxdata-"$datetime".tmp
  33. fetch_path="/tmp/wxdata-$datetime.tmp"
  34. chkfile=$(ls -la $fetch_path | awk -F ' ' '{ print $5 }')
  35.  
  36. if [ "$chkfile" -le "43" ]
  37.     then
  38.     echo "No Data"
  39.     sleep 30
  40.     else
  41.     tempF=$(cat "$fetch_path" | grep To | grep -v 'min\|max\|DRtot\|TRtot' | awk '{print $2}')
  42.     temp1=$(echo "$tempF" | awk '{ printf ("%d\n",$1 + 0.5)}')
  43.     if [ "$temp1" -ge "99" ] || [ "$temp1" -le "-99" ]
  44.         then
  45.             temp="$temp1"
  46.         else
  47.             if [ "$temp1" -le "-1" ]
  48.                 then
  49.                     if [ "$temp1" -ge "-9" ]
  50.                         then
  51.                             temp2=$(echo "$temp1" | sed 's/[-]//g')
  52.                             temp=$(echo -0"$temp2")
  53.                         else
  54.                             temp2=$(echo "$temp1" | sed 's/[-]//g')
  55.                             temp=$(echo -"$temp1")
  56.                     fi
  57.                 else
  58.                     temp=$(echo 0"$temp1")
  59.             fi
  60.     fi
  61.    
  62.     windspeed2=$(cat "$fetch_path" | grep -m1 WS | grep -v 'min\|max\|DRtot\|TRtot'| awk '{print $2/1.609344}' | awk '{ printf ("%d\n",$1 + 0.5)}')
  63. if [ "$windspeed2" -le "9" ]
  64.         then
  65.             windspeed=$(echo 00"$windspeed2")
  66.         else
  67.             if [ "$windspeed2" -le "99" ]
  68.                 then
  69.                     windspeed=$(echo 0"$windspeed2")
  70.                 else
  71.                     windspeed=$(echo "$windspeed2")
  72.             fi
  73.     fi
  74.  
  75.     winddirection2=$(cat "$fetch_path" | grep DIR0 | awk '{print $2}' | sed 's/\..*$//')
  76.     if [ "$winddirection2" -le "9" ]
  77.         then
  78.             winddirection=$(echo 00"$winddirection2")
  79.         else
  80.             if [ "$winddirection2" -le "99" ]
  81.                 then
  82.                     winddirection=$(echo 0"$winddirection2")
  83.                 else
  84.                     winddirection=$(echo "$winddirection2")
  85.             fi
  86.     fi
  87.  
  88.     rain1h=$(cat "$fetch_path" | grep R1h | grep -v 'min\|max' | awk '{print $2}' | sed 's/[.]//g')
  89.     rain24h=$(cat "$fetch_path" | grep R24h | grep -v 'min\|max' | awk '{print $2}' | sed 's/[.]//g')
  90.  
  91.     airpressureR=$(cat "$fetch_path" | grep RP | grep -v 'min\|max' | awk '{print $2}')
  92.     airpressure2=$(echo "scale=1;$airpressureR / 1" | bc | sed 's/[.]//g')
  93.     if [ "$airpressure2" -le "9999" ]
  94.         then
  95.             airpressure=$(echo 0"$airpressure2")
  96.         else
  97.             airpressure=$(echo "$airpressure2")
  98.     fi
  99.  
  100.     relhumidity=$(cat "$fetch_path" | grep RHo | grep -v 'min\|max' | awk '{print $2}' | sed 's/\..*$//')
  101.  
  102.     #Combine variables to forge Xastir string
  103.     xastir="c${winddirection}s${windspeed}t${temp}r${rain1h}p${rain24h}b${airpressure}h${relhumidity}xDvs"
  104.     printf "%s\n" "$xastir" | ncat --send-only $host $port
  105.     echo "$xastir"
  106.         sleep 3
  107.  
  108.     rm -f /tmp/wxdata-*.tmp
  109.  
  110.     echo "stop `date`"
  111.     echo "-----------------------------------"
  112. fi
  113.  
  114. done
  115.  
  116. #EOS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement