Parse weather data from NOAA Aviation Weather Centre

I wanted to import local weather data into emoncms for further processing and display so I wrote this little flow to retrieve the data.

Official Airport weather reports are by nature very accurate and are reported every 30 minutes from every airport worldwide to the NOAA Aviation Weather Centre, formatted as a METAR - http://www.aviationweather.gov/metar

To see what data is retrieved, call - http://www.aviationweather.gov/api/data/dataserver?requestType=retrieve&dataSource=metars&stationString=EGSS&hoursBeforeNow=3&format=xml&mostRecent=true from your browser and it will retrieve the most recent METAR data. In this example from Stanstead airport (EGSS), but change the airport ICAO code to the nearest airport. To find an airport's ICAO code try http://www.avcodes.co.uk/aptcodesearch.asp (don't use the IATA Code - it won't work!).

The flow will parse data from http://www.aviationweather.gov and output as a CSV (which I need for emoncms) however once you have the variables in the function node, you can do whatever you want with the data.

NOTES;

  1. METAR standards mean that the XML feed will only include 'wind gust' data it there are wind gusts exceeding 10 knots above the mean windspeed recorded in the preceding 10 minutes, therefore my flow checks if wind gust data is included, and if not, sets the wind gust output to the same value as the windspeed.

  2. Humidity is calculated in the flow using the August-Roche-Magnus Approximation formula from the temperature and dewpoint

  3. Flow updated 7/11/2023 to reflect the data server change by AWC.

[{"id":"797da8df.868258","type":"http request","z":"8ec88bd9c36c3f6b","name":"Data source","method":"GET","paytoqs":"ignore","url":"https://www.aviationweather.gov{{{payload}}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":325,"y":855,"wires":[["2f8afb7b.d07504"]]},{"id":"2f8afb7b.d07504","type":"xml","z":"8ec88bd9c36c3f6b","name":"","x":471,"y":855,"wires":[["2c53b24f.d3ac4e"]]},{"id":"8252727b.7dad9","type":"debug","z":"8ec88bd9c36c3f6b","name":"","active":true,"console":"false","complete":"false","x":795,"y":855,"wires":[]},{"id":"2c53b24f.d3ac4e","type":"function","z":"8ec88bd9c36c3f6b","name":"Parse METAR","func":"var METARdata = msg.payload.response.data[0].METAR[0];\nvar wind = METARdata.wind_speed_kt[0];\nvar gusts = wind; //if wind_gust_kt is not present, value defaults to wind_speed_kt\n   if (typeof METARdata.wind_gust_kt != \"undefined\") {\n\t   gusts = METARdata.wind_gust_kt[0];\n       }\nvar altim = METARdata.altim_in_hg[0];\nvar pressure = Math.round(altim * 33.8637526); //convert hg to mb\nvar dew = METARdata.dewpoint_c[0];\nvar temp = METARdata.temp_c[0];\n\n//August-Roche-Magnus approximation to calculate humidity\nvar constA = 17.625;\nvar constB = 243.04;\nvar rh_numer = 100.0*Math.exp((constA*eval(dew))/(eval(dew)+constB));\nvar rh_denom = Math.exp((constA*eval(temp))/(eval(temp)+constB));\nvar rh_hum   = (rh_numer/rh_denom);\nvar humidity = Math.round(rh_hum);\n\nmsg.payload = ((wind) + (\",\") + (gusts) + (\",\") + (humidity) + (\",\") + (pressure) + (\",\") + (temp));\nreturn msg;","outputs":1,"x":626,"y":855,"wires":[["8252727b.7dad9"]]},{"id":"8b841d88.747be","type":"comment","z":"8ec88bd9c36c3f6b","name":"NOAA Weather data","info":"Retrieving Finningly Airport METAR feed","x":157,"y":816,"wires":[]},{"id":"4ffb8be82cd5cec4","type":"inject","z":"8ec88bd9c36c3f6b","name":"Weather report","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":false,"onceDelay":"","topic":"","payload":"/api/data/dataserver?requestType=retrieve&dataSource=metars&stationString=EGSS&hoursBeforeNow=3&format=xml&mostRecent=true","payloadType":"str","x":150,"y":855,"wires":[["797da8df.868258"]]}]

Flow Info

Created 11 years ago
Updated 1 year ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • function (x1)
  • http request (x1)
  • inject (x1)
  • xml (x1)

Tags

  • Weather
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option