To be completed!

I have made two libraries with two diferent approaches to get data from X Plane.

  1. Using UDP-client.
    The module uses data broadcasted from X Plane via UDP.
    By defining a field with page and idex in the list of Data Refs, the librafy will enable broadcast of the required page.
  2. Using an available plugin (ExtPlane) and connecting as a TCP client.
    By defining a field, giving the Dref for that field, the Dref and the value will be send to the client.

Common:

Both libraries are used in the same way, with slightly diferent parameters.

  1. Define field objects
  2. Define communication object
  3. in setup()
    1. define field callback for 'onUpdate'
    2. start communication objedt
  4. in Loop()
    1. Scan communication for changes to field objects

UDP client:

#include "xplane.h"

#define hostIP 192,168,1,5
#define rxPort 49000
#define txPort 49003

IPAddress xPlane(hostIP);
XPLANE xplane(rxPort, txPort, xPlane);

FIELD GpsLat(20, 0, 10000); //  set precission to 4 decimals
FIELD GpsLon(20, 1, 10000); //  set precission to 4 decimals

void setup() {
  Serial.begin(115200);
  initWiFi(ssid, password);
  GpsLat.onUpdate([]() {
    Serial.println("GpsLat: " + String(GpsLat.value, 5));
  });
  GpsLon.onUpdate([]() {
    Serial.println("GpsLon: " + String(GpsLon.value, 5));
  });
  xplane.begin(10);
}

void loop() {
  xplane.scan();
  delay(1);
}

Pro:

Contra:

ExtPlane plugin:

#include "extplane.h"
#define hostIP 192,168,1,5
#define port 51000

IPAddress xPlane(hostIP);
EXTPLANE xplane(xPlane, port);

FIELD GpsLat("sub", "sim/flightmodel/position/latitude");
FIELD GpsLon("sub", "sim/flightmodel/position/longitude");


void handledata(String id, String dref, float data) {
  if (id == "EXTPLANE") xplane.config();
}

void setup() {
  xplane.on(handledata);
  GpsLat.onUpdate([]() {
    Serial.println("Latitude: " + String(GpsLat.value, 8));
  });
  GpsLon.onUpdate([]() {
    Serial.println("Longitude: " + String(GpsLon.value, 8));
  });
  xplane.begin();
}

void loop() {
  xplane.scan();
}

	

Pro:

Contra:

Downloads: