IF API connection tutorial

Hey everyone,

Lately I’ve had a few requests for help from developers trying to get a connection up and running with the IF local API.
This is exciting since it means more add-ons are on the horizon! :-)

Best thing is to examine and learn from Cam’s awesome open source LiveFlight Connect (that’s how I learned back when I first wrote the first prototype of In-Flight Assistant):

As you can see, you will want to open a socket to localhost, port 10111 (if you’re going to be on the same device).

The key method is this one:

    private void WriteObject<T>(T state)
    {
        var stateString = Serializer.SerializeJson(state);
        var data = UTF8Encoding.UTF8.GetBytes(stateString);
        byte[] size = BitConverter.GetBytes(data.Length);
        NetworkStream.Write(size, 0, size.Length);
        NetworkStream.Write(data, 0, data.Length);
    }

Note that you first need to send the LENGTH of the JSON’s content that you are trying to send. And THEN you send the JSON itself. The JSON depends on the command you are trying to send.

Note that you need to send the data in Little Endian format (the language you are writing in will have its own way of doing this). If you don’t know what that means, you’re perhaps not quite ready to be programming IF stuff yet (but maybe you can teach yourself!)…

Here’s the counterpart, the reading method:

    private string ReadCommand()
    {
        var sizeToRead = ReadInt();
        var buffer = new byte[sizeToRead];
        var offset = 0;

        while (sizeToRead != 0)
        {
            var read = NetworkStream.Read(buffer, offset, sizeToRead);
            offset += read;
            sizeToRead -= read;
        }

        string str = Encoding.UTF8.GetString(buffer);
        return str;
    }

Pretty much the same thing just the other way around. The data will be coming in and you will need to parse it.

Any questions? Post them in here, that way everyone can see the answers. 🙂

Yep, there is, send the command “ListCommands” and you get the following list back:

Full command list: 105 commands

help: Show the help
listcommands: Lists all commands
airplane.getstate: Retrieves the full airplane state
airplane.getenginesstate: Retrieves the full airplane engines state
airplane.getfuelstate: Retrieves the full airplane engines state
airplane.getinfo: Retrieves the full airplane info
airplane.getlightsstate: Retrieves the full airplane lights state
airplane.setlightsstate: Set lights statestate
camera.virtualcockpit.setviewangle: Set the camera view angle (Radians)
camera.virtualcockpit.resetviewangle: Disabled the view angle override
va: Set the camera view angle (Radians) (Shortcut)
rv: Disabled the view angle override (Shortcut)
autopilot.getstate: Retrieves the AP State
infiniteflight.getstatus: Get the status of the application
networkjoystick.setaxisvalue: Lists all commands
networkjoystick.setbuttonstate: Lists all commands
networkjoystick.setpovstate: Lists all commands
networkjoystick.setnetworkjoystickaxes: Sets all the flight control axes to \“Network Joystick\”.
live.getweather: Lists all commands
live.gettraffic: Lists all commands
live.atcfacilities: Lists all commands
live.getcurrentcomfrequencies: Lists all commands
live.tunetofrequency: Lists all commands
live.enableatcmessagelistupdated: Lists all commands
flightplan.get: Gets the Flight Plan Info
flightplan.load: Gets the Flight Plan Info
commands.elevatortrimup: Elevator Trim Up
commands.elevatortrimdown: Elevator Trim Down
commands.throttleupcommand: Throttle Up
commands.throttledowncommand: Throttle Down
commands.setcockpitcamera: Cockpit Camera
commands.setvirtualcockpitcameracommand: Virtual Cockpit Camera
commands.setfollowcameracommand: Follow Camera
commands.setflybycamera: Fly By Camera
commands.setonboardcameracommand: Onboard Camera
commands.settowercameracommand: Tower Camera
commands.nextcamera: Next Camera
commands.prevcamera: Previous Camera
commands.cameramoveleft: Move Camera Left
commands.cameramoveright: Move Camera Right
commands.cameramovedown: Move Camera Down
commands.cameramoveup: Move Camera Up
commands.cameramovehorizontal: Move Camera Left\/Right
commands.cameramovevertical: Move Camera Up\/Down
commands.camerazoomin: Zoom In
commands.camerazoomout: Zoom Out
commands.showatcwindowcommand: Toggle ATC Window
commands.atcentry1: Select ATC Entry 1
commands.atcentry2: Select ATC Entry 2
commands.atcentry3: Select ATC Entry 3
commands.atcentry4: Select ATC Entry 4
commands.atcentry5: Select ATC Entry 5
commands.atcentry6: Select ATC Entry 6
commands.atcentry7: Select ATC Entry 7
commands.atcentry8: Select ATC Entry 8
commands.atcentry9: Select ATC Entry 9
commands.atcentry10: Select ATC Entry 10
commands.live.setcomfrequencies: SetCOMFrequencies
commands.flightplan.addwaypoints:
commands.flightplan.clear:
commands.flightplan.activateleg:
commands.brakes: Brakes
commands.parkingbrakes: Parking Brakes
commands.flapsdown: Flaps Down (1 Step)
commands.flapsup: Flaps Up (1 Step)
commands.flapsfulldown: Flaps Down (Full)
commands.flapsfullup: Flaps Up (Full)
commands.aircraft.setflapstate:
commands.spoilers: Toggle Spoilers
commands.landinggear: Landing Gear
commands.pushback: Pushback
commands.fueldump: Fuel Dump
commands.reversethrust: ReverseThrust
commands.landinglights: Landing Lights
commands.taxilights: Taxi Lights
commands.strobelights: Strobes
commands.beaconlights: Beacon Lights
commands.navlights: Navigation Lights
commands.setlandinglightsstate:
commands.settaxilightsstate:
commands.setstrobelightsstate:
commands.setbeaconlightsstate:
commands.setnavlightsstate:
commands.autopilot.toggle: Engage\/Disengage Autopilot
commands.autopilot.setstate: SetState
commands.autopilot.setheading: SetHeading
commands.autopilot.setaltitude: SetAltitude
commands.autopilot.setvs: SetVS
commands.autopilot.setspeed: SetSpeed
commands.autopilot.setheadingstate: SetHeadingState
commands.autopilot.setaltitudestate: SetAltitudeState
commands.autopilot.setvsstate: SetVSState
commands.autopilot.setspeedstate: SetSpeedState
commands.autopilot.setapproachmodestate: SetApproachModeState
commands.togglehud: Toggle HUD
commands.togglepause: Pause
commands.start recording:
commands.stop recording:
commands.engine.start: Start Specified Engine
commands.engine.stop: Stop Specified Engine
a+: Increase altitude 1,000ft
a++: Increase altitude 10,000ft
recenter: Recenter World
fpl.add: Add Flight Plan Item
infiniteflight.state: Increase altitude 10,000ft

22 Likes

Uhh, what is Little Endian format?

That would take a while to explain, so best to read here:

https://betterexplained.com/articles/understanding-big-and-little-endian-byte-order/

2 Likes

Very handy!

I’ve bookmarked it ;)

What language is this C#, C++, etc?

1 Like

LiveFlight Connect is in C#.

1 Like

Nice. No wonder it looks familiar to me.

This is really cool! I don’t know much about C#, but I should learn more about it since IF is written in the language

Yep, there is, send the command “ListCommands” and you get the following list back:

Full command list: 105 commands

help: Show the help
listcommands: Lists all commands
airplane.getstate: Retrieves the full airplane state
airplane.getenginesstate: Retrieves the full airplane engines state
airplane.getfuelstate: Retrieves the full airplane engines state
airplane.getinfo: Retrieves the full airplane info
airplane.getlightsstate: Retrieves the full airplane lights state
airplane.setlightsstate: Set lights statestate
camera.virtualcockpit.setviewangle: Set the camera view angle (Radians)
camera.virtualcockpit.resetviewangle: Disabled the view angle override
va: Set the camera view angle (Radians) (Shortcut)
rv: Disabled the view angle override (Shortcut)
autopilot.getstate: Retrieves the AP State
infiniteflight.getstatus: Get the status of the application
networkjoystick.setaxisvalue: Lists all commands
networkjoystick.setbuttonstate: Lists all commands
networkjoystick.setpovstate: Lists all commands
networkjoystick.setnetworkjoystickaxes: Sets all the flight control axes to \“Network Joystick\”.
live.getweather: Lists all commands
live.gettraffic: Lists all commands
live.atcfacilities: Lists all commands
live.getcurrentcomfrequencies: Lists all commands
live.tunetofrequency: Lists all commands
live.enableatcmessagelistupdated: Lists all commands
flightplan.get: Gets the Flight Plan Info
flightplan.load: Gets the Flight Plan Info
commands.elevatortrimup: Elevator Trim Up
commands.elevatortrimdown: Elevator Trim Down
commands.throttleupcommand: Throttle Up
commands.throttledowncommand: Throttle Down
commands.setcockpitcamera: Cockpit Camera
commands.setvirtualcockpitcameracommand: Virtual Cockpit Camera
commands.setfollowcameracommand: Follow Camera
commands.setflybycamera: Fly By Camera
commands.setonboardcameracommand: Onboard Camera
commands.settowercameracommand: Tower Camera
commands.nextcamera: Next Camera
commands.prevcamera: Previous Camera
commands.cameramoveleft: Move Camera Left
commands.cameramoveright: Move Camera Right
commands.cameramovedown: Move Camera Down
commands.cameramoveup: Move Camera Up
commands.cameramovehorizontal: Move Camera Left\/Right
commands.cameramovevertical: Move Camera Up\/Down
commands.camerazoomin: Zoom In
commands.camerazoomout: Zoom Out
commands.showatcwindowcommand: Toggle ATC Window
commands.atcentry1: Select ATC Entry 1
commands.atcentry2: Select ATC Entry 2
commands.atcentry3: Select ATC Entry 3
commands.atcentry4: Select ATC Entry 4
commands.atcentry5: Select ATC Entry 5
commands.atcentry6: Select ATC Entry 6
commands.atcentry7: Select ATC Entry 7
commands.atcentry8: Select ATC Entry 8
commands.atcentry9: Select ATC Entry 9
commands.atcentry10: Select ATC Entry 10
commands.live.setcomfrequencies: SetCOMFrequencies
commands.flightplan.addwaypoints:
commands.flightplan.clear:
commands.flightplan.activateleg:
commands.brakes: Brakes
commands.parkingbrakes: Parking Brakes
commands.flapsdown: Flaps Down (1 Step)
commands.flapsup: Flaps Up (1 Step)
commands.flapsfulldown: Flaps Down (Full)
commands.flapsfullup: Flaps Up (Full)
commands.aircraft.setflapstate:
commands.spoilers: Toggle Spoilers
commands.landinggear: Landing Gear
commands.pushback: Pushback
commands.fueldump: Fuel Dump
commands.reversethrust: ReverseThrust
commands.landinglights: Landing Lights
commands.taxilights: Taxi Lights
commands.strobelights: Strobes
commands.beaconlights: Beacon Lights
commands.navlights: Navigation Lights
commands.setlandinglightsstate:
commands.settaxilightsstate:
commands.setstrobelightsstate:
commands.setbeaconlightsstate:
commands.setnavlightsstate:
commands.autopilot.toggle: Engage\/Disengage Autopilot
commands.autopilot.setstate: SetState
commands.autopilot.setheading: SetHeading
commands.autopilot.setaltitude: SetAltitude
commands.autopilot.setvs: SetVS
commands.autopilot.setspeed: SetSpeed
commands.autopilot.setheadingstate: SetHeadingState
commands.autopilot.setaltitudestate: SetAltitudeState
commands.autopilot.setvsstate: SetVSState
commands.autopilot.setspeedstate: SetSpeedState
commands.autopilot.setapproachmodestate: SetApproachModeState
commands.togglehud: Toggle HUD
commands.togglepause: Pause
commands.start recording:
commands.stop recording:
commands.engine.start: Start Specified Engine
commands.engine.stop: Stop Specified Engine
a+: Increase altitude 1,000ft
a++: Increase altitude 10,000ft
recenter: Recenter World
fpl.add: Add Flight Plan Item
infiniteflight.state: Increase altitude 10,000ft

2 Likes

I’m able to connect to IF Connect and sending commands to them using Camerons source code. Commands like other camera, engine start/stop works fine. But get stuck when comes to receiving data. (Receiving the IP Adress and port works). Can somebody help me out with it? Swift/Objective-C.

3 Likes

This simply uses the API of the ifc.js library which I don’t know and have never used before so it seems like @nicolas would be the one to ask. Is he using those methods right?

1 Like

Not sure. Would you be able to provide a working (able to run commands) out-of-the-box Node JS sample?

Nope, since I’ve only ever dabbled in Node.js…perhaps @Nicolas?

1 Like

He’s not very active on here, but I’ll try asking him on GitHub. Is there another language that supports PC that you could provide a sample in?

Best example (which was extremely helpful when I was just getting started) is Cam’s own LiveFlight Connect, which uses C# and he graciously open-sourced. https://github.com/LiveFlightApp/Connect-Windows

1 Like

Is there a convenient way to see the arguments/parameters required for these commands? Some are toggles, but others, like commands.flightplan.activateleg: look like they would need specific data, in this case a waypoint name (I think).

I can see that this thread has been dormant but it sees the most relevant thread to ask my question.

I’m experimenting with the Connect API for a project I’m working on and while I can see commands like airplane.getState clearly are intended to return data, it is unclear if any of the set/toggle/action commands are intended to return any response such as verifying the action has occurred or that a level/value has changed on a control.

Is there any reference of the parameters each command expects and the expected responses (if any) that the API will return per command?

Thanks.

This API command list shows that it’s not sufficient for us to write a good third-party program, as there are lacking of states of certain instruments and many basic information of the aircraft as well as plane condition. Is there any update schedule of the API soon?

1 Like

Check out the #thirdparty:api category, there’s information on v2 of the api there

Already tried them out. Too limited!