Aprs Weather Beacon

Today I’ve been messing around with an APRS weather beacon. Now Direwolf and Linbpq and Jnos can send an aprs weather beacon. It turns out that this is quite precise, with the format of the beacon.

#!/bin/bash
# The weather beacon have to look like this....
# @220424z5057.81N/00729.37E_094/002g005t043r000p006P006h89b09783
# !5133.52N/00348.15E_073/013g...t048h85b10040wWXD
#
# Jun 01 2003 08:07
# 272/000g006t069r010p030P020h61b10150
# ***********************************************************
# 272 - wind direction - 272 degrees
# 010 - wind speed - 10 mph
# g015 - wind gust - 15 mph
# t069 - temperature - 69 degrees F
# r010 - rain in last hour in hundredths of an inch - 0.1 inches
# p030 - rain in last 24 hours in hundredths of an inch - 0.3 inches
# P020 - rain since midnight in hundredths of an inch - 0.2 inches
# h61 - humidity 61% (00 = 100%)
# b10153 - barometric pressure in tenths of a MILLIBAR - 1015.3 MILLIBARS

My weather station uploads its data to wunderground.com. Now wunderground has the option to read this again with an api key.

https://api.weather.com/v2/pws/observations/current?stationId=IKORTG9&format=json&units=m&apiKey=yourApiKey

You can read here how and what.

After a lot of messing around with a bash script, I am able to create the correct format.

TEMP=-4.9°C Temperature degrees Celsius
WPK=29.4km/h Wind speed in Kilometers per hour
WGK=39km/h Wind guts in Kilometers per hour
GRD=58° Wind direction in degrees
RAIN=0mm Rain in the last hour in mm
RAIN24=0.42065mm Rain in the last 24 hour in mm
RAIN12=0.214mm Rain in the last 12 hour in mm
HUM=74% Humidity in procent
Bar=1004mb Barometric pressure in millibars
FAH=023F Temperature degrees Fahrenheit
WPM=018mph Wind speed in miles per hour
WGM=024mph Wind guts in miles per hour
RNI=000inch Rain in the last hour in inches
RNI=001inch Rain in the last 24 hour in inches
RNI=000inch Rain in the last 12 hour in inches

The file I need to broadcast an APRS Weahter Beacon looks like this.

pd9q@pancake:~/linbpq/wx-project $ cat ~/linbpq/current.txt
Feb 09 2021 13:00
086/004g008t028r000p000P000h75b10007

The config file for Linbpq looks like this, this is in the aprs section of bpq32.cfg

WXCall=PD9Q-7
WXFileName=/home/pd9q/linbpq/current.txt
WXComment=/Weather Station JO11VN
WXPortList=1,5,IS        ; comma separated list 
WXInterval=10            ; mins

For Jnos in the autoexec.nos in the aprs section

aprs wx call PD9Q-7
aprs wx stat "Weather Station JO11VN"
aprs wx pos "5133.52N/00348.15E_METEO
aprs wx data "/home/pd9q/jnos/wx/current.txt"
aprs bc rftimer 10

For direwolf in the file direwolf.conf

PBEACON LAT=51^33.52N LONG=03^48.15E SYMBOL=”weather station” COMMENTCMD=”tail -1 /home/pd9q/linbpq/current.txt”

Direwolf Aprs packet look like this.

PD9Q-7>APDW15:!5133.52N/00348.15E_069/005g006t028r000p000P000h75b10007

BPQ32 Aprs packet look like this.

PD9Q-7>APBPQ1,WIDE1-1:@091338z5133.52N/00348.15E_069/005g006t028r000p000P00
0h75b10007/Weather Station JO11VN

Learned a lot.

Weather beacon

I wanted to broadcast a weather beacon, but since I don’t have a weather station it became a bit more difficult. After some searching on the internet I came across a site where I can download a file with an api with weather data that is no more than 10 minutes old. Great. After downloading the file looks a little messy.

 "liveweer": [{"plaats": "Kortgene", "station": "DE BILT AWS", "timestamp": "1577030283", "time": "22-12-2019 16:58:03", "temp": "7.3", "gtemp": "4.6", "samenv": "Van tijd tot tijd lichte regenbuien of regen", "image": "regen", "windrgr": "182.7", "windr": "ZZO", "windms": "4.06", "windbft": "3", "windknp": "7.9", "windkmh": "14.6", "windstootms": "5.19", "windstootbft": "3", "windstootknp": "10.1", "windstootkmh": "18.7", "luchttemp": "7.2", "lv": "99", "luchtd"

I can’t do much with this. Let`s manupilate the file. First add some “enters”/”new lines” in the file.

Add a enter after/new line “, ”
sed -i $’s/”, “/),\\\n(/g’ ~/wx-project/meteo.wx

Now the file looks like this

{ "liveweer": [{"plaats": "Kortgene),
(station": "DE BILT AWS),
(timestamp": "1577030283),
(time": "22-12-2019 16:58:03),
(temp": "7.3),
(gtemp": "4.6),
(samenv": "Van tijd tot tijd lichte regenbuien of regen),
(image": "regen),
(windrgr": "182.7),
(windr": "ZZO),
(windms": "4.06),
(windbft": "3),
(windknp": "7.9),
(windkmh": "14.6),
(windstootms": "5.19),
(windstootbft": "3),
(windstootknp": "10.1),
(windstootkmh": "18.7),
(luchttemp": "7.2),
(lv": "99),
(luchtd": "_),

That’s better, just clean up the mess. I end up with this.

# Remove the non-letters/numbers except . and : and –
sed -i -e “s/[^ 0-9a-zA-Z.:-]//g” -e ‘s/ \+/ /’ ~/wx-project/meteo.wx

liveweer: plaats: Kortgene
station: DE BILT AWS
timestamp: 1577030283
time: 22-12-2019 16:58:03
temp: 7.3
gtemp: 4.6
samenv: Van tijd tot tijd lichte regenbuien of regen
image: regen
windrgr: 182.7
windr: ZZO
windms: 4.06
windbft: 3
windknp: 7.9
windkmh: 14.6
windstootms: 5.19
windstootbft: 3
windstootknp: 10.1
windstootkmh: 18.7
luchttemp: 7.2
lv: 99

Now we can read the line and get the value from it. I do this with “awk”

temp=$(awk ‘NR==5{print $2}’ meteo.wx)
echo TEMP=”$temp”°C Temperature degrees Celsius

Read line 5 word number two. And we have…………….

7.3°C Temperature degrees Celsius.

In the Netherlands we work with the mertrice system. Now the weather beacon is displayed in the imperial system. Now some calculation work must take place.

# Do some calulation
# From °Celsius to Fahrenheit
fah=$(echo "(($temp*1.8)+32)" | bc)
fah1=$(echo "$fah" | awk -F'.' '{print $1}')
fah2=$(echo $fah1 | sed -e :a -e 's/^.\{1,2\}$/0&/;ta')
echo FAH="$fah2"F Temperature degrees Fahrenheit
# (Wind speed miles)From kilometer per hour to miles per hour and add leading zero(s)
wpm=$(echo "$wpk"/1.609344 | bc)
wpm0=$(echo $wpm | sed -e :a -e 's/^.\{1,2\}$/0&/;ta')
echo WPM="$wpm0"mph Wind speed in miles per hour
# (Wind guts miles) From kilometer per hour to miles per hour and add leading zero(s)
wgm=$(echo "$wgk"/1.609344 | bc)
wgm0=$(echo $wgm | sed -e :a -e 's/^.\{1,2\}$/0&/;ta')
echo WGM="$wgm0"mph Wind guts in miles per hour
# (Rain in inches) From mm to inches the last hour. Remove the (DOT) and only the first 3 numbers
rni=$(echo "$rn"*0.0039370 | bc)
rni0=$(echo $rni | sed -e 's/^[.]*//g' -e 's/^\(.\{3\}\).*$/\1/')
echo RNI="$rni0"inch Rain in the last hour in inches
# (Rain (24) in inches) From mm to inches the last 24 hour. Remove the (DOT) and only the first 3 numbers
rni24=$(echo "$rn24"*0.0039370 | bc)
rni240=$(echo $rni24 | sed -e 's/^[.]*//g' -e 's/^\(.\{3\}\).*$/\1/')
echo RNI="$rni240"inch Rain in the last 24 hour in inches
# (Rain (12) in inches) From mm to inches the last 12 hour. Remove the (DOT) and only the first 3 numbers
rni12=$(echo "$rn12"*0.0039370 | bc)
rni120=$(echo $rni12 | sed -e 's/^[.]*//g' -e 's/^\(.\{3\}\).*$/\1/')
echo RNI="$rni120"inch Rain in the last 12 hour in inches

We can finally put the beacon together.

# Let show what we have and put it on the place it belong.
echo !5133.52N/00348.15E_"$grd"/"$wpm0"g"$wgm0"t"$fah2"r"$rni0"p"$rni240"P"$rni120"h"$hum"b"$bar"
echo !5133.52N/00348.15E_"$grd"/"$wpm0"g"$wgm0"t"$fah2"r"$rni0"p"$rni240"P"$rni120"h"$hum"b"$bar" > /home/pd9q/jnos/wx/current.wx

Output

!5133.52N/00348.15E_272/010g022t046r005p028P017h92b0987

The compleet output looks like this.

TEMP=8°C Temperature degrees Celsius
WPK=16.8km/h Wind speed in Kilometers per hour
WGK=35.6km/h Wind guts in Kilometers per hour
GRD=272° Wind direction in degrees
RAIN=1.48067mm Rain in the last hour in mm
RAIN24=7.23632mm Rain in the last 24 hour in mm
RAIN12=4.53765mm Rain in the last 12 hour in mm
HUM=92% Humidity in procent
Bar=0987mb Barometric pressure in millibars
FAH=046F Temperature degrees Fahrenheit
WPM=010mph Wind speed in miles per hour
WGM=022mph Wind guts in miles per hour
RNI=005inch Rain in the last hour in inches
RNI=028inch Rain in the last 24 hour in inches
RNI=017inch Rain in the last 12 hour in inches
!5133.52N/00348.15E_272/010g022t046r005p028P017h92b098

The complete script look like this.

I put it in a cronjob, now it’s running every 15 minutes.
crontab -e
*/15 * * * * /home/pd9q/wx-project/get-wx.sh >/dev/null 2>&1

!/bin/bash
# Date 22-12-2019... Dammmmm what a job :)
# The weather beacon have to look like this....
# @220424z5057.81N/00729.37E_094/002g005t043r000p006P006h89b09783
# !5133.52N/00348.15E_073/013g...t048h85b10040wWXD
#
# Jun 01 2003 08:07
# 272/000g006t069r010p030P020h61b10150
# ***********************************************************
# 272 - wind direction - 272 degrees
# 010 - wind speed - 10 mph
# g015 - wind gust - 15 mph
# t069 - temperature - 69 degrees F
# r010 - rain in last hour in hundredths of an inch - 0.1 inches
# p030 - rain in last 24 hours in hundredths of an inch - 0.3 inches
# P020 - rain since midnight in hundredths of an inch - 0.2 inches
# h61 - humidity 61% (00 = 100%)
# b10153 - barometric pressure in tenths of a MILLIBAR - 1015.3 MILLIBARS
#
# Get the wx data from Weerlive/Meteoserver
#wget -O - "http://weerlive.nl/api/json-data-10min.php?key=?!?!?!?!?!&locatie=Kortgene" > ~/wx-project/weerlive.wx
#
wget -O - "https://data.meteoserver.nl/api/liveweer_synop.php?locatie=Kortgene&key=!?!?!?!?!?!?&select=1" > ~/wx-project/meteo.wx
#
# Some file manipulation on the METEO.WX file
# Add a enter after ", "
sed -i $'s/", "/),\\\n(/g' ~/wx-project/meteo.wx
# Remove the non-letters/numbers except . and : and -
sed -i -e "s/[^ 0-9a-zA-Z.:-]//g" -e 's/ \+/ /' ~/wx-project/meteo.wx
#
# Getting the data sorted....
now=$(date +%d%H%M)
#
temp=$(awk 'NR==5{print $2}' meteo.wx)
echo TEMP="$temp"°C Temperature degrees Celsius
# Wind speed (Kilometers)
wpk=$(awk 'NR==14{print $2}' meteo.wx)
echo WPK="$wpk"km/h Wind speed in Kilometers per hour
# Wind gust (Kilometers)
wgk=$(awk 'NR==18{print $2}' meteo.wx)
echo WGK="$wgk"km/h Wind guts in Kilometers per hour
grd=$(awk 'NR==9{print $2}' meteo.wx | awk -F'.' '{print $1}')
echo GRD="$grd"° Wind direction in degrees
rn=$(awk 'NR==38{print $2}' meteo.wx)
echo RAIN="$rn"mm Rain in the last hour in mm
rn24=$(awk 'NR==39{print $2}' meteo.wx)
echo RAIN24="$rn24"mm Rain in the last 24 hour in mm
rn12=$(awk 'NR==37{print $2}' meteo.wx)
echo RAIN12="$rn12"mm Rain in the last 12 hour in mm
hum=$(awk 'NR==20{print $2}' meteo.wx)
echo HUM="$hum"% Humidity in procent
bar=$(awk 'NR==21{print $2}' meteo.wx | awk -F: '{ printf "%04i", $1,$2 }')
echo Bar="$bar"mb Barometric pressure in millibars

# Do some calulation
# From °Celsius to Fahrenheit
fah=$(echo "(($temp*1.8)+32)" | bc)
fah1=$(echo "$fah" | awk -F'.' '{print $1}')
fah2=$(echo $fah1 | sed -e :a -e 's/^.\{1,2\}$/0&/;ta')
echo FAH="$fah2"F Temperature degrees Fahrenheit
# (Wind speed miles)From kilometer per hour to miles per hour and add leading zero(s)
wpm=$(echo "$wpk"/1.609344 | bc)
wpm0=$(echo $wpm | sed -e :a -e 's/^.\{1,2\}$/0&/;ta')
echo WPM="$wpm0"mph Wind speed in miles per hour
# (Wind guts miles) From kilometer per hour to miles per hour and add leading zero(s)
wgm=$(echo "$wgk"/1.609344 | bc)
wgm0=$(echo $wgm | sed -e :a -e 's/^.\{1,2\}$/0&/;ta')
echo WGM="$wgm0"mph Wind guts in miles per hour
# (Rain in inches) From mm to inches the last hour. Remove the (DOT) and only the first 3 numbers
rni=$(echo "$rn"*0.0039370 | bc)
rni0=$(echo $rni | sed -e 's/^[.]*//g' -e 's/^\(.\{3\}\).*$/\1/')
echo RNI="$rni0"inch Rain in the last hour in inches
# (Rain (24) in inches) From mm to inches the last 24 hour. Remove the (DOT) and only the first 3 numbers
rni24=$(echo "$rn24"*0.0039370 | bc)
rni240=$(echo $rni24 | sed -e 's/^[.]*//g' -e 's/^\(.\{3\}\).*$/\1/')
echo RNI="$rni240"inch Rain in the last 24 hour in inches
# (Rain (12) in inches) From mm to inches the last 12 hour. Remove the (DOT) and only the first 3 numbers
rni12=$(echo "$rn12"*0.0039370 | bc)
rni120=$(echo $rni12 | sed -e 's/^[.]*//g' -e 's/^\(.\{3\}\).*$/\1/')
echo RNI="$rni120"inch Rain in the last 12 hour in inches

#@220424z5057.81N/00729.37E_094/002g005t043r000p006P006h89b09783
# Let show what we have and put it on place it belong.
echo !5133.52N/00348.15E_"$grd"/"$wpm0"g"$wgm0"t"$fah2"r"$rni0"p"$rni240"P"$rni120"h"$hum"b"$bar"
echo !5133.52N/00348.15E_"$grd"/"$wpm0"g"$wgm0"t"$fah2"r"$rni0"p"$rni240"P"$rni120"h"$hum"b"$bar" > /home/pd9q/jnos/wx/current.wx
#