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

**URL:** <https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492>\
**Category:** Developing Nodes\
**Created:** [16 August 2022 12:11 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492 "2022-08-16T12:11:32Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [16 August 2022 12:11 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/1 "2022-08-16T12:11:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 August 2022 12:38 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/2 "2022-08-16T12:38:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [16 August 2022 12:48 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/3 "2022-08-16T12:48:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [16 August 2022 13:33 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/4 "2022-08-16T13:33:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [16 August 2022 13:43 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/5 "2022-08-16T13:43:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 August 2022 16:55 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/6 "2022-08-16T16:55:43Z")

</div>

Many thanks for contributing to the community.

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [17 August 2022 07:45 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/7 "2022-08-17T07:45:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 August 2022 08:05 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/8 "2022-08-17T08:05:00Z")

</div>

> [@iiot2k](#):
>
> I select for hardware max7219 led driver

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.

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [17 August 2022 09:17 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/9 "2022-08-17T09:17:54Z")

</div>

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

 ![max7219](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/60f75c68c3f0340385c541c1945784467b8750ce.jpeg)  
But if this module not easy to get, we can select an other hardware.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 August 2022 09:29 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/10 "2022-08-17T09:29:19Z")

</div>

> [@iiot2k](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 August 2022 09:55 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/11 "2022-08-17T09:55:46Z")

</div>

> [@iiot2k](#):
>
> other hardware

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 August 2022 10:08 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/12 "2022-08-17T10:08:35Z")

</div>

> [@TotallyInformation](#):
>
> better to have an example than no example.

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

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [17 August 2022 10:44 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/13 "2022-08-17T10:44:49Z")

</div>

ok, no hardware 😊

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 August 2022 11:25 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/14 "2022-08-17T11:25:39Z")

</div>

Until your 2nd example 🤣

---

<div class="post-metadata">

**Author:** ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)\
**Post date:** [23 August 2022 11:18 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/15 "2022-08-23T11:18:21Z")

</div>

How should that work ?  
hmm, awaiting examples.

---

<div class="post-metadata">

**Author:** ![r0ller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0ller/32/14327_2.png) [@r0ller](https://discourse.nodered.org/u/r0ller)\
**Post date:** [23 August 2022 11:40 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/16 "2022-08-23T11:40:13Z")

</div>

The first thing that comes into my mind is to make use of the [Node-API](https://nodejs.org/api/n-api.html) 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](https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules)

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [23 August 2022 13:51 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/17 "2022-08-23T13:51:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [27 August 2022 07:45 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/18 "2022-08-27T07:45:06Z")

</div>

> [@Call C++ from Node.js (Node-Red), A tutorial](https://discourse.nodered.org/t/call-c-from-node-js-node-red-a-tutorial/66979):
>
> Hi guys, I write a litte tutorial how C++ is called from Node.js (Node-Red). The tutorial isn't finished and I hope understandable and helpful for you. If I add more chapters and examples, I inform this here. Thanks to my friends who helped me. Best Regards Ocean (Derya)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 October 2022 07:45 UTC](https://discourse.nodered.org/t/call-c-from-node-red-suggestion-for-examples/66492/19 "2022-10-26T07:45:44Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
