Sara Hi, Regarding the Arduino Sketch. Most of the code is written within the void setup() function. I was always taught that setup() runs only once. How then does the ESP32 react to redirects /on and /off as the coding sits within function setup()?
P.S. Really nice unit, learned alto!!
In that unit, we are building an asynchronous web server. We define what will happen when some event occurs.
Basically, when you use the on() methods on the server, it means that the server (the ESP32) will be listening for requests on the URL we define.
When a request arrives on a URL we have defined, the ESP32 will run whatever we write for that particular request.
Do you know how interrupts work with the ESP32? When the interrupt happens we call a callback function that will be executed. And we don’t need to put anything on the loop(). It is similar here, basically, those lines mean “when this happens, do this”.
Let me know if this is clear.