• 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

How to set initial values?

Q&A Forum › Category: ESP32 › How to set initial values?
0 Vote Up Vote Down
Ron Kreymborg asked 2 years ago

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

Question Tags: Initial default values.
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

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
 

0 Vote Up Vote Down
Ron Kreymborg answered 2 years ago

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

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

Great.
Let me know if you need further help.
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.