Stream data from C program to node-red dashboard?

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...

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

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.

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!!!

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:

	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.

@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.

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.

I took that example I linked to.... changed the line 41 to say "Hello" (as that is what you asked for :slight_smile: 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

2 Likes

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

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

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 :slight_smile:

Thanks @dceejay!

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

err2

err1

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:

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

Everything's a crutch when you don't got legs :smiley:

1 Like

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