I have made two libraries with two diferent approaches to get data from X Plane.
Both libraries are used in the same way, with slightly diferent parameters.
#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); }
#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(); }