Jump to content
The simFlight Network Forums

Interfacing to ForeFlight Mobile


Recommended Posts

Foreflight recently announced a new feature enabling flight sims to drive their latest ForeFlight Mobile™ app over a local netwwork as if the sim were an external GPS.


I've enjoyed using Foreflight's app for years and I'm very impressed they would release this detailed, and admittedly nerdy, feature.

So, using their new interface along with Pete's Lua suggestion earlier in this thread I've created a small Lua program to drive Foreflight running on an iPAD over your local network.

This script works well during my limited testing, but of course, use at your own risk.

I'm attaching my Lua file and copying the source here for your reference.

You will need to update the ip address below to point to your iPad.

(I'm sure this could be enhanced to use a broadcast packet to eliminate the IP requirement if one desired)

A good tutorial on installing and executing a Lua module can be found here: http://www.anadrac.c...cuting Code.htm

-- This Lua script polls FSX once per second for lat/lon, altitude, ground-speed and ground-track
-- This info forms the datagram for a UDP packet which is broadcast over the local network
-- to directly drive the popular Foreflight Mobile(tm) iPad application.
-- This is possible only due to Foreflight's recent, and welcomed, addition of flight simulator support.
-- Annoucement found here: http://www.foreflight.com/support/network-gps
-- Appears to work great on my machine, but use at your own risk.

socket = require("socket");

-- This port was designated by Foreflight
local port = "49002";

-- Insert your iPad IP address here
local ip = "xxx.xxx.xxx.xxx";

local udp = assert(socket.udp());

function getvars(time)
local lat = ipc.readDBL(0x6010);
local lon = ipc.readDBL(0x6018);
local alt = ipc.readDBL(0x6020);
local gs = ipc.readDBL(0x6030);
local trutrack = math.deg(ipc.readDBL(0x6040) + ipc.readDBL(0x6028));
local datagram = string.format("%s, %0.3f, %0.3f, %0.1f, %0.3f, %0.1f","XGPSMySim",lon,lat,alt,trutrack,gs);

-- print("Sending datagram " .. datagram .. " to " .. ip .. ", " .. port .." ");
assert(udp:sendto(datagram, ip, port));

-- Call getvars once per second
event.timer(1000, "getvars");



Link to comment
Share on other sites

this is an advertisement?

Doesn't look like it to me, just a free user contribution of a Lua program to provide an interface to a commercial program. Probably it should be in the User Contributions subforum, like the Lua additions for other commercial programs like PMDG and iFly aircraft.

I had a look at Foreflight Mobile, which is okay for USA fliers, maybe Canada as well, but provides virtually nothing for the rest of the world. And requiring a regular subscription is a bit of a killer. I expect it appeals to real GA pilots in the USA.



Link to comment
Share on other sites

That's correct Pete.

I'm not associated with Foreflight in any way, but I do use their app in my daily RW flying for their geo-referenced approach charts and as a backup moving map.

I use FSX primarily to keep the rust off the procedural aspects of my instrument "skills", so the closer I can keep my sim flows to the real thing the better.

FSUIPC plus Lua is powerful - thanks for the contribution and feel free to move my post wherever you see fit.



Link to comment
Share on other sites

Hi Joshua,

Thanks for the Lua file, but I can't get it to work. Xplane works fine with my Foreflight. I have tried some sample Lua scripts with FSX and they also work. I added my Ipad's ip in your Lua script. Should I see my FSX computer ip in Foreflight Devices tap like Xplane? Do I need a special program on my Ipad that communicates with your script? Is GPSout.dll required? What am I missing?


Link to comment
Share on other sites

  • 2 weeks later...

Hi Martin -

Sounds like you're doing everything I'm doing and I don't think GPSout.dll is required.

Some basic sanity checks:

  • Make sure you can ping your iPad's IP address from your PC to confirm basic network connectivity (pretty much confirmed via Xplane, but check anyway).
  • Enable Lua logging by selecting Add-ons -> FSUIPC -> Logging and checking "Debug/Trace Lua plugins" and "Send to console window" from within FSX.
  • Uncomment the debug print statement near the bottom of the Lua file to print the datagram, ip address and port.
  • Start a flight in an area covered by Foreflight then Launch the Lua script.
  • Reduce the size of your sim window so you can see the console window.

Confirm via the console windows that the Lua script launches, the datagrams looks reasonable and that the IP address is correct.

You should see a datagram being broadcast once per second and a 'MySim' GPS source listed on Foreflight's More->Devices page within 5 seconds of launching the Lua script.

Hope that helps,


Link to comment
Share on other sites

  • 2 weeks later...

I have FSUIPC (registered!) properly installed in FSX. I created the Lua file and inserted my iPad IP address. I named it "ipcinit.lua" and put it in the Program Files (x86) \ Microsoft Games \ Microsoft Flight Simulator X folder (guessing obviously...). Not working.

What do I need to do to execute the Lua file automatically? The link above on Lua modules was helpful but I couldn't crack the code.

Thanks in advance!


Link to comment
Share on other sites

Ok, not that hard after you find and read the FSUIPC Manual. For others: I renamed the Lua file to "XGPSMySim" (it could be any name) and put it in the Modules folder. Then I edited the FSUIPC INI to add


1=Lua XGPSMySim

Works great.



Link to comment
Share on other sites


Thanks for posting the Lua, I love the new capability.

Quick question: if I change

event.timer(1000, "getvars");


event.timer(500, "getvars");

Does that have the effect of getting the GPS data twice a second? Will that smooth the flight path on the Foreflight displays a bit? Any bad impacts? I assume calling too often could impact FSX performance.



Link to comment
Share on other sites

I assume calling too often could impact FSX performance.

It won't hurt to try smaller values. There'll come a point where the graphics redraw on the target will limit it, or you'll notice some impact on the FS PC -- though the latter is actually less likely, as it is all happening in separate threads.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.