Skip to content

Commit 02985a9

Browse files
committed
added skip option
1 parent de59cec commit 02985a9

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ void setOptions(int keepAlive, bool cleanSession, int timeout);
151151
Connect to broker using the supplied client id and an optional username and password:
152152

153153
```c++
154-
bool connect(const char clientId[]);
155-
bool connect(const char clientId[], const char username[]);
156-
bool connect(const char clientId[], const char username[], const char password[]);
154+
bool connect(const char clientId[], bool skip = false);
155+
bool connect(const char clientId[], const char username[], bool skip = false);
156+
bool connect(const char clientId[], const char username[], const char password[], bool skip = false);
157157
```
158158
159+
- If the `skip` option is set to true, the client skip the network level connection and continue with the MQTT level connection. This option should can be used in order to establish and verify TLS connections.
159160
- This functions returns a boolean that indicates if the connection has been established successfully.
160161
161162
Publishes a message to the broker with an optional payload:

src/MQTTClient.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,25 @@ class MQTTClient {
273273
this->timeout = (uint32_t)timeout;
274274
}
275275

276-
bool connect(const char clientId[]) { return this->connect(clientId, nullptr, nullptr); }
276+
bool connect(const char clientId[], bool skip = false) { return this->connect(clientId, nullptr, nullptr); }
277277

278-
bool connect(const char clientId[], const char username[]) { return this->connect(clientId, username, nullptr); }
278+
bool connect(const char clientId[], const char username[], bool skip = false) { return this->connect(clientId, username, nullptr); }
279279

280-
bool connect(const char clientId[], const char username[], const char password[]) {
280+
bool connect(const char clientId[], const char username[], const char password[], bool skip = false) {
281281
// close left open connection if still connected
282-
if (this->connected()) {
282+
if (!skip && this->connected()) {
283283
this->close();
284284
}
285285

286286
// save client
287287
this->network.client = this->netClient;
288288

289-
// connect to host
290-
if (this->netClient->connect(this->hostname, (uint16_t)this->port) <= 0) {
291-
return false;
289+
// connect to hostg
290+
if(!skip) {
291+
int ret = this->netClient->connect(this->hostname, (uint16_t)this->port);
292+
if (ret <= 0) {
293+
return false;
294+
}
292295
}
293296

294297
// prepare options

0 commit comments

Comments
 (0)