| 1 |
FlightGear METAR proxy server |
| 2 |
============================= |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
metarproxy is a caching proxy server for METAR data strings written in |
| 7 |
Perl. It can be used to: |
| 8 |
|
| 9 |
- provide METAR data for machines without internet connection |
| 10 |
- centralize METAR fetching: one machine in a network runs the proxy, all |
| 11 |
other connect to the proxy |
| 12 |
- deliver defined and reproducible weather for educational purposes |
| 13 |
- save weather situations for later use |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
Quick instructions to try out: |
| 20 |
|
| 21 |
$ metarproxy --download 3h |
| 22 |
$ metarproxy --color & |
| 23 |
$ fgfs --proxy=localhost:5509 --time-offset=-2 --enable-real-weather-fetch |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
To make use of the proxy, you have to: |
| 31 |
|
| 32 |
1. check if you want to use the default cache directory |
| 33 |
and other default settings, or change them accordingly |
| 34 |
2. make sure the cache is filled with METAR strings |
| 35 |
3. start the proxy server |
| 36 |
4. run fgfs with appropriate time and proxy settings |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
1. Basic setup and preparing the cache |
| 42 |
====================================== |
| 43 |
If you are happy with the defaults, you can well skip to the |
| 44 |
next section. |
| 45 |
|
| 46 |
|
| 47 |
1a. The cache directory |
| 48 |
----------------------- |
| 49 |
All metarproxy operation modes need access to a cache, either for |
| 50 |
storing or retrieving METAR strings. By default, the cache directory |
| 51 |
is $FG_HOME/metar, whereby $FG_HOME is either to be set as environment |
| 52 |
variable, or defaults to $HOME/.fgfs. $HOME, in turn, defaults to "." |
| 53 |
(the current working directory). In other words: if no provisions are |
| 54 |
made, you end up with /home/$USER/.fgfs/metar as your cache directory |
| 55 |
on Linux-like operating systems, and ./.fgfs/metar elsewhere. |
| 56 |
|
| 57 |
There are several ways to change the cache path: |
| 58 |
|
| 59 |
- change one of the environment variables, ideally $FG_HOME. This can |
| 60 |
be done in the system configuration in MS Windows, and in ~/.bashrc |
| 61 |
or ~/.profile etc. on Linux-like systems |
| 62 |
|
| 63 |
export FG_HOME=/var/tmp/metar |
| 64 |
|
| 65 |
- or on the command line when running metarproxy: |
| 66 |
|
| 67 |
$ FG_HOME=/var/tmp/metar metarproxy |
| 68 |
|
| 69 |
- you can also set the cache directory directly as a command line option |
| 70 |
--base or -b: |
| 71 |
|
| 72 |
$ metarproxy --base=/var/tmp/metar |
| 73 |
|
| 74 |
- this command line option can, together with any of the other metarproxy |
| 75 |
options, be stored again in an environment variable METARPROXY |
| 76 |
|
| 77 |
export METARPROXY="-c -vv -b/var/tmp/metar" |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
1b. set metarproxy's proxy server |
| 83 |
--------------------------------- |
| 84 |
metarproxy isn't only a proxy server itself, it can also use one to |
| 85 |
download METAR strings. By default it uses the one defined in the |
| 86 |
environment variable http_proxy (which is commonly used on Linux-like |
| 87 |
systems, and is, for instance, used by the lynx browser), or none if |
| 88 |
unset. To set a particular proxy server for HTTP download, use one of |
| 89 |
these methods: |
| 90 |
|
| 91 |
- set http_proxy globally: export http_proxy=http://localhost:3128/ |
| 92 |
- or on the command line: $ http_proxy=http://localhost:3128/ metarproxy |
| 93 |
- unset http_proxy: $ http_proxy= metarproxy |
| 94 |
- use the command line option: $ metarproxy --proxy=http://localhost:3128/ |
| 95 |
- set the option globally: export METARPROXY="-yhttp://localhost:3128" |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
2. Fill the cache with METAR data |
| 104 |
================================= |
| 105 |
|
| 106 |
There are three operation modes to do that: |
| 107 |
|
| 108 |
2a. --download mode to download worldwide data sets |
| 109 |
2b. --install mode to install files from your system |
| 110 |
2c. --record mode to record a selection of stations over some period |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
2a. --download mode |
| 115 |
------------------- |
| 116 |
You can download worldwide sets of METAR strings, each in a file of about |
| 117 |
1MB size from tgftp.nws.noaa.gov[1]. This can be done with a separate ftp |
| 118 |
client or web browser, but it can also be done by metarproxy: |
| 119 |
|
| 120 |
$ metarproxy --download 3h ... download last three hours (~ 3MB) |
| 121 |
|
| 122 |
Note that the file for the *current* hour is only partly filled! You can |
| 123 |
use from 1h up to 24h. Alternatively, you can request particular hours: |
| 124 |
|
| 125 |
$ metarproxy --download 0 ... download first hour after midnight GMT |
| 126 |
|
| 127 |
Ranges are allowed, too: |
| 128 |
|
| 129 |
$ metarproxy --download 0-2 ... download first three hours after |
| 130 |
midnight GMT |
| 131 |
|
| 132 |
These three methods can be used in combination: |
| 133 |
|
| 134 |
$ metarproxy --download 6h 0-2 4 |
| 135 |
|
| 136 |
Files downloaded this way aren't stored on your systems in the same form |
| 137 |
as they are offered under [1], but are already stored in the cache in a |
| 138 |
different way (see section 5). Redundant strings are not stored, so it's safe |
| 139 |
to --download the same hours more than once. This won't create duplicates. |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
2b. --install mode |
| 145 |
------------------ |
| 146 |
The --download mode needs a sufficiently cheap and fast internet |
| 147 |
connection. Sometimes it may be desirable to download the files directly |
| 148 |
from the links (see [1]) on one computer, to burn them on a CD and then |
| 149 |
to install them on the laptop. The downloaded files have names like |
| 150 |
00Z.TXT to 23Z.TXT, whereby the number stands for the hour when they |
| 151 |
were started. Only the last 24 hours are available for download. |
| 152 |
If GMT is 1800, then 18Z.TXT will be the currently written and most |
| 153 |
recent file. 19Z.TXT is already 23 hours old and will be overwritten |
| 154 |
in one hour. To install such files in the cache, do this: |
| 155 |
|
| 156 |
$ metarproxy --install 00Z.TXT 01Z.TXT |
| 157 |
|
| 158 |
or |
| 159 |
|
| 160 |
$ metarproxy --install ??Z.TXT |
| 161 |
|
| 162 |
etc. |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
2c. --record mode |
| 168 |
----------------- |
| 169 |
To record a set of stations over a period, without the need to download |
| 170 |
several megabytes of data, you can use the record mode: |
| 171 |
|
| 172 |
$ metarproxy --record KSFO KOAK KNUQ KSJC KCCR |
| 173 |
|
| 174 |
The stations are then checked every 15 minutes and the METAR data |
| 175 |
stored in the cache. Additionally, you can specify one or more files |
| 176 |
with station IDs: |
| 177 |
|
| 178 |
$ metarproxy --record --file=$FG_HOME/station-list |
| 179 |
$ metarproxy --record EDDM --file=/tmp/Austria --file=/tmp/Hungary |
| 180 |
|
| 181 |
These files simply contain station IDs separated by spaces in one |
| 182 |
or more lines: |
| 183 |
|
| 184 |
$ cat /tmp/Austria |
| 185 |
LOWL LOWI LOWS LOWW LOWK LOWG |
| 186 |
LOXL LOXA LOXT |
| 187 |
|
| 188 |
Some of the IDs are logically assigned, so that you can create a list |
| 189 |
of, lets say, all Austrian METAR stations from FlightGear's METAR list: |
| 190 |
|
| 191 |
$ zgrep "^LO" $FG_ROOT/Airports/metar.dat.gz > /tmp/Austria |
| 192 |
$ zgrep "^ED" $FG_ROOT/Airports/metar.dat.gz > /tmp/Germany |
| 193 |
$ zgrep "^EG" $FG_ROOT/Airports/metar.dat.gz > /tmp/UK |
| 194 |
$ zgrep "^K" $FG_ROOT/Airports/metar.dat.gz > /tmp/USA |
| 195 |
|
| 196 |
Quit the --record mode by Ctrl-C or killing the program. |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
3. run the metarproxy server |
| 203 |
============================ |
| 204 |
|
| 205 |
assuming that the cache directory is already set, you just need to |
| 206 |
run the proxy: |
| 207 |
|
| 208 |
$ metarproxy& |
| 209 |
|
| 210 |
or with colored output and more log messages: |
| 211 |
|
| 212 |
$ metarproxy -c -vv |
| 213 |
|
| 214 |
The proxy listens to port 5509 by default, but you can easily let |
| 215 |
it use another port. As you can see, the proxy is quite liberal |
| 216 |
with respect to option syntax: |
| 217 |
|
| 218 |
$ metarproxy --port 1234 |
| 219 |
$ metarproxy --port=1234 |
| 220 |
$ metarproxy -p 1234 |
| 221 |
$ metarproxy -p1234 |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
4. let fgfs use the metar proxy |
| 229 |
=============================== |
| 230 |
|
| 231 |
All you need to do is point FlightGear to the metar proxy and let |
| 232 |
it run at a simulated time for which you actually have cached METAR |
| 233 |
data: |
| 234 |
|
| 235 |
$ fgfs --enable-real-weather-fetch --proxy=localhost:5509 \ |
| 236 |
--start-date-lat=2005:01:12:12:00:00 |
| 237 |
|
| 238 |
FlightGear will then fetch the metar data from the proxy as if it |
| 239 |
were tgftp.nws.noaa.gov. If no appropriate data set is found at all, |
| 240 |
the proxy sends a default string. If data are found but older than |
| 241 |
250 minutes, then the last successful data are sent again. |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
5. the cache organization |
| 249 |
========================= |
| 250 |
|
| 251 |
metarproxy puts all data for KSFO on 2005/1/19 into a directory |
| 252 |
2005-01-19/K/KS/KSFO. The date directory name is used to find all |
| 253 |
data for this day, but metarproxy will also look at the date in |
| 254 |
particular METAR strings. So, renaming the directory to 2005/1/20 |
| 255 |
won't make the cached data available for the next day! You need |
| 256 |
to set fgfs' GMT date to 2005/1/19. Also, if the simulated GMT |
| 257 |
is midnight, then you will get midnight weather. You can't |
| 258 |
enjoy midnight weather at daylight. The cache always delivers |
| 259 |
the (past) real weather at simulated GMT. |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
6. download addresses |
| 266 |
===================== |
| 267 |
Download addresses for the last 24 hours: |
| 268 |
|
| 269 |
http://tgftp.nws.noaa.gov/data/observations/metar/cycles/ |
| 270 |
ftp://tgftp.nws.noaa.gov/data/observations/metar/cycles/ |
| 271 |
|
| 272 |
Addresses for the most recent METAR data strings of particular |
| 273 |
stations: |
| 274 |
|
| 275 |
http://tgftp.nws.noaa.gov/pub/data/observations/metar/stations/ |
| 276 |
ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/ |
| 277 |
|
| 278 |
|
| 279 |
$Id$ |
| 280 |
Melchior FRANZ <mfranz # aon : at>, 2005/1/24 |
| 281 |
|