Skip to content

Commit 3327b25

Browse files
committed
Utilize millis() instead of delay for sending payloads. Fixed memory leak issues. Version bump.
1 parent 3848f59 commit 3327b25

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

examples/Rapid Development Kit/MonitorPerishableGoods/MonitorPerishableGoods.ino

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Adafruit_BME280 tph1;
5555
BME280 tph2;
5656
LED led;
5757

58-
unsigned long previousMillis;
58+
int publishInterval = 60; // Seconds between data publishing
59+
unsigned long previousPublishTime;
5960
float temperature, humidity;
6061
uint8_t sensorType;
6162

@@ -110,24 +111,26 @@ void setSetupError(char* message) {
110111

111112
void loop() {
112113
att.loop(); // Keep the network and connection to AllThingsTalk alive
113-
led.setLight(led.YELLOW);
114-
readTphData();
115-
delay(1000);
116-
led.setLight(led.OFF);
117-
payload.reset();
118-
payload.set("temp", temperature);
119-
payload.set("hum", humidity);
120-
debugSerial.print("Temperature: ");
121-
debugSerial.println(temperature);
122-
debugSerial.print("Humidity: ");
123-
debugSerial.println(humidity);
124-
led.setLight(led.WHITE);
125-
if (att.send(payload)) {
126-
led.setLight(led.GREEN, true);
127-
} else {
128-
led.setLight(led.RED, true);
114+
if (millis() - previousPublishTime >= publishInterval*1000) {
115+
led.setLight(led.YELLOW);
116+
readTphData();
117+
delay(1000);
118+
led.setLight(led.OFF);
119+
payload.reset();
120+
payload.set("temp", temperature);
121+
payload.set("hum", humidity);
122+
debugSerial.print("Temperature: ");
123+
debugSerial.println(temperature);
124+
debugSerial.print("Humidity: ");
125+
debugSerial.println(humidity);
126+
led.setLight(led.WHITE);
127+
if (att.send(payload)) {
128+
led.setLight(led.GREEN, true);
129+
} else {
130+
led.setLight(led.RED, true);
131+
}
132+
delay(1000);
133+
led.setLight(led.OFF);
134+
previousPublishTime = millis();
129135
}
130-
delay(1000);
131-
led.setLight(led.OFF);
132-
delay(30000);
133136
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AllThingsTalk LTE-M SDK
2-
version=2.0.2
2+
version=2.0.3
33
author=AllThingsTalk <support@allthingstalk.com>
44
maintainer=Vanja <vanja@allthingstalk.com>
55
sentence=Connect your LTE-M enabled Arduino device to AllThingsTalk IoT Platform.

src/AllThingsTalk_LTEM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ bool AllThingsTalk_LTEM::send(CborPayload &payload) {
202202
debug("> Failed to Publish Message to AllThingsTalk (CBOR)");
203203
return false;
204204
}
205+
delete topic;
205206
}
206207
} else {
207208
debug("You're trying to send a message but you've disconnected from the network. Execute connect() to re-connect.");

src/CborPayload.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ CborPayload::~CborPayload() {
1616
}
1717

1818
void CborPayload::reset() {
19+
delete writer;
20+
delete output;
1921
output = new CborStaticOutput(buffer, capacity);
2022
writer = new CborWriter(*output);
2123
assetCount = 0;

0 commit comments

Comments
 (0)