Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #This script reads weather data via fetch program which is part of Open2300 suite written by Kenneth Lavrsen (http://www.
- #lavrsen.dk/foswiki/bin/view/Open2300/WebHome).
- #It outputs the right data needed to feed Xastir for APRS weather reports. The scripts utilizes Ncat utility as server to
- #serve the fetched output to Xastir.
- #Fetched Data is pushed to Ncat server and then to Xastir. (Fetched data -> Ncat server -> Xastir)
- #Ncat is part of Nmap, get it by installing Nmap.
- #This script should work for LaCrosse weather stations, WS23xx series. Testing was done with WS2307.
- #Written by S55MA and S56IUL, May 2016
- #DEFINE VARIABLES
- host="127.0.0.1"
- port="1234"
- #Start the Ncat server
- chkncat=$(netstat -ant | grep $host:$port | grep -c LISTEN)
- if [ "$chkncat" -ge "1" ]
- then
- echo "ncat already running, nothing to do"
- else
- nohup ncat -k -l --broker $host $port &>/dev/null &
- fi
- #Start while loop
- while true; do
- echo "start `date`"
- datetime=$(date '+%Y%m%d%H%M%S')
- ws2300config="/etc/open2300/open2300.conf"
- /usr/local/bin/fetch2300 $ws2300config > /tmp/wxdata-"$datetime".tmp
- fetch_path="/tmp/wxdata-$datetime.tmp"
- chkfile=$(ls -la $fetch_path | awk -F ' ' '{ print $5 }')
- if [ "$chkfile" -le "43" ]
- then
- echo "No Data"
- sleep 30
- else
- tempF=$(cat "$fetch_path" | grep To | grep -v 'min\|max\|DRtot\|TRtot' | awk '{print $2}')
- temp1=$(echo "$tempF" | awk '{ printf ("%d\n",$1 + 0.5)}')
- if [ "$temp1" -ge "99" ] || [ "$temp1" -le "-99" ]
- then
- temp="$temp1"
- else
- if [ "$temp1" -le "-1" ]
- then
- if [ "$temp1" -ge "-9" ]
- then
- temp2=$(echo "$temp1" | sed 's/[-]//g')
- temp=$(echo -0"$temp2")
- else
- temp2=$(echo "$temp1" | sed 's/[-]//g')
- temp=$(echo -"$temp1")
- fi
- else
- temp=$(echo 0"$temp1")
- fi
- fi
- 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)}')
- if [ "$windspeed2" -le "9" ]
- then
- windspeed=$(echo 00"$windspeed2")
- else
- if [ "$windspeed2" -le "99" ]
- then
- windspeed=$(echo 0"$windspeed2")
- else
- windspeed=$(echo "$windspeed2")
- fi
- fi
- winddirection2=$(cat "$fetch_path" | grep DIR0 | awk '{print $2}' | sed 's/\..*$//')
- if [ "$winddirection2" -le "9" ]
- then
- winddirection=$(echo 00"$winddirection2")
- else
- if [ "$winddirection2" -le "99" ]
- then
- winddirection=$(echo 0"$winddirection2")
- else
- winddirection=$(echo "$winddirection2")
- fi
- fi
- rain1h=$(cat "$fetch_path" | grep R1h | grep -v 'min\|max' | awk '{print $2}' | sed 's/[.]//g')
- rain24h=$(cat "$fetch_path" | grep R24h | grep -v 'min\|max' | awk '{print $2}' | sed 's/[.]//g')
- airpressureR=$(cat "$fetch_path" | grep RP | grep -v 'min\|max' | awk '{print $2}')
- airpressure2=$(echo "scale=1;$airpressureR / 1" | bc | sed 's/[.]//g')
- if [ "$airpressure2" -le "9999" ]
- then
- airpressure=$(echo 0"$airpressure2")
- else
- airpressure=$(echo "$airpressure2")
- fi
- relhumidity=$(cat "$fetch_path" | grep RHo | grep -v 'min\|max' | awk '{print $2}' | sed 's/\..*$//')
- #Combine variables to forge Xastir string
- xastir="c${winddirection}s${windspeed}t${temp}r${rain1h}p${rain24h}b${airpressure}h${relhumidity}xDvs"
- printf "%s\n" "$xastir" | ncat --send-only $host $port
- echo "$xastir"
- sleep 3
- rm -f /tmp/wxdata-*.tmp
- echo "stop `date`"
- echo "-----------------------------------"
- fi
- done
- #EOS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement