Skip to content

Commit

Permalink
Fixed memory leak problem; Use new method of checking WiFi connectivi…
Browse files Browse the repository at this point in the history
…ty - should be more reliable; Version bump;
  • Loading branch information
epiller committed Feb 24, 2021
1 parent bbe1a40 commit 433744c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AllThingsTalk WiFi SDK
version=2.1.1
version=2.1.2
author=AllThingsTalk <[email protected]>
maintainer=Vanja <[email protected]>
sentence=Connect and control your device with AllThingsTalk
Expand Down
18 changes: 9 additions & 9 deletions src/ATT_ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void Device::disconnect() {

// Main method to connect to WiFi
void Device::connectWiFi() {
if (WiFi.status() != WL_CONNECTED) {
if (!WiFi.localIP().isSet()) {
connectionLedFadeStart();
WiFi.mode(WIFI_STA);
if (wifiHostnameSet) {
Expand All @@ -289,7 +289,7 @@ void Device::connectWiFi() {
debug("Connecting to WiFi:", ' ');
debug(wifiCreds->getSsid(), '.');
WiFi.begin(wifiCreds->getSsid(), wifiCreds->getPassword());
while (WiFi.status() != WL_CONNECTED) {
while (!WiFi.localIP().isSet()) {
debug("", '.');
delay(10000);
}
Expand All @@ -307,7 +307,7 @@ void Device::connectWiFi() {
// Checks and recovers WiFi if lost
void Device::maintainWiFi() {
if (!disconnectedWiFi) {
if (WiFi.status() != WL_CONNECTED) {
if (!WiFi.localIP().isSet()) {
connectionLedFadeStart();
debug("WiFi Connection Dropped! Reason:", ' ');
switch(WiFi.status()) {
Expand Down Expand Up @@ -349,7 +349,7 @@ void Device::maintainWiFi() {

// Main method for disconnecting from WiFi
void Device::disconnectWiFi() {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.localIP().isSet()) {
disconnectAllThingsTalk();
WiFi.disconnect();
disconnectedWiFi = true;
Expand Down Expand Up @@ -516,7 +516,7 @@ void Device::connectAllThingsTalk() {
connectWiFi(); // WiFi needs to be present of course
debug("Connecting to AllThingsTalk", '.');
while (!client.connected()) {
if (WiFi.status() != WL_CONNECTED) {
if (!WiFi.localIP().isSet()) {
debug(" "); // Cosmetic only.
maintainWiFi(); // In case WiFi connection is lost while connecting to ATT
}
Expand Down Expand Up @@ -605,7 +605,7 @@ void Device::disconnectAllThingsTalk() {

// Called from loop; Reports wifi signal to ATTalk Maker at specified interval
void Device::reportWiFiSignal() {
if (rssiReporting && WiFi.status() == WL_CONNECTED) {
if (rssiReporting && WiFi.localIP().isSet()) {
if (millis() - rssiPrevTime >= rssiReportInterval*1000) {
send(wifiSignalAsset, wifiSignal());
rssiPrevTime = millis();
Expand Down Expand Up @@ -861,7 +861,7 @@ void Device::mqttCallback(char* p_topic, byte* p_payload, unsigned int p_length)

// Send data as CBOR
bool Device::send(CborPayload &payload) {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.localIP().isSet()) {
if (client.connected()) {
char topic[128];
snprintf(topic, sizeof topic, "%s%s%s", "device/", deviceCreds->getDeviceId(), "/state");
Expand All @@ -880,7 +880,7 @@ bool Device::send(CborPayload &payload) {

// Send data as Binary Payload
bool Device::send(BinaryPayload &payload) {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.localIP().isSet()) {
if (client.connected()) {
char topic[128];
snprintf(topic, sizeof topic, "%s%s%s", "device/", deviceCreds->getDeviceId(), "/state");
Expand All @@ -898,7 +898,7 @@ bool Device::send(BinaryPayload &payload) {
}

template<typename T> bool Device::send(char *asset, T payload) {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.localIP().isSet()) {
if (client.connected()) {
char topic[128];
snprintf(topic, sizeof topic, "%s%s%s%s%s", "device/", deviceCreds->getDeviceId(), "/asset/", asset, "/state");
Expand Down
2 changes: 2 additions & 0 deletions src/CborPayload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CborPayload::~CborPayload() {
}

void CborPayload::reset() {
delete writer;
delete output;
output = new CborStaticOutput(buffer, capacity);
writer = new CborWriter(*output);
assetCount = 0;
Expand Down

0 comments on commit 433744c

Please sign in to comment.