@@ -140,23 +140,9 @@ MQTTClient::~MQTTClient() {
140140 free (this ->writeBuf );
141141}
142142
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) {
158144 // set client
159- this ->netClient = &client ;
145+ this ->netClient = &_client ;
160146
161147 // initialize client
162148 lwmqtt_init (&this ->client , this ->writeBuf , this ->bufSize , this ->readBuf , this ->bufSize );
@@ -190,10 +176,9 @@ void MQTTClient::setClockSource(MQTTClientClockSource cb) {
190176 this ->timer2 .millis = cb;
191177}
192178
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;
197182 this ->port = _port;
198183}
199184
@@ -292,7 +277,7 @@ bool MQTTClient::publish(const char topic[], const char payload[], int length, b
292277 return true ;
293278}
294279
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) {
296281 // close left open connection if still connected
297282 if (!skip && this ->connected ()) {
298283 this ->close ();
@@ -303,13 +288,12 @@ bool MQTTClient::connect(const char clientId[], const char username[], const cha
303288
304289 // connect to host
305290 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+ }
313297 if (ret <= 0 ) {
314298 this ->_lastError = LWMQTT_NETWORK_FAILED_CONNECT;
315299 return false ;
@@ -320,7 +304,7 @@ bool MQTTClient::connect(const char clientId[], const char username[], const cha
320304 lwmqtt_options_t options = lwmqtt_default_options;
321305 options.keep_alive = this ->keepAlive ;
322306 options.clean_session = this ->cleanSession ;
323- options.client_id = lwmqtt_string (clientId );
307+ options.client_id = lwmqtt_string (clientID );
324308
325309 // set username and password if available
326310 if (username != nullptr ) {
0 commit comments