Let me start by describing the problem. I have a lot of ESP at home. The whole control model is based on connectivity to a server, specifically PHP scripts. The WEB application connects to the server and sends or receives information (e.g. lights a lamp, reads the temperature, etc.). On the other hand, I have ESPs that respond accordingly. If they just send data (e.g. temperature) then there is no problem – they do it at a certain interval. Worse when they are actors – then they ask the server if there is something to do e.g. whether to switch on a relay. In the case of lighting control, however, I don't want to wait long for a response, hence the polling needs to be frequent e.g. every 0.5s. This is not a problem for the server, but nevertheless generates unnecessary traffic and even so these 0.5s are noticeable. Of course, the solution would be to set the ESP in the position of the server, but here other problems arise, e.g. time control – for example, if someone turns on an outdoor light and forgets to turn it off, then with regular polling, there is no problem for the PHP server to conclude that the sun has risen and there is no need to shine.
So I came up with a solution that combines the advantages of both solutions (client and server) for actors. It involves cyclically querying at a longer interval (e.g. 20s), while at the same time using the web server function in ESP exclusively to signal – „stop waiting and query, because I have something for you”. In theory, this approach doesn't change the philosophy and doesn't require a lot of software redesign, yet it should be fast and effective.
My idea is very simple (below is the skeleton of the idea):
.
And now the questions – is such an immediate server shutdown (without downloading) correct? Will everything allow itself and will there be no memory leak? Can I use the „client” variable immediately for uploading?
So I came up with a solution that combines the advantages of both solutions (client and server) for actors. It involves cyclically querying at a longer interval (e.g. 20s), while at the same time using the web server function in ESP exclusively to signal – „stop waiting and query, because I have something for you”. In theory, this approach doesn't change the philosophy and doesn't require a lot of software redesign, yet it should be fast and effective.
My idea is very simple (below is the skeleton of the idea):
Code: C / C++
And now the questions – is such an immediate server shutdown (without downloading) correct? Will everything allow itself and will there be no memory leak? Can I use the „client” variable immediately for uploading?