Reading EFI Engine Data with Lua Script

I am trying to get an EFI engine to send data (like RPM and CHT) to my flight controller. The engine will output the data via RS232 and CAN, though CAN is the only port I have available. I was able to get data to be displayed in the messages box by using the CAN_read.lua script available on the Ardupilot github page and get the following example output:

“9/11/2024 4:11:05 PM : CAN[1] msg from 2290155520: 58, 0, 0, 221, 0, 0, 199”

There are a total of 11 unique frame ID’s, each containing different information. This message, for example, contains the CHT in 0.1 degrees C at index 3 (22.1C). I am trying to write a lua script that is based on the CAN_read.lua script that will pull the value of a specific index of a specific frame ID and print that in a more consumable manner for an operator (i.e. “The CHT is 22.1 degrees C”). I have run into trouble trying to do so. I have attached the script that I have been using, but get no output. I have verified that the “if” statements within the update function are working properly by printing “hello world” inside of the nested if. I have also tried putting the “if frame:id() == XXX” in the update function rather than in the data specific function and I instead get an error that says “trying to index nil variable (global “frame”)”

This is an Edge Autonomy (previously UAV Factory) EFI engine, so there is no prebaked scripts out there that I have found. Any insights are much appreciated!

CAN_read_tester.lua (2.3 KB)

UPDATE: there was a type mismatch error with the output frame ID being “userdata” and trying to compare that with “number” was not working. This issue is solved.