@@ -35,6 +35,15 @@ void QueueManager::setupMQTTQueue(void (*callback)(char*, byte*, unsigned int))
35
35
36
36
}
37
37
38
+ /* ********************************* SET LAST WILL PARAMETERS **********************************/
39
+ void QueueManager::setMQTTWill (const char *topic, const char *payload, const int qos, boolean retain, boolean cleanSession){
40
+ mqttWillTopic = topic;
41
+ mqttWillPayload = payload;
42
+ mqttWillQOS = qos;
43
+ mqttWillRetain = retain;
44
+ mqttCleanSession = cleanSession;
45
+ }
46
+
38
47
/* ********************************* MQTT RECONNECT **********************************/
39
48
void QueueManager::mqttReconnect (void (*manageDisconnections)(), void (*manageQueueSubscription)(), void (*manageHardwareButton)()) {
40
49
@@ -60,10 +69,23 @@ void QueueManager::mqttReconnect(void (*manageDisconnections)(), void (*manageQu
60
69
61
70
// Attempt to connect to MQTT server with QoS = 1 (pubsubclient supports QoS 1 for subscribe only, published msg have QoS 0 this is why I implemented a custom solution)
62
71
boolean mqttSuccess;
72
+
73
+ Serial.println (" MQTT Last Will Params: " );
74
+ Serial.print (" willTopic: " );
75
+ Serial.println (mqttWillTopic);
76
+ Serial.print (" willPayload: " );
77
+ Serial.println (mqttWillPayload);
78
+ Serial.print (" qos: " );
79
+ Serial.println (mqttWillQOS);
80
+ Serial.print (" retain: " );
81
+ Serial.println (mqttWillRetain);
82
+ Serial.print (" clean session: " );
83
+ Serial.println (mqttCleanSession);
84
+
63
85
if (mqttuser.isEmpty () || mqttpass.isEmpty ()) {
64
- mqttSuccess = mqttClient.connect (helper.string2char (deviceName), 0 , 1 , 0 , 0 );
86
+ mqttSuccess = mqttClient.connect (helper.string2char (deviceName), helper. string2char (mqttWillTopic), mqttWillQOS, mqttWillRetain, helper. string2char (mqttWillPayload) );
65
87
} else {
66
- mqttSuccess = mqttClient.connect (helper.string2char (deviceName), helper.string2char (mqttuser), helper.string2char (mqttpass), 0 , 1 , 0 , 0 , 1 );
88
+ mqttSuccess = mqttClient.connect (helper.string2char (deviceName), helper.string2char (mqttuser), helper.string2char (mqttpass), helper. string2char (mqttWillTopic), mqttWillQOS, mqttWillRetain, helper. string2char (mqttWillPayload), mqttCleanSession );
67
89
}
68
90
if (mqttSuccess) {
69
91
0 commit comments