• 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

Module 3 Section 2.1 Hidden Magic

Q&A Forum › Category: ESP32 › Module 3 Section 2.1 Hidden Magic
0 Vote Up Vote Down
Ray Leiter asked 3 years ago

I have 2 questions:

  1. Is the use of percent signs to delimit the so-called “placeholder” string, “STATE” dictated by something I can’t directly observe as I go through the tutorial? Perhaps it is dictated by something with one of the async libraries I’m using? I don’t see it mentioned anywhere within the HTML literature.
  2. I can clearly see that the “processor” function requires a parameter of type “String”. Nowhere in the code do I see a reference to the “processor” function with a parameter being supplied! The question is “How does the function get it’s parameter? Since the function is a parameter to the “send” method of the “request” object, I suppose the function is called by the “send” method and it is the “send” method that provides the string “STATE”? BUT HOW? Is it the case that the “processor” function (aka “Handler function”) is supposed to scan the HTML looking for strings within percent signs and return those strings?

Thanks, Ray

Question Tags: async web server handler function
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
The placeholder works with the Asyncwebserver library, it has nothing to do with HTML literature.
The Asyncwebserver library finds the placeholders and replaces them with whatever we define in the processor function. This is done automatically in the background.
You are correct about what you mention in bullet 2. It is how it happens.
Regards,
Sara
 

0 Vote Up Vote Down
Ray Leiter answered 3 years ago

Sara,
Thanks. I found some good info here:

ESP32 Arduino HTTP server: Template processing


Basically, the idea is that the HTTP server provides a service we call “Template Processing”, whereby we can embed replaceable strings in the HTML and then retrieve them via the server’s call of our template processing function which then returns whatever we wish to replace the “replaceable string” with.
In our case we replace “STATE” with either “ON” or “OFF”. This allows us to merge static HTML with something we only know at runtime thereby modifying our HTML “on the fly”.
It was some years ago when I first encountered this concept — I had forgotten about it.
I also forgot about Lambda functions which is why I struggled to understand the syntax of

"[](AsyncWebServerRequest(*request){ ... }".

Thanks again, Ray
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Yes, that’s right.
That website has very good articles about similar subjects too.
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

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition 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.