I am using as a basis the 4.1 “Web server with input Fields” and all works well. In use, variables modified by a user are saved and restored as required in SPIFFS when fields are edited and pages are changed. However, in my application on boot up some of the fields must not use the values saved previously in SPIFFS, but given default values.
For example, one variable is “steps”. In use this numeric can have any number of values, and they must be saved and restored during use as pages change. But if the ESP32 is powered down and up again, it must both present the value 0 in its respective field and actually have this value in the C++ code.
I have made many attempts at defining global variables in the C++, HTML and javascript code that each could presumably access but without success. I am sure the solution is something simple but would appreciate some help here.
Many thanks, Ron K
Hi.
What attempts did you do?
I think the code is already prepared to send initial values on start up.
You just need to change the values you want to send.
Take a look at the getCurrentInputValues() function. If you want your fields to be zero at startup, you just need to define them inside that function. Add a counter that checks if it’s the first time the function is running, it will send the zero, if not, it will send the actual values.
I hope this helps.
Regards,
Sara
Thanks Sara. So simple and obvious. I was trying to do something similar but in the html/js code which I now understand is quite transient. A lesson learnt.
Cheers,
Ron