Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External Web Interface for a C++ Application [closed]

I am developing a web interface for a C++ application that runs on an embedded system.

I was wondering if it was possible to make a web interface that could be used to manage (set and get values) and display data provided by the application. (Something like Nagios.)

My question is: is there any technology that allows me to "communicate" between the Web interface and the C++ application?

Keep in mind that I have to do this on an embedded system, so I can't use frameworks or other things that are too heavy.

The Web Interface has to be outside the C++ Application (I don't want to code the interface in the C++ Applicaiton).

My idea was to use HTML5 and Javascript for the Web Interface, the web server which i will use is also lightweight (nginx).

If someone could give me any pointers it would be nice. Thank you in advance.

like image 500
Vince Avatar asked Oct 03 '22 23:10

Vince


1 Answers

So you need two things: a local interface your web page can use to configure the C++ app, and the web page itself.

There are a few common mechanisms for such local interfaces:

  1. modify a config file, and send SIGHUP to make the application re-read it

    • advantage is that you can test (and use) it directly from a shell, independently of the web interface
    • also note that changes persist automatically
    • disadvantage is that you need some scheme for storing a "last good" config file in case the edited one is damaged
  2. use a local streams socket and simple protocol (either a UNIX socket if supported, or a localhost:port loopback-only TCP socket)

    • advantage is that you don't touch (and possibly damage) the config file(s)
    • disadvantages are that you then need some other way of persisting changes, if you want to, and that you have to write this protocol in the first place
    • note that so long as the protocol is text-based and not binary, you can at least still test it with telnet or netcat, so you can still use it directly from the shell
      • simple protocol like set variable=value, get variable etc. shouldn't be too hard

If you really want to decouple the web and C++ applications, make sure you can query the available options, ideally giving types, valid ranges and groups for them. Then, you can avoid re-coding the web page every time you add or modify an option.

You can manage that with magic comments in a config file (make sure nothing is silently defaulted with no comment), or with a list command to the stream socket.

With a bit of effort, you can probably build your grouping, data type and validation constraints into the type system of your C++ application, so both the local interface and web app can be driven automatically.

like image 93
Useless Avatar answered Oct 07 '22 20:10

Useless