Closed fanzypantz closed 3 years ago
mqttUser
and mqttPassword
are variables that only live in the scope of the setupMqtt function. As soon as the function ends, the variables are gone. the print
function copies the values of these variables but the mqtt library does not. the mqtt library works asynchronously and will only read the variables when the connection is made which is "in the near future after calling connect
".
You can solve your issue by not using local variables: by using references or pointers to static/global/long lived variables.
I'm not the biggest c++ programmer, so I'm not sure what is going on here. I have some declared static variables in an .h file to be the base values if no new values is assigned in the wifi portal. I can't use the new values for some reason. Converting from String to char array, seems to mess up the credentials.
I'm printing them out and they're identical. Am I just converting the string wrong? If I just use the MQTT_USER and MQTT_PASSWORD directly it works, but would obviously not make it editable from the portal.
Code: