# Stream data from C program to node-red dashboard?

**URL:** <https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213>\
**Category:** General\
**Created:** [18 February 2021 06:19 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213 "2021-02-18T06:19:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 06:19 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/1 "2021-02-18T06:19:14Z")

</div>

Say I want to stream the results of calculations from a C program to node-red for real-time visualization.

The C program and node-red run on the same PC so it seems I can establish a connection with virtual TCP/IP ports.

In node-red, I can use the TCP In node and configure it to receive this data. I've done this with the node as a server (_listening on_) and am comfortable with it.

But what about the C program? I want to say I'll need to create a TCP client object in my C executable, then connect to my node-red server node in order to stream my calculation results.

Is this right? Are there examples anywhere of this?

I'd like to avoid other connection types, and I'd like to keep my program outside of node-red. I'd also like to stick with TCP connections, if possible.

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 06:25 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/2 "2021-02-18T06:25:34Z")

</div>

It seems my C program will need to do the right (client) side of the schematic below? This would be for Windows.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b139e27a29ebc00c6d3e44931499b134f88ae90.png)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [18 February 2021 06:31 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/3 "2021-02-18T06:31:29Z")

</div>

> [@a1ex](#):
>
> Are there examples anywhere of this?

Yes, but most likely not here in this forum, you have to google around. Stackoverflow, Codeproject, tons of possible places.

Myself I would for sure use MQTT instead, you would get a lot of other benefits as well

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 06:41 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/4 "2021-02-18T06:41:17Z")

</div>

OK, so it seems I can set up an MQTT broker, then stream my .c results to it, and then from my MQTT broker to node-red? I trust the broker-to-node-red connection is straightforward, but is the .c-to-MQTT straightforward also?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [18 February 2021 06:44 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/5 "2021-02-18T06:44:45Z")

</div>

Depends what you mean with straight forward? If you think C is, then there should not be any problem for you to add MQTT support. But for this, you have to google around. Look for Paho MQTT C Client

Like here maybe: [GitHub - eclipse/paho.mqtt.c: An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/](https://github.com/eclipse/paho.mqtt.c)

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 18:01 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/6 "2021-02-18T18:01:40Z")

</div>

Totally lost trying to add the Paho library to my mingw compiler. Why are there no instructions ever on Github? I mean, what do people do with that bunch of files included in a package? Does everyone just know how to go from there? How are newbies supposed to figure it out there is zero info on how to install a Github package? Oy.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 February 2021 18:17 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/7 "2021-02-18T18:17:09Z")

</div>

@a1ex what is this `c` application to do that node-red cannot? Is this an academic thing or do you have a real need for this?

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 18:22 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/8 "2021-02-18T18:22:09Z")

</div>

I'll be running a simulation in C. I have no choice. My data has to come from C. So to visualize that simulation data in node-red I have to communicate it from C. Eventually the simulation will be on a separate machine, so I will need to establish a remote connection, so that will be coming up. So for now I'm just testing whether I can in fact stream data from C to node-red. If I cannot, then node-red is out, because I have no control over the simulation side of things.

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 18:27 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/9 "2021-02-18T18:27:21Z")

</div>

Actually forget mqtt. This is clearly meant for developers who already know what they're doing, and there is zero practical help for newbies like me.

So I'm sticking with TCPIP, which is well established and better documented. So now my challenge is reduced to streaming creating a TCP client object in C to stream data to node-red. I guess this is all I'd like to do at this point: to create a "hello world" program in C that streams "hello world" to node-red. That's all. Any practical examples that newbies could follow for this?

Please don't just suggest I google things, because trust I've googled things, and please don't just point me to Github because there is zero practical info on how to actually use what's on Github.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 February 2021 18:28 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/10 "2021-02-18T18:28:37Z")

</div>

> [@a1ex](#):
>
> Actually forget mqtt. This is clearly meant for developers who already know what they're doing, and there is zero practical help for newbies like me

Did you check out [the samples](https://github.com/eclipse/paho.mqtt.cpp/tree/master/src/samples)

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 18:32 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/11 "2021-02-18T18:32:28Z")

</div>

Thanks, Steve, but Github... I don't know what to make of it... What are the files, how do I install them on my machine... Am I supposed to just download and put them in some folder---what? Because nothing is said on Github. Either you know it or you don't. I can't waste my time with assumptions that are undocumented. Why don't they bother to write just two sentences on how to use the packages shared on Github? I mean, come on. It's like giving someone a car but leaving the keys two towns over and expecting the person to drive off the lot no problem.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 February 2021 18:38 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/12 "2021-02-18T18:38:31Z")

</div>

Adding a `c` lib to a project is something you learn if you are a `c` programmer so it is not surprising there are no hand holding instructions. (I mean you are looking to do native TCPIP comms so i imagine you are a C programmer?)

I personally avoid C like the plague, hated it when I had to use it and find every excuse to avoid it.

That said, adding PAHO is no different to adding any other lib. You include the .h file, write the code (as per examples) compile your objects / binaries.

Writing your own TCP comms channel, I am afraid you will face many issues (like handling disconnections / re-connections etc) that MQTT handles automagically. If I can sway you, put your efforts into getting MQTT up and running - you will benefit from the experience of the great minds that developed MQTT and the years of issues that PAHO lib has seen and fixed.

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [18 February 2021 18:45 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/13 "2021-02-18T18:45:23Z")

</div>

Is your simulation result a data file or live data?

Both TCP and MQTT work wonderfully for your case. Yes Node RED can visualize the data nicely too.

If you feed live data, then I will recommend MQTT for its simplicity and robustness. If you just send files, then I may prefer TCP.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [18 February 2021 18:50 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/14 "2021-02-18T18:50:30Z")

</div>

there is a simple C tcp sender here - 64 lines of fairly commented code so should be possible to take apart ok

> <https://gist.github.com/suyash/2488ff6996c98a8ee3a84fe3198a6f85>

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 18:50 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/15 "2021-02-18T18:50:54Z")

</div>

Not a developer. Just an engineer. I'm simulating a machine and the simulation environment is slow. It's common practice in the field to deploy the simulation as C code, which runs at a more respectable rate. So I'm trying it.

And I would like to have real-time gauges like those I see in node-red. I've gotten those to work with TCPIP connections.

And right now I want to do just one thing: to stream "hello world" from C to node-red using either TCPIP or MQTT.

But I'm not a developer. I've gone through multiple instructions and installed multiple programs and it's become clear that I'm going on tangents to tangents to tangents... getting no closer to streaming from C to node-red, and in fact risking running out of time before I accomplish a thing with node-red.

I just want to say hello from C to node-red. Literally.

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 18:57 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/16 "2021-02-18T18:57:16Z")

</div>

Thanks, Steve. I know you mean well, but the challenge here is the same as before. I don't have all the libraries/header files included in the script and therefore it doesn't compile. I don't know how to install the libraries, which is what kept me from using the Paho QTT library. If I can't install, I can't include, I can't compile, and I can't run...

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [18 February 2021 19:03 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/17 "2021-02-18T19:03:09Z")

</div>

This might not work in your case, but the first thing I would try is to launch the C program using an `exec` node. Then have the C program send its output to stdout, and get the result in NR from the standard output of the `exec` node. As long as everything is on one host, you shouldn't need mqtt or tcp.

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 19:03 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/18 "2021-02-18T19:03:27Z")

</div>

It probably matters that I'm on Windows, not on Linux or Unix.

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [18 February 2021 19:07 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/19 "2021-02-18T19:07:45Z")

</div>

Windows will work well too. Though Linux environment is better 😁  
Your TCP framework is correct. You just need to sit down and write the C code for the communication part. The reward is there.

---

<div class="post-metadata">

**Author:** ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)\
**Post date:** [18 February 2021 19:30 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/20 "2021-02-18T19:30:39Z")

</div>

Thanks, David. I know the reward is in doing it yourself.

The problem is the info on how to do it is swiss cheese. Seems everyone has a blog or stackoverflow post or other web page outlining how to do this... but there is always something missing.

If I knew how to do this, I would just do it and feel like a champ for doing it. But I don't know how to do it, so I depend on info being available and complete to do it.

I'm not a psychic and at this stage my guess as to why things don't work is as good as no guess.

[Next page](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213.md?page=2)
