@@ -171,9 +171,9 @@ int MqttClient::messageRetain() const
171
171
return -1 ;
172
172
}
173
173
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)
175
175
{
176
- _txMessageTopic = topic;
176
+ _txMessageTopic = topic. c_str () ;
177
177
_txMessageRetain = retain;
178
178
_txMessageQoS = qos;
179
179
_txMessageDup = dup;
@@ -191,19 +191,9 @@ int MqttClient::beginMessage(const char* topic, unsigned long size, bool retain,
191
191
return 1 ;
192
192
}
193
193
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
-
204
194
int MqttClient::beginMessage (const String& topic, bool retain, uint8_t qos, bool dup)
205
195
{
206
- return beginMessage (topic. c_str () , retain, qos, dup);
196
+ return beginMessage (topic, 0xffffffffL , retain, qos, dup);
207
197
}
208
198
209
199
int MqttClient::endMessage ()
@@ -259,9 +249,9 @@ int MqttClient::endMessage()
259
249
return 1 ;
260
250
}
261
251
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)
263
253
{
264
- int topicLength = strlen ( topic);
254
+ int topicLength = topic. length ( );
265
255
size_t willLength = (2 + topicLength + 2 + size);
266
256
267
257
if (qos > 2 ) {
@@ -272,7 +262,7 @@ int MqttClient::beginWill(const char* topic, unsigned short size, bool retain, u
272
262
273
263
_txBuffer = _willBuffer;
274
264
_txBufferIndex = 0 ;
275
- writeString (topic, topicLength );
265
+ writeString (topic. c_str (), topic. length () );
276
266
write16 (0 ); // dummy size for now
277
267
_willMessageIndex = _txBufferIndex;
278
268
@@ -284,19 +274,9 @@ int MqttClient::beginWill(const char* topic, unsigned short size, bool retain, u
284
274
return 0 ;
285
275
}
286
276
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
-
297
277
int MqttClient::beginWill (const String& topic, bool retain, uint8_t qos)
298
278
{
299
- return beginWill (topic. c_str () , retain, qos);
279
+ return beginWill (topic, _tx_payload_buffer_size , retain, qos);
300
280
}
301
281
302
282
int MqttClient::endWill ()
@@ -314,9 +294,10 @@ int MqttClient::endWill()
314
294
return 1 ;
315
295
}
316
296
317
- int MqttClient::subscribe (const char * topic, uint8_t qos)
297
+ int MqttClient::subscribe (const String& topic, uint8_t qos)
298
+
318
299
{
319
- int topicLength = strlen ( topic);
300
+ int topicLength = topic. length ( );
320
301
int remainingLength = topicLength + 5 ;
321
302
322
303
if (qos > 2 ) {
@@ -334,7 +315,7 @@ int MqttClient::subscribe(const char* topic, uint8_t qos)
334
315
335
316
beginPacket (MQTT_SUBSCRIBE, 0x02 , remainingLength, packetBuffer);
336
317
write16 (_txPacketId);
337
- writeString (topic, topicLength);
318
+ writeString (topic. c_str () , topicLength);
338
319
write8 (qos);
339
320
340
321
if (!endPacket ()) {
@@ -362,14 +343,9 @@ int MqttClient::subscribe(const char* topic, uint8_t qos)
362
343
return 0 ;
363
344
}
364
345
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)
371
347
{
372
- int topicLength = strlen ( topic);
348
+ int topicLength = topic. length ( );
373
349
int remainingLength = topicLength + 4 ;
374
350
375
351
_txPacketId++;
@@ -382,7 +358,7 @@ int MqttClient::unsubscribe(const char* topic)
382
358
383
359
beginPacket (MQTT_UNSUBSCRIBE, 0x02 , remainingLength, packetBuffer);
384
360
write16 (_txPacketId);
385
- writeString (topic, topicLength);
361
+ writeString (topic. c_str () , topicLength);
386
362
387
363
if (!endPacket ()) {
388
364
stop ();
@@ -406,11 +382,6 @@ int MqttClient::unsubscribe(const char* topic)
406
382
return 0 ;
407
383
}
408
384
409
- int MqttClient::unsubscribe (const String& topic)
410
- {
411
- return unsubscribe (topic.c_str ());
412
- }
413
-
414
385
void MqttClient::poll ()
415
386
{
416
387
if (clientAvailable () == 0 && !clientConnected ()) {
@@ -775,22 +746,11 @@ MqttClient::operator bool()
775
746
return true ;
776
747
}
777
748
778
- void MqttClient::setId (const char * id)
779
- {
780
- _id = id;
781
- }
782
-
783
749
void MqttClient::setId (const String& id)
784
750
{
785
751
_id = id;
786
752
}
787
753
788
- void MqttClient::setUsernamePassword (const char * username, const char * password)
789
- {
790
- _username = username;
791
- _password = password;
792
- }
793
-
794
754
void MqttClient::setUsernamePassword (const String& username, const String& password)
795
755
{
796
756
_username = username;
0 commit comments