[color=#202124]I am trying to adapt a program that accesses a website by sending a password.
The program declares the contents of this password at the beginning as a char * variable:
example:
char * passwd = "my password";
The processor is the ESP32.
However, I am trying to change the program so that this content can be changed by the user during execution by the serial monitor, and also saving and retrieving in the EEPROM.
I already done the menu and manipulate the data easily as String variable but I cannot convert the String to char * afterwards. I've tried several methods: toCharArray and passwd.c_str (). Either an error message occurs when compiling, or a crash occurs when running, or the site does not accept the data.
What do you suggest?
I prefer to work the data as String both as input on the serial monitor and operations on the EEPROM using Put and Get, because I am a beginner and still do not understand the particulars of arrays.
I appreciate the help[/color]
acjacques, could you Modify your post and remove the "pre" and "color" tags ?
I think you should copy the c_str into a buffer (a char or byte array) and then use a pointer to it.
gcjr, your link is to the 'std' library. The Arduino String library c_str is this: c_str() - Arduino Reference.
you should not use global defined variables of type String. The variable-type String eats up all RAM over time
because each new assignemt needs new RAM. In a RAM-limited environmanet lieke a microcontroller this is a problem.
Over time all RAM is taken by the string-variables and then starts to even overwrite other variables. This will make your program act strange and is very hard to debug. So you should use alternatives like PString, or SafeString. both available through the library-manager in the Arduino-IDE.
For more information why read here
The Evils of Arduino Strings
But there are alternatives that are easy to use and are safe
there is a library PString and another called SafeString
which offers almost the same comfort as String but don't eat up memory over time
best regards Stefan
StefanL38:
you should not use global defined variables of type String. The variable-type String eats up all RAM over time
because each new assignemt needs new RAM. In a RAM-limited environmanet lieke a microcontroller this is a problem.
best regards Stefan
The ESP32' OS, freeRTOS, when used, cleans up memory holes caused by the use of Strings.
Using String's as a buffer, String.reserve(), mitigates the String creation of memory holes.