K
K
Kirill Khalitov2014-01-23 12:33:16
Arduino
Kirill Khalitov, 2014-01-23 12:33:16

What is the best way to organize interaction with a desktop Qt / C ++ Application via the Internet?

Hello. There was a task to implement remote interaction with Arduino via the Internet. In addition, real-time monitoring of the data sent from the Arduino is required. I wrote a Qt App to receive data from the Arduino for the first time, so that later I can send data packets to the server (there is no ethernet shield) and receive control packets with the same program.
Now I am faced with a choice with a slight misunderstanding. After looking at a couple of articles , I realized that this does not suit me.
After a little thought, I came to the conclusion that you can use sockets. C sockets worked a little and only in the local network. However, this is what I think is the solution. That is, I create a socket in Qt App, launch a separate stream for receiving / transmitting, and doing sendto to mysite.com. waiting for incoming packets.
The server side is more difficult. The first thing that came to mind was PHP Socket. I have never worked with them and so many questions arose. How to organize the markup of a web page so that the php script works asynchronously and updates the markup in accordance with the received data in real time, and at the same time accepts the user's frontend control commands. Yes, in addition, the ip-address that controls the arduino computer is dynamic.
I understand the general abstract structure of interaction and the process of data exchange at the level of packages (structures - that is, void * arrays). I don't know what means to use.
What do you advise, dear?

Answer the question

In order to leave comments, you need to log in

10 answer(s)
K
Kirill Khalitov, 2014-04-10
@Voronar

Wt, turns out to be paid for KI. In the furnace then it ... I
came up with this option.
We buy VPS for 200 rubles per month. We put a program there in C / C ++. This program accepts UDP packets from Qt App (this program accepts packets from Arduino). The exchange of the program for C / C ++ with client-side JS goes through the Web socket (libwebsocket for C / C ++).
In this way, I will try to achieve almost real-time display of data on my site with Arduino.
I will test this option on 127.0.0.1

D
Dmitry, 2014-01-24
@peleron

I will offer three options for interaction via the Web:
1. Connection "client-server-client". the simplest HTTP server is organized on the Internet. A CGI script is placed on it, which receives requests from the control device and adds them to a file. The second (managed) device periodically downloads requests from the server and responds to them - the responses are also stored on the server. And then the control device rakes them out. This is a classic case, in principle, there is nothing complicated and terrible. But the main disadvantage - real-time'a will not work. Delays will be in a couple of seconds
2. Client-client connection over IPv4. The controlling and controlled computers somehow agree on the connection between themselves - in order to overcome all kinds of NATs and firewalls. And then they exchange data with each other. Plus - real-time, minus - complex solutions for organizing the initial connection. And minus bold - for embedded devices, especially without full support for the network stack and third-party utilities for the network, this is very difficult to organize.
3. Client-client connection over IPv6. Since the network is IPv6, there is no need to bother about overcoming NATs - in IPv6, any device can be reached directly. The code is very minimal. Minus - IPv6 is not yet very developed, but there are many services that allow you to forward IPv6 over IPv4. But this requires the installation of additional software.
So decide whether it is worth suffering with Arduino, or is it easier to take something more powerful, for example. the same RaspberryPi and similar comrades

N
nekipelov, 2014-01-23
@nekipelov

If you have no experience with sockets, then it's better not to take it. Use a higher level protocol: HTTP, as the json data format. It's not entirely clear what is meant by "interaction with Arduino", you may need something like WebSockets if this interaction can occur from any side.

K
Kirill Khalitov, 2014-01-23
@Voronar

That's what I mean by interacting with the Arduino.
For example, Arduino controls something and I want to use Arduino control through the browser. I open the browser, type in the address and see a page that shows some real-time changing indicators coming from the Arduino (temperature, etc.). Also on this page there are buttons that I can press, and as a result of clicking on one of them, the Arduino should respond to these clicks in an appropriate way.
That is, you propose to send HTTP requests. If I send requests every 100 milliseconds, nothing bad will happen? I just haven't come across it.
But what about incoming packets that are formed when interacting with the web interface using buttons. How to send them to the host computer? Responses to inquiries? Until I can understand.

K
Kirill Khalitov, 2014-01-23
@Voronar

About sockets. So if you don’t work with them, where will the experience come from?
Worked a bit with UDP sockets on Linux. I have a general idea about them.

K
Kirill Khalitov, 2014-01-25
@Voronar

Thinking about the prospects, I thought that I want to find a fairly universal way to communicate with the server. So that, for example, I, having an operating system such as linux, android, windows on any device with an Internet connection, could communicate with the server in the same way for each of the OS. After all, for each OS there is an implementation of sockets. It seems to me that this is the best option. The only problem is that you need hosting with the ability to run your own program, for example, in C ++, which would process socket requests. Of course, it is better to communicate through a php script that will work on a cheaper hosting. Of course, this is the thinking of a pure web newbie.

R
Robotex, 2014-01-30
@Robotex

Why not run a C++ application on the server that will also use sockets?
Look also towards CppCMS and Wt.

K
Kirill Khalitov, 2014-01-30
@Voronar

So I immediately wanted to use linux sockets on the pluses. The problem is where to get such hosting so that you can run any commands and programs in the terminal and that it is also free or at least not expensive. Moreover, I have not even found a domain yet. I was looking for a free 3rd level, but I did not find where to order it. Therefore, while it is necessary to conduct tests on a local server.
The second snag is that I do not yet have a complete understanding of the interaction of my own program on the server and the client. So far I have this picture in front of my eyes.
There is a program on the pluses, which receives requests in a separate thread and responds to them. All this happens without stopping in real time (with acceptable delays for me). Here I have a difficulty. How to organize a request from a js / html client through jquery-ajax to the server to the program on the pluses? So far, I have only had the experience of sending an ajax-post request to a php script, which returned a json string in response via echo. The data was updated only after the page was reloaded. How to make client requests loop in a separate thread? Or will you have to generate an html document manually on the server on the plus side?
Now I'm experimenting and trying to get by with a php script. Already got two way communication by running php script just in console, separate from browser. However, the same problem still remains. Namely, how to make asynchronous continuous requests to a php script from the client side, which spins in processes and returns a json string?
All my difficulties are due to a misunderstanding of the interaction between the server and the client at the OS level. The browser level cannot give me a complete picture. What do you advise on this topic?

K
Kirill Khalitov, 2014-01-30
@Voronar

Looked towards Wt. Intrigued by the description on Wikipedia.
Thanks Robotex. So far, I just don’t understand on which hosting it can be deployed. I will sort this out.

I
I_maleficus, 2014-04-09
@I_maleficus

And if you try to use the OPC standards?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question