Board index FlightGear Development

Help coding with the HTTP server

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Help coding with the HTTP server

Postby Algernon » Fri Feb 07, 2020 7:28 pm

Hi all,

I've read the most easily-findable documentation on using the HTTP server but I'm still not sure where to start with a project. Maybe someone could help me out with some suggestions?

Basically, I'd like to be able to control certain aspects of the FG Video Assistant from a web page rather than using dialogs in the sim. To begin with, and as a learning experience, I'm going to focus on one particular function - having a list of the current MP pilots appear in an HTML page, where each callsign is a link and clicking that link changes the selected pilot in the video assistant's camera system. I'm pretty sure changing the selected pilot is as simple as changing a string property, which I know can be done via HTTP. I suspect it's not a tricky thing to do, and perhaps I can figure most of it out by looking at the source code from web pages provided by the FG HTTP server, but I thought it would be worth asking before I start in case anybody had good ideas about the best way to go about it.

Any suggestions would be much appreciated!
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
Developer: Eurofighter EF2000 - English Electric Lightning - Handley Page Victor
User avatar
Algernon
 
Posts: 507
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 2019.1.1
OS: Win10

Re: Help coding with the HTTP server

Postby Hooray » Sat Feb 08, 2020 6:24 am

Indeed, that should be a fairly good start and simple thing to toy with.

Basically, without providing the solution, I would approach the task like this:

  • open the PUI dialog where you can switch views
  • look up the bindings to see what properties are accessed/manipulated
  • next open the property browser to make sure that your findings are correct, i.e. try to manipulate views via the property browser


Once that works, you now how to cycle views - the next step is trying to do that remotely, so instead of using the property browser, you could use the props/telnet protocol.

Afterwards, I would fire up httpd/Phi and look at the property tree API there, I believe there is a dedicated "props" module - you will want to repeat the experiment to see if you can change properties via Phi. Once that works, you could use a tiny piece of JavaScript code to cycle views using two buttons.

The next step would probably be reviewing the property tree structure to see how to obtain a list of all views, so that you can query fgfs and extract that list to create a table with views, with one button per row.

If you haven't done anything like that before, you could obviously also look at Phi to find any related functionality, and then review the JavaScript code there to see how it's done, to extract and generalize the useful bits.

That being said, you could also implement most of this fgfs side by registering a new fgcommand (binding), say something like "getViewList()" via the addcommand() API and then call that via AJAX/JSON over httpd/mongoose - that way, you can continue to use Nasal, and only need to call your new fgcommand. If this had been done earlier, our dialogs would be much less of a pain to parse for 3rd party UI efforts like the Qt5/QQ2 GUI port - i.e. registering Nasal related functionality as dedicated fgcommands, so that regardless of the front-end, all it needs to do is call bindings instead of knowing about Nasal.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11891
Joined: Tue Mar 25, 2008 8:40 am

Re: Help coding with the HTTP server

Postby Algernon » Sun Feb 09, 2020 8:29 am

Fantastic, thanks - I'll give it a go over the next few days and see what I can come up with.
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
Developer: Eurofighter EF2000 - English Electric Lightning - Handley Page Victor
User avatar
Algernon
 
Posts: 507
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 2019.1.1
OS: Win10

Re: Help coding with the HTTP server

Postby Hooray » Mon Feb 10, 2020 5:34 am

See the Phi folder in fgdata: https://sourceforge.net/p/flightgear/fg ... e/Phi/lib/

Specifically:
https://sourceforge.net/p/flightgear/fg ... ib/fgfs.js
https://sourceforge.net/p/flightgear/fg ... command.js
https://sourceforge.net/p/flightgear/fg ... b/props.js
https://sourceforge.net/p/flightgear/fg ... /props2.js


I think there will be more people interested in doing similar things, so it would be a cool idea to turn the whole thing into a tutorial for the wiki, including setup instructions and screen shots to illustrate how to configure FlightGear so that it can receive instructions over http, and how to tell what properties are relevant, confirming those via the property browser/telnet and then take it from there by using tiny pieces of JavaScript to set access/modify properties in FlightGear, with the property browser open to confirm that your javascript code is working.

I once wrote a similar "howto" predating the mongoose/Phi days, showing how to do the opposite, i.e. making AJAX calls over http using fgcommands via Nasal: http://wiki.flightgear.org/Howto:Making ... from_Nasal

I believe these days, there are better ways (dedicated http bindings), but still this kind of tutorial could be useful to illustrate to people how to extend FlightGear by writing JavaScript code, and who knows, maybe this could even become the foundation for some kind of Phi-related "plugin" framework
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11891
Joined: Tue Mar 25, 2008 8:40 am

Re: Help coding with the HTTP server

Postby geed » Fri Apr 03, 2020 10:11 pm

Do you have any info on dedicated http bindings? I would like to have a look at that :)
geed
 
Posts: 86
Joined: Fri Apr 18, 2014 12:53 pm
Location: in between
Callsign: G-EED
Version: 2017.3.1
OS: OSX, Win8.1

Re: Help coding with the HTTP server

Postby Hooray » Sat Apr 04, 2020 8:45 am

Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11891
Joined: Tue Mar 25, 2008 8:40 am


Return to Development

Who is online

Users browsing this forum: No registered users and 0 guests