# 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:** 14\
**Page:** 2

<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:32 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/21 "2021-02-18T19:32:39Z")

</div>

You mean run my C executable from the exec node? What would my exec-node command be---the name of the executable?

This wouldn't work down the line, because I will need to run my C code on a separate machine, but this could be a way of simplifying to troubleshoot things if needed...

---

<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 20:01 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/22 "2021-02-18T20:01:31Z")

</div>

> [@a1ex](#):
>
> What would my exec-node command be---the name of the executable?

Basically, yes. Use the same command you would use to invoke it from the command line.

> [@a1ex](#):
>
> I will need to run my C code on a separate machine

When that time comes, if the remote machine can run NR you might consider using the same setup on the remote machine and connecting the two hosts using mqtt. Then you can use just standard NR nodes and avoid writing any additional C code.

---

<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 20:05 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/23 "2021-02-18T20:05:22Z")

</div>

Oh! That's an idea for when the time comes! Not sure if it will work on RTOS computers with limited resources for complex models, but it might come in very handy nevertheless. Thanks!!!

---

<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 20:05 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/24 "2021-02-18T20:05:46Z")

</div>

If you have TCP experience, it is actually not that bad.  
On your C program side, you just need to look into TCP client.  
Create socket-\>connect to Node Red TCP server -\> send "hello world".  
In your case, the TCP server is the local host.  
You can do this in c:

```auto
	const char* server_name = "localhost";
	const int server_port = 8877;

```

On Node Red side, use TCP in node to accept inputs. Also use the same port in your c program. In this case, it is 8877. Check the output from TCP after you run the c program.

---

<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 20:08 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/25 "2021-02-18T20:08:41Z")

</div>

@drmibell:

Say I compile a C program:

`gcc test.c -o test`

From the command line, I would run test by entering `test`.

I take it test is then the command to use in the exec node? But how does it know where to find the test executable if I haven't told it? The program wouldn't run from the command line if I weren't in the right folder, but there I could just cd to it.

---

<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 20:11 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/26 "2021-02-18T20:11:59Z")

</div>

Thanks, @davidz! I'm sure there's more to the code than just those two lines, though. That's where things go wrong for me. I've tried several C scripts but they all require libraries I don't have on Windows, and when I replace them with their Windows equivalents, the code errors out.

---

<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 20:28 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/27 "2021-02-18T20:28:02Z")

</div>

I took that example I linked to.... changed the line 41 to say "Hello" (as that is what you asked for 🙂 Then commented out lines 46 to 59 (the listen part as I don't need anything back) - then compiled the code - `gcc -o send client.c` - to create and executable called send... Then in Node-RED set up a tcp in node listening on port 8877 feeding a debug node... then run `send` - and data arrives...  
but yeah I'm not on windows

---

<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 20:32 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/28 "2021-02-18T20:32:50Z")

</div>

In Linux environment such as Raspberry Pi or Ubuntu, it is very straightforward. Just compile the C codes and done 😂  
For Windows, you may have to install some library for it to work 😂. You will need to look at error message and figure out which library is missing and then install it for your compiler.

---

<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 20:35 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/29 "2021-02-18T20:35:15Z")

</div>

That's all I've been doing for the last day ☹

---

<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 20:37 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/30 "2021-02-18T20:37:17Z")

</div>

OK, I see the exec node works if I use the path to my C executable as my command---e.g. this:

`C:\Users\myself\.node-red\test.exe`

and not this:

`test.exe`

So OK, I have this one crutch now 🙂

---

<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 20:49 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/31 "2021-02-18T20:49:28Z")

</div>

Thanks @dceejay!

Sadly I can't get it to work on Windows:

![err2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7aa9dbca2a057e83591dfe75924968a530200ff3.png)

![err1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e37dbedf8cc701a2c874e97c2747da4be48f8040.png)

I looked up the missing packages and found suggestions that winsock2.h should be in their place, but that only led to a different error:

 ![err3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/245fd95d21334d7290d0a8e29df55bc5d92de323.png)

---

<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 21:11 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/32 "2021-02-18T21:11:57Z")

</div>

> [@a1ex](#):
>
> OK, I have this one crutch now

I wouldn't call it a crutch... more like a bicycle compared to the Ferrari's in the other comments.

---

<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 21:13 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/33 "2021-02-18T21:13:47Z")

</div>

Everything's a crutch when you don't got legs 😃

---

<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:** [19 April 2021 21:14 UTC](https://discourse.nodered.org/t/stream-data-from-c-program-to-node-red-dashboard/41213/34 "2021-04-19T21:14:27Z")

</div>

Closed on 19 April 2021 21:14 UTC

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

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