Skip to content
Merged
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
20 changes: 13 additions & 7 deletions light-duino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ bool initializeMQTT() {

// define what to listen to
subscribeMQTTTopic(strTopicPrefixID + "set");


return true;
}
} else {
return true;
}
return true;
}
return false;
}
Expand Down Expand Up @@ -248,11 +250,15 @@ void setup() {

void loop() {
// check for connection and process MQTT
processMQTTLoop();

// process new mqtt messages
if (mqttNewMessage)
processMQTTMessage();
if (processMQTTLoop()) {
// MQTT connection is alive
// process new mqtt messages
if (mqttNewMessage)
processMQTTMessage();
} else {
// No MQTT Connection, reinitialize
initializeMQTT();
}

// check switches
if (switchesEnabled)
Expand Down
7 changes: 5 additions & 2 deletions mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ bool connectMQTT(String strUser, String strPass, String strHost, uint16_t port =
return MQTTconnected;
}

void processMQTTLoop() {
bool processMQTTLoop() {
// handle mqtt messages and wifi connection
if (mqttClient.connected())
if (mqttClient.connected()) {
mqttClient.loop();
return true;
}
return false;
}


Expand Down