@@ -171,9 +171,9 @@ int MqttClient::messageRetain() const
171171 return -1 ;
172172}
173173
174- int MqttClient::beginMessage (const char * topic, unsigned long size, bool retain, uint8_t qos, bool dup)
174+ int MqttClient::beginMessage (const String& topic, unsigned long size, bool retain, uint8_t qos, bool dup)
175175{
176- _txMessageTopic = topic;
176+ _txMessageTopic = topic. c_str () ;
177177 _txMessageRetain = retain;
178178 _txMessageQoS = qos;
179179 _txMessageDup = dup;
@@ -191,19 +191,9 @@ int MqttClient::beginMessage(const char* topic, unsigned long size, bool retain,
191191 return 1 ;
192192}
193193
194- int MqttClient::beginMessage (const String& topic, unsigned long size, bool retain, uint8_t qos, bool dup)
195- {
196- return beginMessage (topic.c_str (), size, retain, qos, dup);
197- }
198-
199- int MqttClient::beginMessage (const char * topic, bool retain, uint8_t qos, bool dup)
200- {
201- return beginMessage (topic, 0xffffffffL , retain, qos, dup);
202- }
203-
204194int MqttClient::beginMessage (const String& topic, bool retain, uint8_t qos, bool dup)
205195{
206- return beginMessage (topic. c_str () , retain, qos, dup);
196+ return beginMessage (topic, 0xffffffffL , retain, qos, dup);
207197}
208198
209199int MqttClient::endMessage ()
@@ -259,9 +249,9 @@ int MqttClient::endMessage()
259249 return 1 ;
260250}
261251
262- int MqttClient::beginWill (const char * topic, unsigned short size, bool retain, uint8_t qos)
252+ int MqttClient::beginWill (const String& topic, unsigned short size, bool retain, uint8_t qos)
263253{
264- int topicLength = strlen ( topic);
254+ int topicLength = topic. length ( );
265255 size_t willLength = (2 + topicLength + 2 + size);
266256
267257 if (qos > 2 ) {
@@ -272,7 +262,7 @@ int MqttClient::beginWill(const char* topic, unsigned short size, bool retain, u
272262
273263 _txBuffer = _willBuffer;
274264 _txBufferIndex = 0 ;
275- writeString (topic, topicLength );
265+ writeString (topic. c_str (), topic. length () );
276266 write16 (0 ); // dummy size for now
277267 _willMessageIndex = _txBufferIndex;
278268
@@ -284,19 +274,9 @@ int MqttClient::beginWill(const char* topic, unsigned short size, bool retain, u
284274 return 0 ;
285275}
286276
287- int MqttClient::beginWill (const String& topic, unsigned short size, bool retain, uint8_t qos)
288- {
289- return beginWill (topic.c_str (), size, retain, qos);
290- }
291-
292- int MqttClient::beginWill (const char * topic, bool retain, uint8_t qos)
293- {
294- return beginWill (topic, _tx_payload_buffer_size, retain, qos);
295- }
296-
297277int MqttClient::beginWill (const String& topic, bool retain, uint8_t qos)
298278{
299- return beginWill (topic. c_str () , retain, qos);
279+ return beginWill (topic, _tx_payload_buffer_size , retain, qos);
300280}
301281
302282int MqttClient::endWill ()
@@ -314,9 +294,10 @@ int MqttClient::endWill()
314294 return 1 ;
315295}
316296
317- int MqttClient::subscribe (const char * topic, uint8_t qos)
297+ int MqttClient::subscribe (const String& topic, uint8_t qos)
298+
318299{
319- int topicLength = strlen ( topic);
300+ int topicLength = topic. length ( );
320301 int remainingLength = topicLength + 5 ;
321302
322303 if (qos > 2 ) {
@@ -334,7 +315,7 @@ int MqttClient::subscribe(const char* topic, uint8_t qos)
334315
335316 beginPacket (MQTT_SUBSCRIBE, 0x02 , remainingLength, packetBuffer);
336317 write16 (_txPacketId);
337- writeString (topic, topicLength);
318+ writeString (topic. c_str () , topicLength);
338319 write8 (qos);
339320
340321 if (!endPacket ()) {
@@ -362,14 +343,9 @@ int MqttClient::subscribe(const char* topic, uint8_t qos)
362343 return 0 ;
363344}
364345
365- int MqttClient::subscribe (const String& topic, uint8_t qos)
366- {
367- return subscribe (topic.c_str (), qos);
368- }
369-
370- int MqttClient::unsubscribe (const char * topic)
346+ int MqttClient::unsubscribe (const String& topic)
371347{
372- int topicLength = strlen ( topic);
348+ int topicLength = topic. length ( );
373349 int remainingLength = topicLength + 4 ;
374350
375351 _txPacketId++;
@@ -382,7 +358,7 @@ int MqttClient::unsubscribe(const char* topic)
382358
383359 beginPacket (MQTT_UNSUBSCRIBE, 0x02 , remainingLength, packetBuffer);
384360 write16 (_txPacketId);
385- writeString (topic, topicLength);
361+ writeString (topic. c_str () , topicLength);
386362
387363 if (!endPacket ()) {
388364 stop ();
@@ -406,11 +382,6 @@ int MqttClient::unsubscribe(const char* topic)
406382 return 0 ;
407383}
408384
409- int MqttClient::unsubscribe (const String& topic)
410- {
411- return unsubscribe (topic.c_str ());
412- }
413-
414385void MqttClient::poll ()
415386{
416387 if (clientAvailable () == 0 && !clientConnected ()) {
@@ -775,22 +746,11 @@ MqttClient::operator bool()
775746 return true ;
776747}
777748
778- void MqttClient::setId (const char * id)
779- {
780- _id = id;
781- }
782-
783749void MqttClient::setId (const String& id)
784750{
785751 _id = id;
786752}
787753
788- void MqttClient::setUsernamePassword (const char * username, const char * password)
789- {
790- _username = username;
791- _password = password;
792- }
793-
794754void MqttClient::setUsernamePassword (const String& username, const String& password)
795755{
796756 _username = username;
0 commit comments