flightgear_python.fg_if.HTTPConnection

class flightgear_python.fg_if.HTTPConnection(host, tcp_port, timeout_s=2.0)

Bases: PropsConnectionBase

FlightGear HTTP Interface Connection (also known as the property interface). See https://wiki.flightgear.org/Property_Tree_Servers for general details.

Parameters:
  • host (str) – IP address of FG (usually localhost)

  • tcp_port (int) – Port of the telnet socket (i.e. the 5050 from --httpd=5050)

  • timeout_s (float) – Optional timeout value in seconds for the HTTP connection

__init__(host, tcp_port, timeout_s=2.0)
Parameters:
  • host (str) –

  • tcp_port (int) –

  • timeout_s (float) –

Methods

get_prop(prop_str)

Get a property from FlightGear.

list_props([path, recurse_limit])

List properties in the FlightGear property tree.

set_prop(prop_str, value)

Set a property in FlightGear.

get_prop(prop_str)

Get a property from FlightGear.

Parameters:

prop_str (str) – Location of the property, should always be relative to the root (/)

Returns:

The value of the property. If FG tells us what the type is we will pre-convert it (i.e. make an int from a string)

Return type:

Any

list_props(path='/', recurse_limit=0)

List properties in the FlightGear property tree.

Parameters:
  • path (str) – Directory to list from, should always be relative to the root (/)

  • recurse_limit (int | None) – How many times to recurse into subdirectories. 1 (default) is no recursion, 2 is 1 level deep, etc. Passing in None disables the recursion limit. Be warned that enabling any kind of recursion will take a long time!

Returns:

Dictionary with keys:

  • directories: List of directories, absolute path

  • properties: Dictionary with property name as the key (absolute path), value as their value.

Return type:

Dict[str, list | Dict]

Example for list_props('/position', recurse_limit=0):

{
    'directories': [
        '/position/model'
    ],
    'properties': {
        '/position/altitude-agl-ft': 3.148566963,
        '/position/altitude-agl-m': 0.9596832103,
        '/position/altitude-ft': 3491.986254,
        '/position/ground-elev-ft': 3488.469757,
        '/position/ground-elev-m': 1063.285582,
        '/position/latitude-deg': 0.104476136,
        '/position/latitude-string': '0*06\'16.1"N',
        '/position/longitude-deg': 100.023135,
        '/position/longitude-string': '100*01\'23.3"E',
        '/position/sea-level-radius-ft': 20925646.09
    }
}
set_prop(prop_str, value)

Set a property in FlightGear.

Parameters:
  • prop_str (str) – Location of the property, should always be relative to the root (/)

  • value (Any) – Value to set the property to. Must be convertible to str