Add weather report from local weather station to APRS node

I recently set up a APRS gateway. Check instructions in older posts. In the script pymultimonaprs you can set weather when set in a json-file. eg: “weather”: “/path/to/weather.json”. I live next to the automated weather station for our city. Instead of building own WX I decided to use the data from this nearby station. The data is provided in XML from our national agency ARSO. The data is available for some major cities in Europe, too.

Main idea was to prepare PHP script to parse the XML data and prepare text file, which is acceptable for pymultimonaprs. Next step is to wget this text from some server and copy it to the raspberry pi with cron job.

This page will give you an example how to:

  • parse XML file with weather data using PHP script
  • output the text for pymultimonaprs weather file
  • prepare cron job with raspberry pi



The weather status file can look like this

    "timestamp": 1366148418,
    "wind": {
        "speed": 10,
        "direction": 240,
        "gust": 200
    "temperature": 18.5,
    "humidity": 20,
    "pressure": 1013.25


  • timestamp is seconds since epoch – must be included
  • wind
    • speed is in km/h
    • direction is in deg
    • gust is in km/h
  • temperature is in °C
  • humidity is in %
  • pressure is in hPa

The timestamp must be included – everything else is optional.

The whole XML from weather agency looks something like this (not whole file shown, for complete XML specification you may check ARSO page in Slovenian language):

SimpleXMLElement Object
    [@attributes] => Array
            [id] => MeteoSI_WebMet_observationAms_xml
    [language] => sl
    [credit] => - ARSO
... ... ...
    [meteosi_url] => SimpleXMLElement Object
    [two_day_history_url] =>
    [metData] => SimpleXMLElement Object
            [domain_title] => NOVO MESTO
            [domain_id] => SimpleXMLElement Object
            [domain_shortTitle] => NOVO MESTO
            [domain_longTitle] => Novo mesto
... ... ...
            [t_var_desc] => Temperatura
            [t_var_unit] => °C
            [t] => 5.8
            [t_state] => 0
            [tavg_var_desc] => Povprečna temperatura v časovnem intervalu
            [tavg_var_unit] => °C
            [tavg] => 5.7
            [tavg_state] => 0
            [tx_var_desc] => Maksimalna temperatura v časovnem intervalu
            [tx_var_unit] => °C
            [tx] => 6.1
            [tx_state] => 0
... ... ... 


Now you read XML to the object and print just the proper data from this object. The code for this is:

// Get data from weather station
$url = '';
$xml = simplexml_load_file($url) or die("feed not loading");
    "timestamp": <?php echo strtotime($xml->metData->tsUpdated_UTC);?>,
    "wind": {
        "speed": <?php echo $xml->metData->ffavg_val_kmh;?>,  
        "direction": <?php echo $xml->metData->ddavg_val;?>,
        "gust": <?php echo $xml->metData->ffmax_val."\n";?>
    "temperature": <?php echo $xml->metData->tavg;?>,
    "humidity": <?php echo $xml->metData->rhavg;?>,
    "pressure": <?php echo $xml->metData->pavg."\n";?>

You should place this PHP source on some server where you can nrun PHP scripts. Mine is here: Just check the source of the page, not what your browser display. This output is not for browser. You may look for more fancy output in a table HERE.

Now you prepare periodic read on your raspberry pi to read from the output of the above script to local file. You will need this for APRS weather status reporting. When  you want to run a script periodically on your Raspberry Pi, you use something called “cron job”.

Go to the directory /etc/cron.d and check for files there:

cd /etc/cron.d

This is where all the magic happens. The cron.d folder is where you create a file for each Cron Job. You can NOT use folders to organize them, but you can put more than one Cron Job in one file.

But let’s first create a shell script to get php output. You can place it in dedicated “weather” folder and make it executable:

mkdir ~/rtl/weather
nano ~/rtl/weather/

And type the command (use your url):

wget -q -O ~/rtl/weather/weather.json

Save the file, close nano (CTRL+X) and use chmod to make it executable:

chmod +x ~/rtl/weather/

You may check if shell script is working:


The output should be in file ~/rtl/weather/weather.json. You may check the content with

less ~/rtl/weather/weather.json

just press “q” to quit the preview with less.

Check with pwd that you are in /etc/cron.d folder. If not, type cd /etc/cron.d

Edit cron job file:

sudo nano mycronjob

and enter the following line in the editor:

*/10 * * * * pi ~/rtl/weather/

Don’t forget to add a line break to your Cron Job. If your Cron Job does not run it´s probably the reason why. The five stars define the minute, hour, day, month and day of the week (in that order). After the stars, we add the user context for the Cron Job so we can write into the pi folder. The last parameter is the script that should get run, obviously. You want to run your Cron Job every 10 minutes, that’s why you need to divide by 10 after first star.

After saving and closing the Cron Job file, there is nothing else to do. Your Cron Job is set up and should hopefully work, just check the text file (/home/pi/rtl/weather/weather.json) after ten minutes!

There is one final step. Edit the file pymultimonaprs.json and change the link to weather status file.

sudo nano /etc/pymultimonaprs.json

and change weather line to:

"weather": "/home/pi/rtl/weather/weather.json"

Final result should be something like this:


Leave a Reply