3

I have an embedded board that runs a Qt application (developed by me, I have the source code), this app is always active and it doesn't have any GUI (no display!), I'd like to add a web page that works as monitor (show some simple values) and permit to configure some parameters for the application... The first goal would be a simple web-page that permit to set a variable in the application, and show the status of another variable in "realtime".

The board is an ARM ,runs Linux and a web server is available, i already used succesfully cgi and php...

How i can communicate between the web part and the process of the application? I can use cgi to call another app that communicates to the main application with a socket, but i think there are better solutions...

browsing the web i think the keywords are Json-Ajax-JQuery but i don't find any example useful for my case.

Thanks for any advise and/or example

Nadir
  • 101
  • 6
  • If your needs aren't too complex, you could write a simple HTTP server on top of QTcpServer. Here's one example: http://doc.qt.digia.com/solutions/4/qtservice/qtservice-example-server.html – MrEricSir May 09 '15 at 19:41
  • As @MrEricSir says, you should be interested in adding your http server with https://github.com/azadkuh/qhttp and process within your application. – AlexandreP May 09 '15 at 20:33
  • Thanks for the responses, last week i played with different technologies and i haven't decide yet, I'd prefer to avoid to implement a http server in my application to permit more flexibility, this is only a first demo but it will be a standard for different applications; at the moment i think the best solution would be using web sockets that communicates with the webserver in a "standard" mode, I've seen it's possible to use them with all the most important web languages... – Nadir May 21 '15 at 09:30

2 Answers2

1

You have many different options for handling this, and the way you do it depends mostly on what you feel confident in doing. Some of the alternatives:

  1. Create a webserver within your own application that listens on port 80 and handles all the HTTP communication with clients:

    a) Webservers are complex beasts which are not easy to implement. Start with an example (http://doc.qt.digia.com/solutions/4/qtservice/qtservice-example-server.html) and modify to suit your needs. If you're not doing anything fancy this would be somewhat easy to accomplish.

    b) Obtaining the data from your application will be simple as the webserver is running within the same process so you can handle it as any other code under your control.

    c) This keeps your dependencies simpler, just one daemon/application to start and no other software to install on the embedded platform, so a simpler install.

  2. Run a full blown webserver (apache, nginx, lightty, etc) and whatever server-side code you need to support your use case (php, cgi, perl, python, etc).

    a) You won't have to worry too much about technical details of network programming and how to implement the HTTP protocol. This is specially valuable if you don't have much experience with network programming.

    b) You can create special command-line switches in your application so that the server-side script can call your program and parse the output in order to get it's data. You can also use a FIFO file which is written to by your application and read by the server-side script (see mkfifo).

    c) Installation will be a lot more complex, with another piece of software that needs to be installed (the webserver) and configured correctly. The magnitude of this problem depends on how you intend to deploy your software, if it's just for your own use or for clients, etc.

fleed
  • 640
  • 9
  • 15
0

Communication between Web side and Qt side may be implemented with QTcpSocket (in addition to http embedded server solution). Node.js framework allow this.

There is example of JavaScript TCP server and socket realization with Node.js

TCP socket programming in node.js

You can also be interesting in reading answers for How to get sensor data over TCP/IP in nodejs?

Community
  • 1
  • 1
Andrei Shikalev
  • 702
  • 4
  • 13
  • Thanks, I didn't know nodejs and in these days I'm playing with that, I added a QWebSocket to my application that communicate with a simple script for nodeJS that manage the connections with the clients, it works well on my PC;, the problem is that port nodeJS to my device (and compile plugins as well) is not a simple task, at this point i was thinking: can the client webpage comunicate directly with my application in javascript? – Nadir May 21 '15 at 09:19