Calling C/C++ functions from custom node

Hi All,

I created a set of custom nodes for energenie devices a few months ago. The node uses functions written in C to interact with an energenie raspberry pi 433Mhz radio device.

It currently uses the node ffi and ref libraries to interact with the C routines, but I get quite a few deprecation errors from these libraries and it appears that they are no longer being maintained.

Does anyone have any recommended alternative ways of calling C functions from my custom node javascript code?

I don't have the expertise myself but I believe the following is the standard method:

https://nodejs.org/api/addons.html

1 Like

After doing a bit more research on the subject I'm going to try to use N-API as it will ensure ABI stability across different versions of node.

1 Like

I have accomplished within QT creator project setup ( utilizing CMAKE-JS) to generate (bindings-gyp) NAPI with addon-api (C++ wrapping) nodes. Now im stuck in understading how I can embed/extend this into a Node-Red custom node ? Whats the best way to go from here ?? Having the .node module file and the *.js file to test it via the appropriate javascript code

I've done this in my node-red module, you just need to 'require' it in node-red to use the function. The code for N-API calls is done, but I'm still testing some radio timing issues as I also decided to add support for radiator valves, so have yet to release it for general consumption.

You will need to follow the guides on creating custom nodes, or you could take a look at my 'develop' branch: https://github.com/Achronite/node-red-contrib-energenie-ener314rt/tree/develop/red. The simplest one to follow would be the ener314rt-raw.js / .html files.

1 Like