My program is a adaptation of the well known "click on/off" led light example, in several online tutorials.
The significant components of the original example are
client.print("
<a href="/GPIO17ON"><button class="button button1">Click to turn ON
");
resulting in the URL visible in the browser being appended with "/GPIO17ON" after the "ON" button is pressed and
if (request.indexOf("/GPIO16ON") != -1)
i.e if the URL IS appended with "/GPIO16ON" then turn the led on.
The user can press either the ON or OFF button. The request is always appended with either
"/GPIO17ON" or "/GPIO17OFF".
My implmentation differs in two respects
My buttons either "ADD" or "SUBTRACT" from a counter
I have an
client.println("Refresh: 2");
as one of the initial lines of the client request (i.e my page is refreshed every two seconds)
My problem is that the counter is added or subtracted every two seconds, NOT just once when there is a user click of a button. This is because the request is always appended with the ADD or SUBTRACT after each refresh.
The example only changes the request URL via an explicit user click of a button. But I would like to detect the user click once and then reset the request URL to not have the appended "ADD" or "SUBTRACT"
I've tried saving the orginal localIP value and reseting the Wifi.config() without luck
How can I reset the client URL without any explcit user action
Are you awared about the fact that opn ESP32 the F() macro do nothing and it's kept only for compatibility?
For saving SRAM you should use a const char array which by default it's stored in program memory space.
Using a raw literal string can also be a better approach for code clarity and readability.
const char* myHTML= R"literal_string(
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
)literal_string";
The problem I stated was in the context of a larger, more complex, application that I dont wish to substantially re-write
I suppose I was after a silver bullet. A short code snippet that sent a href, with the required structure, from the client to the server, without user input,.
Just two notes: invest 60 minutes for a small Proof of Concept. The Webserver / HelloServer makes it very easy to extract GET and POST parameters. If you use POST parameters you don't have the "problem" with the appended user action.
The update of page parts can be done either with websockets or with the FetchAPI. Later can be found in my example also.
Thank for the the insights you've provided. Ill research further
"invest 60 minutes for a small Proof of Concept"
Sometimes what appears to be a "minor technical issue" arrises after a significant amount of successful development. That is, it requires a near complete implmentation to discover the problem.
Im still suprised that this doesnt have a single line solution
I totally agree with @noiasca
A bad implementation, even if at beginning seems work well and fit the requirements, sooner or later presents the bill and something needs to be revised.