Open siteswapjuggler opened 5 years ago
you can call the instance link globally
Adafruit_MQTT_Client *mqtt;
and fill out the structure during initialization
mqtt = new Adafruit_MQTT_Client( &client, config.mqtt_server, config.mqtt_port );
rewriting a little function void MQTT_connect()
void MQTT_connect() {
int8_t ret;
// Stop if already connected.
if (mqtt->connected()){
return;
}
....
Thanks a lot seems a classy solution :)
Hai iam having the same issues with the port. I have saved the mqtt configurations in SPIFFS and initialized with structure. When iam trying to connect with mqtt its failed. But its getting connected when the port number defined globally. Any thoughts
Hello there,
I got a situation here in the Arduino IDE with an ESP8266 Wemos D1 mini Pro.
I was used to store my parameters in EEPROM with structures so I decided to the same on my last project with MQTT parameters. Unfortunatly I was unable to connect.
When I enter the parameters manually like in the exemple it works, but with my structure it doesn't. I tripled checked the value everything was correct. Server, username and key are also stored in a structure and works well. The port is the only parameter that doesn't pass to the MQTT_Client instanciation.
I suspected a problem because the instance is called globally, while my structure get its values in the setup()... still doesn't explain why stings and so are working but it's a clue.
Workout 1 (not working)
I tried to find a way to declare the instance in the setup but I didn't find the way to do it. I'm not confortable enough with class extensions like it seems to be in this case. Adafruit_MQTT_Client extend Adafruit_MQTT.
Workout 2 (working but dirty)
I added a setPort method to Adafruit_MQTT class, doing so I can call it later in the setup and make it work.