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

Port not recognise with structure parameters #157

Open
siteswapjuggler opened this issue Jul 15, 2019 · 3 comments
Open

Port not recognise with structure parameters #157

siteswapjuggler opened this issue Jul 15, 2019 · 3 comments

Comments

@siteswapjuggler
Copy link

siteswapjuggler commented Jul 15, 2019

Hello there,

I got a situation here in the Arduino IDE with an ESP8266 Wemos D1 mini Pro.

  • Arduino 1.8.9
  • ESP Core 2.5.2
  • Adafruit MQTT Library 1.0.3

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.

@ElizabethMorves
Copy link

ElizabethMorves commented Dec 24, 2019

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;
  }
....

@siteswapjuggler
Copy link
Author

Thanks a lot seems a classy solution :)

@AlenSunnyMathew
Copy link

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

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

3 participants