Node-RED Plumbing

1.0 Raspberry Pi Node-RED 4.0

Obsolete content

This content was created for an older version and is outdated. Check version 2 for an up-to-date description!

I was looking for a simple way to get data from Elite Dangerous forwarded to my cockpit but all the programs I found online are closed source solutions that have to be bought and are – as usual – Windows only. Best it would get is Android support and requires a tablet with touch functions. Nothing of this I want! The idea is to use something system agnostic that can be adjusted easily, because I want to use this for different games and not depend on a single vendor, hoping support will last and the thing work with my setup [in the future].

Using Node-RED to get status information

This was when I remembered Node-RED from usage in home automation because this is basically the same. You get a zoo of hardware, that somehow all interacts with a dashboard. All the data is on the wire and can be accessed via a web-browser. Fun enough I wasn’t the first with this idea because when I started searching for “Node-RED for simpit usage” I stumbled over the YouTube channel of Jon Back who did exactly this before (and even also used cardboard for prototyping). Encouraging and big shout out for the pioneer work!

So after installing Node-RED on my Linux PC and on my Raspberry Pi I connected the two installations via Websockets. That’s basically just entering an IP. While using MQTT is probably a better solution that I may evaluate in the future this was the easiest one because it doesn’t need an additional service.

Why I installed it twice? Well Elite drops a lot of the current game status in various JSON files, like a timestamped Journal and a Status file that holds most of the ship data I’m interested in most. The file is updated on changes and it’s easy to watch for such a change on a local filesystem. I also intend to make the receiving side as dumb as possible so I don’t have to update the code too often. I’m still uncertain what I’ll use in the end – an Arduino is also in consideration. This way I can hopefully connect other games easily as well by keeping the resulting data structure more universal and let the sender to the hard work of hammering the data into shape.

The sender flow

Image of a simple Node-RED flow sender side
Image of a simple Node-RED flow sender side

Short explanation what’s going on: File Changes listens for changes in my ED folder where the JSON files are located. Switches check for the file name forward it to a file opener. This one reads the file (Journal line by line) and passes the data to a JSON parser. This one forwards the parsed JSON data to a function that creates the desired data structures. Finally it is send to the receiver.

Parsing the Elite Dangerous Status flags

Most of the magic for Elite Dangerous happens in the function that parses the Status.json file, which is explained in detail at https://elite-journal.readthedocs.io/en/latest/Status%20File

flags = msg.payload.Flags;
// https://elite-journal.readthedocs.io/en/latest/Status%20File/
[
    "DockedOnPad", 
    "LandedOnSurface", 
    "LandingGearDown",
    "ShieldsUp",
    "Supercruise",
    "FlightAssistOff",
    "HardpointsDeployed",
    "InWing",
    "LightsOn",
    "CargoScoopDeployed",
    "SilentRunning",
    "ScoopingFuel",
    "SrvHandbrake",
    "SrvusingTurretview",
    "SrvTurretRetracted",
    "SrvDriveAssist",
    "FsdMassLocked",
    "FsdCharging",
    "FsdCooldown",
    "LowFuel",
    "OverHeating",
    "HasLatLong",
    "IsInDanger",
    "BeingInterdicted",
    "InMainShip",
    "InFighter",
    "InSRV",
    "HudinAnalysismode",
    "NightVision",
    "AltitudefromAverageradius",
    "fsdJump",
    "srvHighBeam",
].forEach((value, key) => {
   msg.payload[value] = flags & 1;
   flags = flags >> 1;
});
return msg;

The receiver flow

The receiving Node-RED process on the Raspberry Pi does something similar.

Image of a simple Node-RED flow receiver side
Image of a simple Node-RED flow receiver side

The received data is once more parsed as JSON and checked based on the event string what type of message it got. If a status event is found it’s forwarded as 0 or 1 to a GPIO where a LED will be enabled or disabled. See the short demo video of the Primary Buffer Panel in action:

Watch this video on BekoPharm

Conclusion

This is a proof of concept that uses only a tiny bit of the available information to drive some LED I have on my custom GPIO breakout board. Later I ordered a Neopixel, a LED strip with WS2811 modules, and rewrote the receiving part.

More on this under blinken lights.