@@ -231,16 +231,6 @@ bool isPrivateIpAddress(const IPAddress &ip)
231231 }
232232 return false ;
233233}
234-
235- std::pair<std::string, uint16_t > parseHostAndPort (std::string address, uint16_t port = 0 )
236- {
237- const size_t delimIndex = address.find_first_of (' :' );
238- if (delimIndex > 0 ) {
239- port = std::stoul (address.substr (delimIndex + 1 , address.length ()));
240- address.resize (delimIndex);
241- }
242- return std::make_pair (std::move (address), port);
243- }
244234} // namespace
245235
246236void MQTT::mqttCallback (char *topic, byte *payload, unsigned int length)
@@ -318,8 +308,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
318308 }
319309
320310 IPAddress ip;
321- isMqttServerAddressPrivate =
322- ip.fromString (parseHostAndPort (moduleConfig.mqtt .address ).first .c_str ()) && isPrivateIpAddress (ip);
311+ isMqttServerAddressPrivate = ip.fromString (moduleConfig.mqtt .address ) && isPrivateIpAddress (ip);
323312
324313#if HAS_NETWORKING
325314 if (!moduleConfig.mqtt .proxy_to_client_enabled )
@@ -435,9 +424,14 @@ void MQTT::reconnect()
435424 pubSub.setClient (mqttClient);
436425#endif
437426
438- std::pair<std::string, uint16_t > hostAndPort = parseHostAndPort (serverAddr, serverPort);
439- serverAddr = hostAndPort.first .c_str ();
440- serverPort = hostAndPort.second ;
427+ String server = String (serverAddr);
428+ int delimIndex = server.indexOf (' :' );
429+ if (delimIndex > 0 ) {
430+ String port = server.substring (delimIndex + 1 , server.length ());
431+ server[delimIndex] = 0 ;
432+ serverPort = port.toInt ();
433+ serverAddr = server.c_str ();
434+ }
441435 pubSub.setServer (serverAddr, serverPort);
442436 pubSub.setBufferSize (512 );
443437
0 commit comments