Meteoalarm Weather Warnings PHP WebService

Accurate, localised weather warnings are a useful addition to any weather website. Historically I have used Wunderground’s Alerts API for this purpose on my own weather website. However, at some point last year Wunderground’s Alerts API stopped returning any weather warnings for the UK even during major weather events. At the time of writing this is still the case.

I noted that Wunderground were receiving their European weather warning data from Meteoalarm. Looking at their website I found that weather warnings from the UK were being reported accurately matching exactly what the UK MetOffice (the source of Meteoalarm’s UK data) were publishing on any given day.

To my disappointment neither Meteoalarm nor the MetOffice published a webservice API for weather warnings. Meteoalarm do, however, provide RSS feeds of weather warnings for each country and region in Europe that they support.

I decided to use Meteoalarm’s RSS feeds to solve my own issue with publishing weather warnings to my website for my local area. However, I knew that directly publishing raw RSS feeds would not be not flexible enough for my needs. I would instead prefer a RESTful JSON formatted web service API which I could call via AJAX.

To this end I’ve written meteo-alarm-weather-warnings. This is a PHP API available on GitHub under the MIT License. It’s primary use case is to make it easy to incorporate the latest MeteoAlarm weather warnings into a web site while not requiring users to directly engage with the underlying RSS feeds. The web service fetches the appropriate RSS feed for a given request and parses and converts it into a consistent JSON formatted reply.

It’s functionality includes:

  1. The ability to query for all weather warnings for all regions within any European country covered by Meteoalarm for today and tomorrow.
  2. The ability to query for weather warnings for any individual region for today and tomorrow.
  3. Custom date/time formats to use for results.
  4. Custom time zone to use for date/times in results (Meteoalarm reports all date/times in CET).

For example, here is a portion of the the raw JSON results from meteo-alarm-weather-warnings for the UK on 31/Dec/2017 when several warnings were in effect:

meteo-alarm-weather-warnings

Click to Enlarge

meteo-alarm-weather-warnings is now incorporated into my own weather web site’s weather warnings page. Here is how it looked rendering results from the web service for my local area on 31/Dec/2017:

meteo-alarm-weather-warnings on website

Click to Enlarge

 

 

Explore posts in the same categories: Code Projects, Meteorology, Open Source, Weather Station

Tags: , , , ,

You can comment below, or link to this permanent URL from your own site.

10 Comments on “Meteoalarm Weather Warnings PHP WebService”

  1. Manuel Says:

    Hello Wayne,

    First of all thanks a lot for your API. It has allowed me to make a Tasker task to update the weather alerts directly to my Android phone.

    I was wondering if there is any problem with the API?, I haven’t been able to get weather alerts this past couple of days and your weather site is also not showing any Alerts.

    Best regards and thanks!!

    Manuel

    • waynedgrant Says:

      Hello Manuel,

      Metoeoalarm itself is having issues.

      Their main RSS link linked from http://www.meteoalarm.eu/ (http://www.meteoalarm.eu/documents/rss/europa.rss) is returning a 404 as is the UK RSS my site uses (http://www.meteoalarm.eu/documents/rss/uk.rss).

      Warnings are being shown in HTML and Atom feeds are also okay.

      Warnings are, however, still be rendered and Atom feeds are okay.

      I’ve mailed them to see if they’re aware of the issue.

      – Wayne

      • waynedgrant Says:

        Meteoalarm is working again.

      • Manuel Says:

        Yes, I just saw it. But when I get to your API: https://waynedgrant.com/weather/warnings/warnings.json?country=ES I get a 404. Does the API need time to update to the working page?

      • waynedgrant Says:

        This is by design. My instance of the warnings.json is intended for use by my website only. I have therefore locked it down overnight (in investigating this Meteoalarm issue I found instances of automated scripts polling my warnings.json on regular intervals – this amounted to 1000s of hits a month).

        If you need a weather warnings then you can stand up your own service – https://github.com/waynedgrant/meteo-alarm-weather-warnings. This is why I open sourced my work.

      • Manuel Says:

        Oh sorry… I thought it was open. I was was one of those pulling data every 3 hours. Unfortunately I don’t have the skills to use your Githhub (or any other github). I will have to look for an alternative…

        Regards

      • waynedgrant Says:

        It’s unfortunate. I’d love to make it open but then meteoalarm would potentially get a load of traffic from my website and then ban me.

        I had one Ruby script in Finland hitting it every 5 minutes which is taking the piss. That’s what I was looking to prevent. Every 3 hours is pretty reasonable though.

        So 2 things:

        1) I may look to make the webservice smarter with caching so I can make my instance open. This will take a while to achieve.
        2) In the meantime it seems unfair you are being “punished” for reporting an issue to me so I’ll give you access. I’ll be in touch later today with the details on the email address you have posted your comments on.

  2. Nico Says:

    Hello Wayne
    First of all, I hope my English can be read. Understanding is fine but I’m 64 then writing is a bit more difficult. I’m trying to get your php scripts up and running but there are a few uncertainties.
    You indicate on github that I have to change the warnings.json to warnings.php. Then you give warnings.json in the examples. ???
    Okay that’s both trying to see which one works. but both do not get to see raw data in my browser.
    when I use http://192.168.2.26/MeteoAlarm/Warnings.php I get NOT FOUND
    If I only use http://192.168.2.26 I get my PHP info data nicely.
    What could I do wrong?

  3. Nico Says:

    Oh i forgot but this is wat i find in my apache log
    PHP Fatal error: Uncaught Error: Call to undefined function mb_convert_encoding() in /var/www/html/MeteoAlarm/Warnings.php:26\nStack trace:\n#0 {main}\n thrown in /var/www/html/MeteoAlarm/Warnings.php on line 26

    • waynedgrant Says:

      Hello Nico,

      You only need to rename the file if you cannot place the AddHandler line in an .htaccess file to get PHP to process .json files.

      After renaming you should have *both* of these files:
      warnings.php
      Warnings.php

      Note the different case of the first letter of each.

      The first is the endpoint (all lower case) you need to hit with your browser.

      If you only have one of these files then I would guess you are using windows to do the rename which does not support multiple files that differ in name only by case.

      In that case simply rename warnings.php to be meteoalarm.php and access:

      http://192.168.2.26/MeteoAlarm/meteoalarm.php


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: