External web interface for C ++ application

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

I was wondering if it is possible to create a web interface that can be used to control (set and receive values) and display the 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 in the embedded system, so I cannot use frameworks or other things that are too heavy.

The web interface should be outside the C ++ application (I do not want to code the interface in the C ++ Applicaiton).

My idea was to use HTML5 and Javascript for the web interface, the web server I will use is also lightweight (nginx).

If someone can give me some pointers, it would be nice. Thank you in advance.

+4
source share
2 answers

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

There are several common mechanisms for such local interfaces:

  • change the configuration file and send SIGHUP so that the application re-read it

    • Advantage
    • is that you can test (and use) it directly from the shell, regardless of the web interface
    • also note that changes are saved automatically
    • is that you need some kind of scheme to store the β€œlast good” configuration file in case the edited file is damaged.
  • use a local socket stream and a simple protocol (either a UNIX socket, if supported, or a TCP port with a local host: TCP port only)

    • the advantage is that you do not touch (and possibly damage) the configuration file (s)
    • that is, then you will need another way to save the changes if you want, and that you must first write this protocol
    • note that as long as the protocol is not text-based and not binary, you can at least test it with telnet or netcat, so you can use it directly from the shell anyway
      • a simple protocol, such as set variable=value , get variable , etc., should not be too complicated.

If you really want to separate web and C ++ applications, make sure you can query for available parameters, ideally by providing types, valid ranges and groups for them. You can then avoid re-encoding the web page every time you add or change a parameter.

You can control this by using magical comments in the configuration file (make sure that nothing is disabled by default without comments) or by using the list command on the stream socket.

With a little effort, you can probably create your own grouping, data type, and check constraints into the type system of your C ++ application, so you can automatically control the local interface and web application.

+3
source

If you drop the requirement that the web server be in a different process, there are many solutions

lightweight web servers

0
source

Source: https://habr.com/ru/post/1484177/


All Articles