Skip to content

Commit 8b7cc68

Browse files
committed
MCU8MASS-1169 Add example for MQTT with connection loss
1 parent 9b1c79e commit 8b7cc68

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

examples/mqtt_with_connection_loss_handling/mqtt_with_connection_loss_handling.ino

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
#include <led_ctrl.h>
1010
#include <log.h>
1111
#include <lte.h>
12-
#include <mcp9808.h>
1312
#include <mqtt_client.h>
1413
#include <sequans_controller.h>
15-
#include <veml3328.h>
1614

1715
#define MQTT_PUB_TOPIC_FMT "%s/sensors"
1816

@@ -127,6 +125,7 @@ static uint32_t failed_publishes = 0;
127125
static uint32_t timer = 0;
128126

129127
void loop() {
128+
130129
if (!connecteded_to_network) {
131130
Log.info("Not connected to the network. Attempting to connect!");
132131
if (connectLTE()) {
@@ -142,26 +141,26 @@ void loop() {
142141
}
143142
}
144143

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

165-
timer = millis();
161+
counter++;
166162
}
163+
164+
timer = millis();
165+
// }
167166
}

0 commit comments

Comments
 (0)