Skip to content

Commit 0b387e5

Browse files
committed
MCU8MASS-1169 Publish every tenth second in connection loss sketch
1 parent 5174681 commit 0b387e5

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

examples/mqtt_with_connection_loss_handling/mqtt_with_connection_loss_handling.ino

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,26 @@ void loop() {
141141
}
142142
}
143143

144-
// if (millis() - timer > 10000) {
145-
if (connected_to_broker) {
146-
char message_to_publish[8] = {0};
147-
sprintf(message_to_publish, "%lu", counter);
148-
149-
bool published_successfully = MqttClient.publish(mqtt_pub_topic,
150-
message_to_publish,
151-
AT_LEAST_ONCE,
152-
60000);
153-
if (published_successfully) {
154-
Log.infof("Published message: %s. Failed publishes: %d.\r\n",
155-
message_to_publish,
156-
failed_publishes);
157-
} else {
158-
failed_publishes++;
144+
if (millis() - timer > 10000) {
145+
if (connected_to_broker) {
146+
char message_to_publish[8] = {0};
147+
sprintf(message_to_publish, "%lu", counter);
148+
149+
bool published_successfully = MqttClient.publish(mqtt_pub_topic,
150+
message_to_publish,
151+
AT_LEAST_ONCE,
152+
60000);
153+
if (published_successfully) {
154+
Log.infof("Published message: %s. Failed publishes: %d.\r\n",
155+
message_to_publish,
156+
failed_publishes);
157+
} else {
158+
failed_publishes++;
159+
}
160+
161+
counter++;
159162
}
160163

161-
counter++;
164+
timer = millis();
162165
}
163-
164-
timer = millis();
165-
// }
166166
}

0 commit comments

Comments
 (0)