Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Read data from HOBOlink station and send it to APRS network via Xastir. Server ports option has to be enabled on Xastir.
- #Create a temporary RAM disk (we don't want to write on a SD card too often).
- #You need to run this script as sudo (root) or create a temporary ramdisk at boot as root
- #and run this script as a normal user.
- if [ ! -d "/mnt/ramdisk/" ]; then
- mkdir -p /mnt/ramdisk; mount -t tmpfs tmpfs /mnt/ramdisk -o size=10m
- fi
- #Check if file exist
- if [ ! -f "/mnt/ramdisk/sequence_numberjavornik.txt" ]; then
- touch /mnt/ramdisk/sequence_numberjavornik.txt
- fi
- #Read sequence number
- read num < /mnt/ramdisk/sequence_numberjavornik.txt
- num=$((num + 1))
- if (( num == 1000 )); then
- num=0
- fi
- #Error log file
- error=/var/log/wxdata.log
- #Define login info
- user=S55MA-10
- password=passcode
- #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
- #requires 9 char long callsign so you need to add whitespaces after the callsign and telemetry, for example:
- #t2="$usersend>APN002,WIDE2-1::"$usersend" :PARM.Solar Radiation,Battery" #5 whitespaces between "$usersend" and :PARM because
- #S51Y is only 4 char long.
- usersend=S51Y
- #Define xastir server
- server=192.168.0.140
- port=2023
- #Define station location (Veliki Javornik, Postojna)
- lat=4545.48N
- lon=01417.72E_ #_ is a symbol for WX station
- #Download weather data
- file=/mnt/ramdisk/wxdata.txt
- file1=/mnt/ramdisk/wxdata1.txt
- curl -s https://www.hobolink.com/p/d0a7b4f0dbc44b973b0a5cce75a0521d | grep nobr | awk -F\> '{print $6}' | sed 's/<\/nobr//g' > "$file"
- 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"
- if [ -s "$file" ] #If downloaded file is not empty, continue, else quit
- then
- #Date in UTC
- zuludate="$(date -u +%d%H%M)"
- #APRS needs temperature in F, data is fetched in degress C so we need to convert it.
- tempC="$(sed -n -e 1p "$file")"
- tempF="$(echo "((9/5) * $tempC) + 32" | bc -l | awk -F. '{print $1}')"
- #Relative humidity
- rh="$(sed -n -e 2p "$file" | awk -F. '{print $1}')"
- #APRS need windspeed in mph, data is fetched in meters per second so we need to convert it.
- windspeedms="$(sed -n -e 4p "$file")"
- windspeedmph="$(echo "(($windspeedms * 3.6) / 1.609344)" | bc -l | awk -F. '{print $1}')"
- gustsms="$(sed -n -e 5p "$file")"
- gustsmph="$(echo "(($gustsms * 3.6) / 1.609344)" | bc -l | awk -F. '{print $1}')"
- rain1h="$(sed -n -e 7p "$file" | awk -F. '{print $1}')"
- winddirection="$(cat "$file1")"
- solarradiation="$(sed -n -e 6p "$file")" #For telemetry only
- batteryvoltage="$(sed -n -e 8p "$file" | tr -d '.' | head -c 3)" #For telemetry only
- #Station comment
- aprscomment="Veliki Javornik 1268m asl"
- #Xastir weather variable with padding zeros for correct APRS format
- printf -v xastirwx "%03d/%03dg%03dt%03dr%03dh%02d%s" "$winddirection" "$windspeedmph" "$gustsmph" "$tempF" "$rain1h" "$rh" "$aprscomment"
- #Xastir user and WIDE path data
- xastirpath="$usersend>APN100,WIDE2-1:=$lat/$lon"
- #Telemetry
- printf -v t1 "%s>APN002,WIDE2-1:T#%03d,%03d,%03d,000,000,000,00000000" "$usersend" "$num" "$solarradiation" "$batteryvoltage"
- t2="$usersend>APN002,WIDE2-1::$usersend :PARM.Solar Radiation,Battery"
- t3="$usersend>APN002,WIDE2-1::$usersend :UNIT.W/m2,Volts"
- #Add coefficient in EQNS field to convert real data.
- t4="$usersend>APN002,WIDE2-1::$usersend :EQNS.0,1,0,0,0.01,0,0,0,0,0,0.0,0,0,0,0"
- t5="$usersend>APN002,WIDE2-1::$usersend :BITS.00000000,Weather station Veliki Javornik Postojna"
- #Send data to Xastir
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$xastirpath$xastirwx"
- #Send telemetry data to Xastir
- #Send PARAMS, UNITS, EQNS and BITS every 2 hours.
- #Check if file exist
- if [ ! -f "/mnt/ramdisk/datejavornik.txt" ]; then
- echo 0 > /mnt/ramdisk/datejavornik.txt
- fi
- #calculate time difference
- read olddate < /mnt/ramdisk/datejavornik.txt
- date="$(date +%s)"
- diff="$(echo "$date - $olddate" | bc)"
- if [ "$diff" -gt 7200 ]; then
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t1"
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t2"
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t3"
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t4"
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t5"
- echo "$date" > /mnt/ramdisk/datejavornik.txt
- else
- /usr/bin/xastir_udp_client $server $port $user $password -to_rf "$t1"
- fi
- #Delete old data
- rm -f /mnt/ramdisk/wxdata.txt /mnt/ramdisk/wxdata1.txt
- #Write sequence number
- echo "$num" > /mnt/ramdisk/sequence_numberjavornik.txt
- else
- echo ["$(date -u)"] Error downloading data >> "$error"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement