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 "Property Tree/Web Server"

From FlightGear wiki
Jump to: navigation, search
(Links)
m (moved to Telnet usage)
Line 15: Line 15:
 
You can now browse the entire FG property tree "live" as the sim is running. You need to refresh the browser to see changes and you can even change values if you like. You can configure autopilot modes and even set control inputs so you could literally fly the airplane from your web browser, although it's maybe not the most convenient interface for doing that. ;-)
 
You can now browse the entire FG property tree "live" as the sim is running. You need to refresh the browser to see changes and you can even change values if you like. You can configure autopilot modes and even set control inputs so you could literally fly the airplane from your web browser, although it's maybe not the most convenient interface for doing that. ;-)
  
== Telnet Server ==
 
FlightGear has a telnet server that can be used to read and set values of the [[PropertyTree]]. The telnet server is activated with the '''--telnet=port''' [[Command Line Parameters|command line option]], where port is the number of the listening port that will be opened.
 
 
A connection to the server can be done using a [[Telnet usage|telnet client]] or opening a simple socket from any program. Multiple connections (more below) are possible at the same time. Too start FG and open the port 5401 as available telnet server use this command:
 
fgfs --telnet=5401
 
Using this server protocol is covered in detail on the [[Telnet usage]] page.
 
 
== Manipulate Properties ==
 
The cool thing is that you can easily write scripts to access the --telnet=<port#> interface.
 
//* psuedo code
 
conn = telnet.connect(127.0.0.1, 5480)
 
gear_down = conn.get("/gear/state")
 
if gear_down:
 
  conn.set("/gear/state", "up")
 
 
Some links to source code examples in various flavours:
 
* Perl - [http://gitorious.org/fg/flightgear/trees/next/scripts/perl/examples /source/scripts/perl/examples].
 
* Python - [http://gitorious.org/fg/flightgear/trees/next/scripts/python /source/scripts/python/]
 
* Java - [http://gitorious.org/fg/flightgear/trees/next/scripts/java source/scripts/java/]
 
 
You could just as easily interact with a running FlightGear instance using perl, C, C++, java, python, probably even <ack> visual basic or anything else that can do TCP/IP network communication ... matlab? netcat? twisted?
 
 
Also note that the downside to the telnet interface is that you can't blast a lot of data across it. It's fine if you want to monitor location and speed every second or 1/4 second and occasionally set some values; such as dump in a new weather configuration, reset the aircraft location, or read a set of values, etc.
 
 
If you need to track 100 different variables at 60hz, this isn't the interface for you.
 
For that you need a '''[[PropertyTree:Sockets|socket]]'''.
 
 
== Multi Servers ==
 
Note that you can setup as many of these servers as you want, for instance, just to be obscene you could do:
 
fgfs --httpd=5400 --httpd=5401 --httpd=5402 --telnet=5403 --telnet=5404 --telnet=5405
 
 
Now there are six network interfaces running that you can access from anywhere ;-) >> can I borrow your ipod please. why ?
 
 
==== Links ====
 
* httpd source - [http://gitorious.org/fg/flightgear/blobs/next/src/Network/httpd.cxx source/src/Network/httpd.cxx]
 
* telnet (props) source - [http://gitorious.org/fg/flightgear/blobs/next/src/Network/props.cxx source/src/Network/props.cxx]
 
  
 
[[Category:Property Tree]]
 
[[Category:Property Tree]]

Revision as of 13:22, 26 March 2013

FlightGear has a few network access protocols. These are started as a command line option.

Web Server

To view the PropertyTree with a web browser, start FlightGear with the following option:

fgfs --httpd=5480

where 5480 is the port number. You can pick any port number, but 5480 will probably work just fine.

On the same machine, fire up a web browser and open up the following url:

http://localhost:5480/

You can now browse the entire FG property tree "live" as the sim is running. You need to refresh the browser to see changes and you can even change values if you like. You can configure autopilot modes and even set control inputs so you could literally fly the airplane from your web browser, although it's maybe not the most convenient interface for doing that. ;-)