You don't need a plugin to get data out of X-Plane 12. It listens on UDP port 49000, and if you ask nicely it'll stream any dataref back to you. The Hangar Addons Telemetry app reads X-Plane this way, which means it can run on a second computer too.
How the request works
You send one small packet for each value you want. It holds the text RREF and a zero byte, then how many times a second you want it, a number you pick to identify it, and the dataref's name padded to 400 bytes. X-Plane replies to the port you sent from with pairs of your number and a decimal value.
The script
You need Node and nothing else. Save this as telemetry.mjs.
import dgram from "node:dgram";
const sim = { host: process.argv[2] ?? "127.0.0.1", port: 49000 };
const datarefs = [
["lat", "sim/flightmodel/position/latitude"],
["lon", "sim/flightmodel/position/longitude"],
["altM", "sim/flightmodel/position/elevation"],
["ias", "sim/flightmodel/position/indicated_airspeed"],
["gsMs", "sim/flightmodel/position/groundspeed"],
["vs", "sim/flightmodel/position/vh_ind_fpm"],
["hdg", "sim/flightmodel/position/psi"],
["ground", "sim/flightmodel/failures/onground_any"]
];
const socket = dgram.createSocket("udp4");
const values = {};
function subscribe(frequency) {
datarefs.forEach(([, path], index) => {
const packet = Buffer.alloc(413);
packet.write("RREF\0", 0, "ascii");
packet.writeInt32LE(frequency, 5);
packet.writeInt32LE(index, 9);
packet.write(path, 13, "ascii");
socket.send(packet, sim.port, sim.host);
});
}
socket.on("message", (message) => {
if (message.toString("ascii", 0, 4) !== "RREF") {
return;
}
for (let offset = 5; offset + 8 <= message.length; offset += 8) {
const entry = datarefs[message.readInt32LE(offset)];
if (entry) {
values[entry[0]] = message.readFloatLE(offset + 4);
}
}
});
socket.bind(() => subscribe(5));
setInterval(() => {
if (values.lat === undefined) {
console.log("Nothing from X-Plane yet.");
subscribe(5);
return;
}
const { lat, lon, altM, ias, gsMs, vs, hdg, ground } = values;
console.log(
`${lat.toFixed(5)}, ${lon.toFixed(5)} ${Math.round(altM * 3.28084)} ft ${Math.round(ias)} kt IAS ` +
`${Math.round(gsMs * 1.94384)} kt GS ${Math.round(vs)} fpm hdg ${Math.round(hdg)} ${ground > 0 ? "ground" : "air"}`
);
}, 1000);
process.on("SIGINT", () => {
subscribe(0);
setTimeout(() => process.exit(0), 200);
});
