Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help -- How to read config from a String #179

Closed
wilson405 opened this issue Oct 20, 2021 · 3 comments
Closed

help -- How to read config from a String #179

wilson405 opened this issue Oct 20, 2021 · 3 comments

Comments

@wilson405
Copy link

wilson405 commented Oct 20, 2021

hi,
everything works perfectly, I just need a help, I need user and password, to be read from a string, because I will store it in Spiffs, can someone help me.

example :

// database user and password
char user[] = here variable type String ;
char password[] = here variable type String;

@ChuckBell
Copy link
Owner

ChuckBell commented Oct 21, 2021 via email

@wilson405
Copy link
Author

Hi Sir ChuckBell,

in my code >

IPAddress server_addr(myserver); // IP of the MySQL server here
char user[] = read string here; // MySQL user login username
char password[] = read string here; // MySQL user login password
char db[] = read string here; // MySQL Database

I would like to read the username, password and database from a String that I have stored in a variable, how do I convert the variable that is a String to the char * ? Would you help me ?

@ChuckBell
Copy link
Owner

I am not familiar with SPIFF (from the ESP world), but to convert a string to a char *, you would use the c_str() method to get the char * pointer.

For example, say you read the user name into a string something like this:

String user = something.spiff_read();

To use the user (which is a String class) as a char *, just call the c_str0 method like this:

connect(user.c_strr()...

There is no need to copy the string to a char * buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants