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

Support pre-connected Client #571

Merged
merged 1 commit into from
Nov 25, 2019
Merged

Conversation

kevinresol
Copy link
Contributor

@kevinresol kevinresol commented Feb 3, 2019

I was trying to use this with the WiFiClientSecure Client for ESP32 where I need to call its connect function manually because it has a non-standard overload to support the TLS/SSL stuff:

client.connect(DOMAIN, PORT, CA_CERT, CLIENT_CERT, PRIVATE_KEY);

However, if I use this pre-connected Client with PubSubClient, the latter's connect call will be basically skipped because pubsub.connected returns true when the underlying Client is connected, disregarding the it's own internal MQTT state.

In order to make it work with a pre-connected Client, I did 2 things:

  1. in connected, double check the internal MQTT state is MQTT_CONNECTED , after checking the underlying Client is connected
  2. In connect, skip the underlying Client's connect call if it is already connected.

P.S. It is not needed to call setServer if the underlying Client is manually connected.

@knolleary knolleary merged commit 2b83aa0 into knolleary:master Nov 25, 2019
@knolleary
Copy link
Owner

Thanks - apologies for the long delay. This change looks good.

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

Successfully merging this pull request may close these issues.

2 participants