Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/MQTT.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace MQTT {
uint32_t len = 2 + _clientid.length();
if (_will_topic.length()) {
len += 2 + _will_topic.length();
len += 2 + _will_message.length();
len += 2 + _will_length;
}
if (_username.length()) {
len += 2 + _username.length();
Expand All @@ -325,7 +325,8 @@ namespace MQTT {

if (_will_topic.length()) {
write(buf, bufpos, _will_topic);
write(buf, bufpos, _will_message);
write(buf, bufpos, _will_length);
write(buf, bufpos, _will_message, _will_length);
}

if (_username.length()) {
Expand Down
11 changes: 9 additions & 2 deletions src/MQTT.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ namespace MQTT {

String _clientid;
String _will_topic;
String _will_message;
uint8_t* _will_message;
uint16_t _will_length;
String _username, _password;

uint16_t _keepalive;
Expand All @@ -185,9 +186,15 @@ namespace MQTT {

//! Set the "will" flag and associated attributes
Connect& set_will(String willTopic, String willMessage, uint8_t willQos = 0, bool willRetain = false) {
_will_topic = willTopic; _will_message = willMessage; _will_qos = willQos; _will_retain = willRetain;
_will_topic = willTopic; _will_message = (uint8_t*)willMessage.c_str(); _will_length = willMessage.length(); _will_qos = willQos; _will_retain = willRetain;
return *this;
}
//! Set the "will" flag and associated attributes
Connect& set_will(String willTopic, uint8_t* willMessage, uint16_t willLength, uint8_t willQos = 0, bool willRetain = false) {
_will_topic = willTopic; _will_message = willMessage; _will_length = willLength; _will_qos = willQos; _will_retain = willRetain;
return *this;
}

//! Unset the "will" flag and associated attributes
Connect& unset_will(void) { _will_topic = ""; return *this; }

Expand Down