Call C++ from Node-Red, suggestion for examples ? :)

Hi guys,
I see that many node developers calls Python from Node-Red.
But JavaScript has the possibilities to call C++ functions directly.
Some parts of JavaScript are written in C++.
This has advantages and disadvantages for node developer.
But if you familiar with C++, this make easy to write binary nodes that calls from JavaScript (Node-Red).
All my nodes are witten with this technique for the raspberry pi.
I plan to write a short instructions how you write code in C++ for Node-Red for my friends here.
But I have two problems:

  1. My english is not so good.
  2. I have no idea for examples

Can you help me and make suggestions for hardware or library that we call from C++ ?
I add your suggestions in my instructions.
Thanks you in advance.
Ocean

5 Likes

For an example you could just show how to write a node that returns the current time, for example, where the time itself is provided via C++.

But you say already have nodes that call C++, so you could just show one of those.

Hi Colin,
thanks for suggestion. This was my plan in next level.
Ok I start with easy examples.

1 Like

Hi @iiot2k,
Very interesting. Looking forward to read your instructions!!

Have been experimenting recently to draw lines and (filled) polygons on images from my IP cams. But using Javascript this was horrible slow. So at the end I gave up. But I assume c++ is much faster for such use cases, since you can address pixels in memory directly.

Although that would be a more "advanced" example, it could be useful to demonstrate WHY it would be useful to implement some nodes partly in c++. And of course I might even use your example in real life. Although I don't know any fast algorithms by head to solve this. So perhaps calling a lib like OpenCv is faster. Not sure...

Bart

1 Like

I started writing the instruction document.
But it takes little time.
If finished. I give the link.

4 Likes

Many thanks for contributing to the community.

2 Likes

Hi,
I see that other Node-Red user don't give suggestions for examples. Therefore I select for hardware max7219 led driver example in C++ with call from Node-Red. Later we can use the C++ interface of SQLite for using with Node-Red.

The problem with that is that very few, if any, here will be able to try it out, as we don't have the hardware.

Hi Colin,
this is an very cheap module and anywhere aviable.
You can connect modules in series for more digits.
The interface is spi.


But if this module not easy to get, we can select an other hardware.

To show the principle of interfacing node-red with C++ a non-hardware problem would be better. Something that can be installed and tested on any node-red system. Even just a Hello World example where the text is generated in C++. The important aspect of your work is how to interface between node-red and C++, not how to interface C++ to some hardware.

2 Likes

I agree with Colin that the better option would not start with a hardware project since by no means everyone using Node-RED uses it with IoT hardware.

However, having said that, better to have an example than no example.

1 Like

That is true, we can, if we don't have the hardware, comment out the hardware stuff to test it.

ok, no hardware :blush:

2 Likes

Until your 2nd example :rofl:

1 Like

How should that work ?
hmm, awaiting examples.

The first thing that comes into my mind is to make use of the Node-API of Node js. As far as I can recall, you can create node-api node modules (see previous link) and NR is capable of loading node modules: Writing Functions : Node-RED

Hi,
to write good instruction and examples takes time.
I write this in my free time.
Please have a little more patience.

3 Likes
3 Likes