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.

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

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

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.

We can finally put the beacon together.

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