@@ -140,23 +140,9 @@ MQTTClient::~MQTTClient() {
140
140
free (this ->writeBuf );
141
141
}
142
142
143
- void MQTTClient::begin (IPAddress ipAddr, int port, Client &client) {
144
- // set hostname and port
145
- this ->setHost (ipAddr, port);
146
- // finish up begin() call
147
- _begin (port, client);
148
- }
149
-
150
- void MQTTClient::begin (const char hostname[], int port, Client &client) {
151
- // set hostname and port
152
- this ->setHost (hostname, port);
153
- // finish up begin() call
154
- _begin (port, client);
155
- }
156
-
157
- void MQTTClient::_begin (int port, Client &client){
143
+ void MQTTClient::begin (Client &_client) {
158
144
// set client
159
- this ->netClient = &client ;
145
+ this ->netClient = &_client ;
160
146
161
147
// initialize client
162
148
lwmqtt_init (&this ->client , this ->writeBuf , this ->bufSize , this ->readBuf , this ->bufSize );
@@ -190,10 +176,9 @@ void MQTTClient::setClockSource(MQTTClientClockSource cb) {
190
176
this ->timer2 .millis = cb;
191
177
}
192
178
193
- void MQTTClient::setHost (IPAddress _ipAddr, int _port) {
194
- // set hostname and port
195
- this ->ipaddress = _ipAddr;
196
-
179
+ void MQTTClient::setHost (IPAddress _address, int _port) {
180
+ // set address and port
181
+ this ->address = _address;
197
182
this ->port = _port;
198
183
}
199
184
@@ -292,7 +277,7 @@ bool MQTTClient::publish(const char topic[], const char payload[], int length, b
292
277
return true ;
293
278
}
294
279
295
- bool MQTTClient::connect (const char clientId [], const char username[], const char password[], bool skip) {
280
+ bool MQTTClient::connect (const char clientID [], const char username[], const char password[], bool skip) {
296
281
// close left open connection if still connected
297
282
if (!skip && this ->connected ()) {
298
283
this ->close ();
@@ -303,13 +288,12 @@ bool MQTTClient::connect(const char clientId[], const char username[], const cha
303
288
304
289
// connect to host
305
290
if (!skip) {
306
- int ret = 0 ;
307
- if (this ->hostname != nullptr ){
308
- ret = this ->netClient ->connect (this ->hostname , (uint16_t )this ->port );
309
- }else {
310
- ret = this ->netClient ->connect (this ->ipaddress , (uint16_t )this ->port );
311
- }
312
-
291
+ int ret;
292
+ if (this ->hostname != nullptr ) {
293
+ ret = this ->netClient ->connect (this ->hostname , (uint16_t )this ->port );
294
+ } else {
295
+ ret = this ->netClient ->connect (this ->address , (uint16_t )this ->port );
296
+ }
313
297
if (ret <= 0 ) {
314
298
this ->_lastError = LWMQTT_NETWORK_FAILED_CONNECT;
315
299
return false ;
@@ -320,7 +304,7 @@ bool MQTTClient::connect(const char clientId[], const char username[], const cha
320
304
lwmqtt_options_t options = lwmqtt_default_options;
321
305
options.keep_alive = this ->keepAlive ;
322
306
options.clean_session = this ->cleanSession ;
323
- options.client_id = lwmqtt_string (clientId );
307
+ options.client_id = lwmqtt_string (clientID );
324
308
325
309
// set username and password if available
326
310
if (username != nullptr ) {
0 commit comments