Skip to content
Dipack's Website
GitLabGitHub

GUI METAR Decoder in Rust

5 min read

As a follow-up to my last project over 3 years ago, about a YouTube scraper for Spotify libraries in Rust, I recently decided to write a METAR decoder GUI application in Rust!

What is a METAR?

METAR stands for Meteorological Aerodrome Report, which is a method of encoding weather information observed at a weather station in a concise and information rich format.

A typical METAR looks like something like:

KPAE 142153Z 18025G33KT 10SM BKN023 BKN030 BKN042 09/06 A2965 RMK AO2 PK WND 18043/2134 RAE47 SLP040 P0000 T00890056

where KPAE stands for the weather reporting station, in this case Paine Field in Everett, Washington state, 142153Z stands for the 14th day of the month, at 2153 Zulu (UTC) time, 18025G33KT stands for the wind direction of 180 degrees, with wind speeds of 25 knots gusting to 35 knots peak, 10SM stands for 10 statute miles of visibility, BKN023, BKN030, BKN042 all stand for cloud layers at 2300 feet, 3000 feet, and 4200 feet above ground level respectively, 09/06 stands for 9 degrees Celsius temperature, with a dew-point of 6 degrees Celsius, and A2965 stands for 29.65 inches of mercury as the local air pressure. Everything from the RMK block of text onwards represents remarks that are meant for more complex or involved use cases.

If you want to read some more about how to decode METARs, and other similar sources of weather information this is a great guide 

I've used in the past.

Okay, but why METARs?

A couple of years ago, I was fortunate enough to indulge in a new hobby of mine, aviation. I was able to earn my Private Pilot's License, a few months later. A core component of being a safe pilot is being to "read" the weather, and understand how it might influence your flight, if you decide to take-off.

I regularly use METARs as a way of deciding if I want to fly on a particular day, and if I do, then what the weather might look like along the route of my flight. Even when I'm not planning on flying myself, I use METARs as a way of determining what the local weather in my area might look like.

The aforementioned reasons, combined with my desire to continue on my journey of learning Rust, led me to try and build a simple METAR decoder, i.e. something that can take the highly abbreviated and dense METAR strings and convert them into plain English.

What does it look like?

When you first boot the application. Starting screen

After you put in some valid weather stations, and hit the "Fetch" button. With some weather stations

Where's the code?

The code is accessible on my Gitlab here 

.

What can it do?

Apart from its main feature of decoding METAR information into plain English, it can do the following:

  1. Since it uses the Aviation Weather.gov (AWC) Data API to fetch METAR information, it supports any weather station indexed by AWC, which means it works for most airports in the world
  2. A nice wind chevron indicating where the wind is coming from
  3. Automatically refreshes METAR information to capture changes, every 5 minutes
  4. Filters out invalid weather station codes
  5. No real limits (apart from how much you want to scroll) to the number of weather stations you can query and display
  6. Duplicate weather station code reconciliation
  7. Background colour changes for each weather station depending on weather conditions. For example, Green means VFR, Blue means Marginal VFR, etc. so you can tell what the local weather is at a glance

Challenges

This project took me about a week of solid effort to complete -- even now there's some things that I could add on it, such as the ability to decode weather forecasts published by some weather stations called Terminal Aerodrome Forecast (TAF) 

.

With that said I do consider this project feature complete for my use case.

As for the challenges, there were quite a few, most of which were actually related to the use of the Iced-rs 

GUI library, stemming from a lack of documentation for most of its features. I had to spend a ton of time scouring the internet with obscure search terms (not helped by the fact that phrase "iced", and "rust" can mean different things depending on context), and looking at the examples page on the project's Github repository. I was aware that I might run into such issues when using Iced, since it seems to have a reputation in the Rust GUI community for lacking documentation, and being harder to understand compared to alternatives.

To framework's credit though, there are a fair number of examples 

for a multitude of use cases, which proved to be pretty useful, and it keeps all of its logic in Rust, which was a huge factor in my decision to use Iced over alternatives which used CSS/JavaScript, etc. to supplement their Rust code.

A couple of examples of some meaty challenges:

  1. Dynamic stylesheets: I wanted the ability to change the colour of a text box depending on certain information, and there's no clear examples of how to generate dynamic stylesheets, or even how to apply them in the Iced docs. In the end, after a lot of searching on the internet, I stumbled upon the move keyword, and how it could be used to apply stylesheets dynamically 

    .

  2. Automatic refreshes of METARs: This one was not as tough as the dynamic stylesheets problem, but did require a better understanding of how Iced works in general. I was able to look at the Stopwatch example 

    to see how it handled GUI updates on a set frequency.

These are just a couple of issues that I faced when building this application, but with that said, I did thoroughly enjoy building with Rust and Iced GUI framework -- nothing really beats the sensation of seeing your application work to end-to-end smoothly with no hitches!

© 2024 by Dipack's Website. All rights reserved.