Chat freely about anything...

User avatar
By Hairyloon
#93727
btidey wrote:I suspect the question was about asynchronous / synchronous operation of software elements rather than serial communication.


Yes, exactly this, thank you.

Say for example I have an asynchronous web server with a button on it.
The button should trigger a routine on the ESP.

Meanwhile the programme is running a loop.
Does the server interrupt the loop in order to run its routine?
If not, then how does it work?
User avatar
By btidey
#93728 For the synchronous web server case you will normally have a call (server.handleClient(); within the loop which checks to see if there is any client requests to be handled. If there is then the code is expected to process the request and send back any response before returning control back to the rest of the loop. If no request is outstanding then the handleClient returns immediately. This works OK for many simple cases but the handling can be delayed by any prolonged activity in the rest of the loop.

For the asynchronous case nothing is required in the loop. The asyncwebserver is set up with event handlers and also uses the asyncTCP library. with this it can listen for connections in the background, parse and formulate the request requests and then triggers the appropriate event handler. This can allow the user loop to continue processing when there any spare time in the handling for example while responses are being transmitted.

For detail on how this works look at the readme at
https://github.com/me-no-dev/ESPAsyncWebServer
User avatar
By Hairyloon
#93796
btidey wrote:For the asynchronous case nothing is required in the loop. The asyncwebserver is set up with event handlers and also uses the asyncTCP library. with this it can listen for connections in the background, parse and formulate the request requests and then triggers the appropriate event handler...


This may be clear after I've visited the link, but this seems to mean that the loop would stop and wait for the event. Is that correct?
User avatar
By btidey
#93800 It is not waiting for the event, but when an event occurs the handler will effectively perform its task and on a single core processor like the esp8266 this will inevitably pause activity in the loop.