@@ -143,27 +143,18 @@ MQTTClient::~MQTTClient() {
143143void MQTTClient::begin (IPAddress ipAddr, int port, Client &client) {
144144 // set hostname and port
145145 this ->setHost (ipAddr, port);
146-
147- // set client
148- this ->netClient = &client;
149-
150- // initialize client
151- lwmqtt_init (&this ->client , this ->writeBuf , this ->bufSize , this ->readBuf , this ->bufSize );
152-
153- // set timers
154- lwmqtt_set_timers (&this ->client , &this ->timer1 , &this ->timer2 , lwmqtt_arduino_timer_set, lwmqtt_arduino_timer_get);
155-
156- // set network
157- lwmqtt_set_network (&this ->client , &this ->network , lwmqtt_arduino_network_read, lwmqtt_arduino_network_write);
158-
159- // set callback
160- lwmqtt_set_callback (&this ->client , (void *)&this ->callback , MQTTClientHandler);
146+ // finish up begin() call
147+ _begin (port, client);
161148}
162149
163150void MQTTClient::begin (const char hostname[], int port, Client &client) {
164151 // set hostname and port
165152 this ->setHost (hostname, port);
153+ // finish up begin() call
154+ _begin (port, client);
155+ }
166156
157+ void MQTTClient::_begin (int port, Client &client){
167158 // set client
168159 this ->netClient = &client;
169160
@@ -199,11 +190,11 @@ void MQTTClient::setClockSource(MQTTClientClockSource cb) {
199190 this ->timer2 .millis = cb;
200191}
201192
202- void MQTTClient::setHost (IPAddress ipAddr , int port ) {
193+ void MQTTClient::setHost (IPAddress _ipAddr , int _port ) {
203194 // set hostname and port
204- this ->ipaddress = ipAddr ;
195+ this ->ipaddress = _ipAddr ;
205196
206- this ->port = port ;
197+ this ->port = _port ;
207198}
208199
209200void MQTTClient::setHost (const char _hostname[], int _port) {
@@ -316,13 +307,7 @@ bool MQTTClient::connect(const char clientId[], const char username[], const cha
316307 if (this ->hostname != nullptr ){
317308 ret = this ->netClient ->connect (this ->hostname , (uint16_t )this ->port );
318309 }else {
319- uint32_t thisIP = 0 ;
320- thisIP = ipaddress[0 ];
321- thisIP |= uint32_t (ipaddress[1 ] << 8 );
322- thisIP |= uint32_t (ipaddress[2 ] << 16 );
323- thisIP |= uint32_t (ipaddress[3 ] << 24 );
324-
325- ret = this ->netClient ->connect (thisIP, (uint16_t )this ->port );
310+ ret = this ->netClient ->connect (this ->ipaddress , (uint16_t )this ->port );
326311 }
327312
328313 if (ret <= 0 ) {
0 commit comments