I have a boolean function which contains a string. In my main project this string is extracted from a website using an ESP8266 which is compatible with the Arduino IDE. I need to convert this string to a char* type of which is to be used in the loop() section of the code. The issue which I have faced is related to the setting of the mPass global variable, which does not change when it is done in the restoreConfig() Boolean function, meaning it remains blank when called for in the loop.
I do understand that this problem is related to the fact that I am defining the mPass within the Boolean function, however I am unsure as to the process in which I can change the global variable without errors.
I have tried resolving this problem through moving the mqttpass, mqttpasslen and mPass variables out of the restoreConfig() function, however it creates significantly more problems than that which I have at the moment. As a result I have only presented the code without any adjustment below:
char* mPass = "";
void setup() {
Serial.begin(115200);
}
void loop() {
if (restoreConfig()) {
Serial.println(mPass);
Serial.println("ABOVE IS mPass IN LOOP");
}
delay(1000);
}
boolean restoreConfig() {
String mqttpass = "DOGS";
int mqttpasslen = mqttpass.length() + 1;
char mPass[mqttpasslen];
mqttpass.toCharArray(mPass, mqttpasslen);
Serial.println(mPass);
Serial.println("ABOVE IS mPass IN BOOLEAN");
return true;
}
My current output from this is:
DOGS
ABOVE IS mPass IN BOOLEAN
ABOVE IS mPass IN LOOP