I’m going through the Build Web Servers eBook, and am mystified by the send( ) section of an HTTP request, specifically the processor place holder. Send( ) apparently expects a string in that place-holder, but how does the word processor accomplish that? Obviously the processor() function is expecting a (const String& var) argument…. but where does that come from? I follow what the processor() function should do (i.e. return the ledstate, or an empty string)…. it’s the argument that puzzles me.Thanks
The processor() function is called automatically with the String you set as an argument on the send() function when the send() function runs.
I hope this is not confusing.
Thanks Sara, but the question is where does “the String you set as an argument” come from? Perhaps my confusion is also in understanding the meaning of the (const String& var) argument – I can understand the typing done by the const part, presumeably for the String& part of the argument … implying that there are 2 arguments, a constant “string&” and and a variable “var” The function clearly checks this variable var (i.e. var), but again, where does var come from ? and what is const String& doing … if it’s really a separate argument, where does it come from ? Thank you for your patience …
Basically, it searches your HTML text for placeholders, which are delimited by % signs.
For example %TEMPERATURE%, or %VARIABLE%, or %STATE% in the example on page 202. These placeholders are then passed automatically as arguments (var variable) to the processor() function, see page 214.
Then, you can check the names of the placeholders, and return whatever information you want to replace the placeholders.
Thanks Sara for your explanation… I now understand better this surprisingly behind-the-scenes complex function. I also found this link that helped further clarify this “processor” placeholder (called an AwsTemplateProcessor in the link) in the AsyncWebServerRequest part of the Asynchronous WebServer library for Espressif MCUs. … the fundamental source of confusion is that within the send( ) function, the placeholder titled processor is more than just processor() – it’s really a different function which goes and reads the html file to find a %xxxx%… and it’s only then that the processor() function finally has its arguments so it can do its thing. Subtle, and I know this is not the depth of explanation appropriate for the eBook, but I needed it. This topic can be closed. thanks again.
Just to see if I can clarify a bit. “const String& var” is a C language thing. What it is saying is that var is is a pointer to a string in memory. ie. it points to where the String var is. The const part is saying that var is not changeable. You can read it as “constant address of a String type variable named var”. There is only one argument being passed. It is an integer which is a location in memory where the string starts. The processor reads each byte from that start location until it reaches a null character and then stops.