• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

more info on “request->send(SPIFFS, “/index.html”, “text/html”, false, processor);”

Q&A Forum › Category: ESP32 › more info on “request->send(SPIFFS, “/index.html”, “text/html”, false, processor);”
0 Vote Up Vote Down
Joe Margevicius asked 3 years ago

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

Question Tags: Web Server send()
6 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
 
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.
 
Regards,
Sara

0 Vote Up Vote Down
Joe Margevicius answered 3 years ago

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 …

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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.
 
Regards,
Sara

0 Vote Up Vote Down
Joe Margevicius answered 3 years ago

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.

0 Vote Up Vote Down
Steve Mercer answered 3 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Thanks for your contribution, Steve.
 
Joe, I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.