Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Difference between revisions of "Howto:Fetch live aloft data"

From FlightGear wiki
Jump to: navigation, search
(New page: == Introduction == This HOWTO describes how to setup live setting of wind aloft. This is the wind speed, direction and temperature for different altitudes. FlightGear's feature of setting ...)
 
(Running FlightGear: added weather category)
 
(13 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== Introduction ==
+
This [[:Category:Howto|howto]] describes '''how to setup live setting of wind aloft'''. This is the wind speed, direction and temperature for different altitudes. [[FlightGear]]'s feature of setting current weather by using the <tt>--enable-real-weather-fetch</tt> uses [[METAR]] which only reports ground weather.  
This HOWTO describes how to setup live setting of wind aloft. This is the wind speed, direction and temperature for different altitudes. FlightGear's feature of setting current weather by using the --enable-real-weather-fetch uses METAR which only reports ground weather.  
+
  
The aloft feature currently only works for the CVS version of FlightGear since you have to apply a tiny patch to the sourcecode (just a single line). It only works if you have '''bash''', '''awk''', '''wget''' and '''netcat''' on your machine. This is usually the case if you are running linux and should be no sweat for OS/X but might require some setup if you have some less feature rich operating system.
+
The aloft feature currently only works if you have a source distribution of FlightGear or the [[Git]] version since you have to apply a tiny patch to the sourcecode (just a single line). It only works if you have '''bash''', '''awk''', '''wget''' and '''netcat''' on your machine. This is usually the case if you are running linux and should be no sweat for OS/X but might require some setup if you have some less feature rich operating system.
 +
 
 +
Update 2019/01: It seems the Jeppesen service has been put behind a paywall. Can anyone confirm? ([[User:OO-ISA|OO-ISA]] ([[User talk:OO-ISA|talk]]))
  
 
== General description ==
 
== General description ==
The wind aloft data is brought to you by the nice people of Jeppesen(R). Under [[http://www.jeppesen.com/weather http://www.jeppesen.com/weather]] a Text Weather service is provided free of charge. We use this service to fetch the aloft forcast and use these data as input for FlightGear.
+
The wind aloft data is brought to you by the nice people of Jeppesen(R). Under http://www.jeppesen.com/weather a Text Weather service is provided free of charge. We use this service to fetch the aloft forecast and use these data as input for FlightGear.
  
When enabling the --real-weather-fetch option, FlightGear searches for the nearest airport to your present position that has a METAR service. If it finds one, it propagates the environmental settings and the station id of the airport the METAR was fetched for. A tiny add-on sends this station-id to a listening daemon program called aloftd.  
+
When enabling the <tt>--real-weather-fetch</tt> option, FlightGear searches for the nearest airport to your present position that has a METAR service. If it finds one, it propagates the environmental settings and the station id of the airport the METAR was fetched for. A tiny add-on sends this station-id to a listening daemon program called aloftd.  
  
The aloftd waits for input from FlightGear and interprets it as station ids. If the station id changes, it retrieves the aloft forcast from Jeppesen(R), parses the data, connects to the FlightGear telnet server and sets the aloft data in the property tree.
+
The aloftd waits for input from FlightGear and interprets it as station ids. If the station id changes, it retrieves the aloft forecast from Jeppesen(R), parses the data, connects to the FlightGear telnet server and sets the aloft data in the property tree.
  
 
== What to do ==
 
== What to do ==
Line 15: Line 16:
 
First, we need to tell FlightGear how to broadcast the station ID of the actual METAR-station. Copy and paste the following code into a file named
 
First, we need to tell FlightGear how to broadcast the station ID of the actual METAR-station. Copy and paste the following code into a file named
 
metarstationid.xml and save it to your data/Protocol directory.
 
metarstationid.xml and save it to your data/Protocol directory.
<?xml version="1.0"?>
+
<source>
<PropertyList>
+
<?xml version="1.0"?>
  <comment>
+
<PropertyList>
  <![CDATA[
+
<comment>
    Usage:  
+
  <![CDATA[
    fgfs --generic=socket,out,1,localhost,5500,udp,metarstationid
+
    Usage:  
  ]]>
+
    fgfs --generic=socket,out,1,localhost,5500,udp,metarstationid
  </comment>
+
  ]]>
  <generic>
+
</comment>
  <output>
+
<generic>
    <line_separator>newline</line_separator>
+
  <output>
    <var_separator>,</var_separator>
+
  <line_separator>newline</line_separator>
    <chunk>
+
  <var_separator>,</var_separator>
    <name>metar-station-id</name>
+
  <chunk>
    <format>%s</format>
+
    <name>metar-station-id</name>
    <type>string</type>
+
    <format>%s</format>
    <node>/environment/metar/station-id</node>
+
    <type>string</type>
    </chunk>
+
    <node>/environment/metar/station-id</node>
  </output>
+
  </chunk>
  </generic>
+
  </output>
</PropertyList>
+
</generic>
 +
</PropertyList>
 +
</source>
  
 
=== The FlightGear Patch ===
 
=== The FlightGear Patch ===
Line 43: Line 46:
 
  // fgSetupWind(dir_from, dir_to, speed, gust);
 
  // fgSetupWind(dir_from, dir_to, speed, gust);
 
in the file src/Environment/environment_ctrl.cxx. It should be around line 620. Perform a make for FlightGear.
 
in the file src/Environment/environment_ctrl.cxx. It should be around line 620. Perform a make for FlightGear.
 +
 +
'''EDIT:''' This is no longer needed if you use FlightGear Git. Just set the property
 +
/environment/params/metar-updates-winds-aloft
 +
to false. This can be done from the command line like
 +
--prop://environment/params/metar-updates-winds-aloft=0
  
 
=== The aloftd ===
 
=== The aloftd ===
 
Copy and paste the following code to a file named '''aloftd''':
 
Copy and paste the following code to a file named '''aloftd''':
 +
<source lang="bash">
 
  #!/bin/bash
 
  #!/bin/bash
 
  #KSFO FD DATA BASED ON 190600Z.
 
  #KSFO FD DATA BASED ON 190600Z.
Line 141: Line 150:
 
   ' | netcat localhost ${TELNET_PORT}
 
   ' | netcat localhost ${TELNET_PORT}
 
  done
 
  done
 +
</source>
  
 
Save the file to any location and make the file executable.
 
Save the file to any location and make the file executable.
Line 147: Line 157:
 
Now start your FlightGear with the following additional options:
 
Now start your FlightGear with the following additional options:
 
  --generic=socket,out,0.5,localhost,5123,udp,metarstationid --telnet=2323
 
  --generic=socket,out,0.5,localhost,5123,udp,metarstationid --telnet=2323
 +
 +
Open another console window and start the created script '''aloftd'''. You should see some output telling you which airport it is fetching data for.
 +
 +
[[Category:Howto|Fetch live aloft data]]
 +
[[Category:Weather]]

Latest revision as of 05:54, 16 March 2019

This howto describes how to setup live setting of wind aloft. This is the wind speed, direction and temperature for different altitudes. FlightGear's feature of setting current weather by using the --enable-real-weather-fetch uses METAR which only reports ground weather.

The aloft feature currently only works if you have a source distribution of FlightGear or the Git version since you have to apply a tiny patch to the sourcecode (just a single line). It only works if you have bash, awk, wget and netcat on your machine. This is usually the case if you are running linux and should be no sweat for OS/X but might require some setup if you have some less feature rich operating system.

Update 2019/01: It seems the Jeppesen service has been put behind a paywall. Can anyone confirm? (OO-ISA (talk))

General description

The wind aloft data is brought to you by the nice people of Jeppesen(R). Under http://www.jeppesen.com/weather a Text Weather service is provided free of charge. We use this service to fetch the aloft forecast and use these data as input for FlightGear.

When enabling the --real-weather-fetch option, FlightGear searches for the nearest airport to your present position that has a METAR service. If it finds one, it propagates the environmental settings and the station id of the airport the METAR was fetched for. A tiny add-on sends this station-id to a listening daemon program called aloftd.

The aloftd waits for input from FlightGear and interprets it as station ids. If the station id changes, it retrieves the aloft forecast from Jeppesen(R), parses the data, connects to the FlightGear telnet server and sets the aloft data in the property tree.

What to do

The Protocol Extension

First, we need to tell FlightGear how to broadcast the station ID of the actual METAR-station. Copy and paste the following code into a file named metarstationid.xml and save it to your data/Protocol directory.

<?xml version="1.0"?>
<PropertyList>
 <comment>
  <![CDATA[
    Usage: 
    fgfs --generic=socket,out,1,localhost,5500,udp,metarstationid
  ]]>
 </comment>
 <generic>
  <output>
   <line_separator>newline</line_separator>
   <var_separator>,</var_separator>
   <chunk>
    <name>metar-station-id</name>
    <format>%s</format>
    <type>string</type>
    <node>/environment/metar/station-id</node>
   </chunk>
  </output>
 </generic>
</PropertyList>

The FlightGear Patch

Unfortunately we have to patch FlightGear. The current implementation of FGMetarEnvironmentCtrl sets up the aloft data by just guessing some values and it does so after every reception of a new METAR. As a bad hack, just comment the line

fgSetupWind(dir_from, dir_to, speed, gust);

so it reads

// fgSetupWind(dir_from, dir_to, speed, gust);

in the file src/Environment/environment_ctrl.cxx. It should be around line 620. Perform a make for FlightGear.

EDIT: This is no longer needed if you use FlightGear Git. Just set the property

/environment/params/metar-updates-winds-aloft

to false. This can be done from the command line like

--prop://environment/params/metar-updates-winds-aloft=0

The aloftd

Copy and paste the following code to a file named aloftd:

 #!/bin/bash
 #KSFO FD DATA BASED ON 190600Z.
 #       3000    6000    9000   12000   15000   18000   21000   24000
 #18Z  1516P07 1723P03 1732M01 1738M06 1941M11 2045M16 2148M23 2151M30
 #00Z  1814P09 1819P02 1826M03 1932M08 2039M12 2246M16 2254M23 2161M30
 #06Z  1713P08 1915P02 2118M03 2223M09 2229M13 2236M18 2245M25 2253M32
 #12Z  1609P07 2011P03 2313M03 2420M08 2430M13 2441M19 2450M26 2458M33
 
 #set
 #/environment/config/aloft/entry[i]/elevation-ft
 #/environment/config/aloft/entry[i]/wind-from-heading-deg
 #/environment/config/aloft/entry[i]/wind-speed-kt
 #/environment/config/aloft/entry[i]/temperature-degc
 #
 #guess
 #/environment/config/aloft/entry[i]/dewpoint-degc
 
 LISTEN_PORT=5123
 TELNET_PORT=2323
 
 METAR_STATION_ID="XXXX"
 
 # FL060-390
 #WX_TYPE="fd"
 
 # FL030-240
 WX_TYPE="fdl"
 
 # FL120-500
 #WX_TYPE="fdh"
 
 URL="http://www.jetplan.com/jeppesen/weatherServlet?query=999&notamFilterName=&"
 
 netcat -u -l -p ${LISTEN_PORT} | \
 while read line; do
  if [ "$line" == "$METAR_STATION_ID" ]; then
    continue
  fi
  METAR_STATION_ID="$line"
 
  if [ "$METAR_STATION_ID" == "XXXX" ]; then
    continue
  fi
 
  echo "new ID: $METAR_STATION_ID" >&2
  echo "${URL}wxType=${WX_TYPE}&wxStation=${METAR_STATION_ID}" >&2
  wget --quiet --output-document=- "${URL}wxType=${WX_TYPE}&wxStation=${METAR_STATION_ID}" | awk '
    BEGIN {
      state=0;
      count=0;
      delete altitudes;
      printf( "data\r\n" );
    }
    /FD DATA BASED ON/ {
      state = 1;
      count = 0;
    }
 
    /^[0-9][0-9]Z/ {
      if( state == 1 )
        state = 2;
    }
 
    {
      if( state == 1 ) {
        if( count == 1 ) {
          for( i = 1; i <= NF; i++ ) {
            altitudes[i] = $i;
          }
        }
      }
      if( state == 2 ) {
        for( i = 2; i <= NF; i++ ) {
          altitude = altitudes[i-1];
          token = $i;
          wind_dir = substr( token, 1, 2 ) * 10;
          wind_speed = substr( token, 3, 2 );
          sign = substr( token, 5, 1 );
          temp = substr( token, 6, 2 );
          if( sign == "M" )
            temp = temp * -1;
          printf( "set /environment/config/aloft/entry[%d]/elevation-ft %d\r\n", i-2, altitude );
          printf( "set /environment/config/aloft/entry[%d]/wind-from-heading-deg %d\r\n", i-2, wind_dir );
          printf( "set /environment/config/aloft/entry[%d]/wind-speed-kt %d\r\n", i-2, wind_speed );
          printf( "set /environment/config/aloft/entry[%d]/temperature-degc %d\r\n", i-2, temp );
        }
        state = 3;
      }
      count++;
    }
    END {
     printf( "quit\r\n" );
    }
  ' | netcat localhost ${TELNET_PORT}
 done

Save the file to any location and make the file executable.

Running FlightGear

Now start your FlightGear with the following additional options:

--generic=socket,out,0.5,localhost,5123,udp,metarstationid --telnet=2323

Open another console window and start the created script aloftd. You should see some output telling you which airport it is fetching data for.