Deprecation Notice - This repository is archived in favor of https://github.com/fsmosquito/fsmosquito which includes all the functionality contained in this repository (within /fsmosquito-simconnect-client) with the addition of a desktop application that displays a moving map and eventually more.
Client application that connects to FS2020 via SimConnect and relays data to the FSMosquito Server via MQTT
Prerequisites (For just the client):
Pretty straight forward, this is a .Net Core 3.1 application using Windows Forms.
The necessary FS2020 SDK files are included in the /lib folder (these will probably need to be updated over time as FS2020 is updated)
I'm using VS2019 for development, but there shouldn't be anything that prevents VSCode from being the IDE of choice during the development process except for it's annoyances with C#. Maybe JetBrains Rider is a good alternative that doesn't require a full VS2019 license.
With VS2019, just open the .sln file and run.
There are four main classes involved:
MainForm - Provides a minimalistic UI - and importantly a WinHandle that SimConnect posts messages to.
How SimConnect works is that it uses Windows Procedures to communicate with applications out-of-process
Within the SimConnect constructor, one passes the handle of the window that should be notified by FS2020 when a message is available.
This mechanism happens within Forms/MainForm.cs class with the WndProc override.
When that message is recieved by the MainForm, it raises an event which is handled by the SimConnectMqttAdapter which then requests the actual data associated with the message from SimConnect.
The adapter then then serializes this data into a MQTT message and publishes it to the broker.
The metrics that are transmitted are very much like individual data points that an IoT device would be relaying to an IoT edge server which can be analyzed. In FSMosquito's case this data is subscribed by various server components which notify the web client of position updates and react to events such as taking off and landing at airports.
SimConnect requires a client app to register 'subscriptions' to various events that occur in FS2020 prior to having those events be raised by the instance of a SimConnect class. The FSMosquitoClient doesn't statically register these events, but subscribes to requests for registration events coming from the MQTT broker (FSMosquitoServer) and then correspondingly registers the event with SimConnect.
This allows for the data points that are utilized by the FSMosquitoServer to change and grow over time. Effectively, the FSMosquitoClient is just a "dumb pipe" that facilitates communication between FS2020 and the FSMosquitoServer.
The client currently also accepts SimVars to be set via MQTT messages as well, this opens up some interesting possibilities for automation.
TODO: System variables, invoking various SimConnect functions
While by default the client is configured to use FSMosquito's hosted broker, the client can be pointed at any MQTT Broker that supports web sockets. Simply change the connection string in appconfig.json to point to your own MQTT broker
Some available MQTT Brokers:
Currently the FSMosquitoClient creates log files located in the ./logs folder relative to where the FSMosquitoClient.exe is located.
This project contains a publishing profile that will bundle the application (including all .net dependencies) into a single file.
Press the 'Publish' button. A new single-file build will be located in $(ProjectLocation)\bin\x64\Release\netcoreapp3.1\win-x64\publish
A GitHub action is included that will automatically build and publish new releases to GitHub
git tag -a v0.2.0-alpha01 -m "Release Description" && git push --tags
) Builds the project and creates a release that corresponds to the tag.