Okay, so as the title says, I'm an embedded C/C++ developer.
Right now, I'm working on a project that involves a client/server C application. The server side of the application is running on multiple SoC nodes that are deployed in random locations (they run off a battery and use a cellular modem for communication).
Right now, I would like to poll information about these nodes. So I have a central computer that I call my server, but that is running the client-side application of the project (bear with the nomenclature here). I run my program from the command line with an IP address, and other parameters as an input. It establishes a TCP connection with a node, sends it a request packet, and the node answers with a response packet. I then write this data to a CSV file on the server computer (the one who initiated the request). The socket is closed, and that's it.
One of the modes it runs in is "live mode", in which the client instantiates a TCP connection to one of the nodes (running the server portion of the application), and returns data once a second. When data is returned, a CSV file is appended to. Once the program receives an interrupt signal, it gracefully shuts down.
Now I'd like to do a little more. I would like a user to be able to control this application via a web browser.
The hacky solution I came up with is to have a button on a page. When this button is pressed, I do a shell_exec(/srv/bin/myApp_cli <parameters> &)
. Then through AJAX Javascript, the page starts reading from its output file once a second. It looks at the last line of the CSV file and posts it on the screen. When I want to stop this application, I do shell_exec(killall -2 myApp_cli)
.
It works, but my god is that a hacky way of doing something that should be easy. These two parts of the larger project: the web portion and the C client server portion; are extremely independent of one another.
My question is.. how can I interface my simple little C program with PHP, or any web language easily (I chose PHP because that's the only real back-end language I know). What would be the best approach to achieve what I would like to do? Especially in the case in which I run a program indefinitely until I want to send it a signal to stop?