Skip to content

Commit

Permalink
Klimerko Firmware v1.3.1
Browse files Browse the repository at this point in the history
- Utilize new version of AllThingsTalk WiFi SDK (v2.1.2) which fixes a memory leak issue and utilizes a new way of checking if WiFi is connected.
- Minor fixes to variable types & ogranization
- Update website link
  • Loading branch information
epiller committed Feb 24, 2021
1 parent 3080f61 commit e61381f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
49 changes: 24 additions & 25 deletions Klimerko_Firmware/Klimerko_Firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@
#include <Wire.h>
#include <EEPROM.h>

String firmwareVersion = "1.3.0";
int sendInterval = 15; // [MINUTES] Default sensor data sending interval
int wakeInterval = 30; // [SECONDS] Seconds to activate sensor before reading it
int averageSamples = 10; // Number of samples used to average values from sensors
int deviceRestartWait = 3; // Seconds to wait when restarting NodeMCU
bool noSleep = false;
// Pins to which the PMS7003 is connected to
const uint8_t pmsTX = D5;
const uint8_t pmsRX = D6;
const char *airQuality, *airQualityRaw;
unsigned long currentTime, lastReadTime, lastSendTime;
int avgTemperature, avgHumidity, avgPressure, avgPM1, avgPM25, avgPM10;
String firmwareVersion = "1.3.1";
uint8_t sendInterval = 15; // [MINUTES] Default sensor data sending interval
const uint8_t wakeInterval = 30; // [SECONDS] Seconds to activate sensor before reading it
const uint8_t averageSamples = 10; // Number of samples used to average values from sensors
const uint8_t deviceRestartWait = 3; // Seconds to wait when restarting NodeMCU
const uint8_t pmsTX = D5;
const uint8_t pmsRX = D6;
bool noSleep = false;
bool firstReading = true;
bool pmsWoken = false;
bool pmsWoken = false;
const char *airQuality, *airQualityRaw;
String wifiName, wifiPassword, deviceId, deviceToken;
String wifiNameTemp, wifiPasswordTemp, deviceIdTemp, deviceTokenTemp;
int wifiName_EEPROM_begin = 0;
int wifiName_EEPROM_end = 255;
int wifiPassword_EEPROM_begin = 256;
int wifiPassword_EEPROM_end = 511;
int deviceId_EEPROM_begin = 512;
int deviceId_EEPROM_end = 767;
int deviceToken_EEPROM_begin = 768;
int deviceToken_EEPROM_end = 1024;
int EEPROMsize = 1024;
String dataDivider = ";";
int avgTemperature, avgHumidity, avgPressure, avgPM1, avgPM25, avgPM10;
unsigned long currentTime, lastReadTime, lastSendTime;
// Memory addresses
const uint16_t wifiName_EEPROM_begin = 0;
const uint16_t wifiName_EEPROM_end = 255;
const uint16_t wifiPassword_EEPROM_begin = 256;
const uint16_t wifiPassword_EEPROM_end = 511;
const uint16_t deviceId_EEPROM_begin = 512;
const uint16_t deviceId_EEPROM_end = 767;
const uint16_t deviceToken_EEPROM_begin = 768;
const uint16_t deviceToken_EEPROM_end = 1024;
const uint16_t EEPROMsize = 1024;
String dataDivider = ";";
// Assets to be published to
char* PM1_ASSET = "pm1";
char* PM2_5_ASSET = "pm2-5";
Expand Down Expand Up @@ -99,7 +99,7 @@ void setup() {
Serial.println("");
Serial.println(" ------------------------- Project 'KLIMERKO' ----------------------------");
Serial.println("| https://github.com/DesconBelgrade/Klimerko |");
Serial.println("| www.vazduhgradjanima.rs |");
Serial.println("| www.klimerko.org |");
Serial.print("| Firmware Version: ");
Serial.print(firmwareVersion);
Serial.println(" |");
Expand Down Expand Up @@ -300,7 +300,6 @@ void pmsPower(bool state) {
while(millis() < now + 100);
pmsWoken = false;
pms.sleep();

}
}

Expand Down
18 changes: 9 additions & 9 deletions Klimerko_Firmware/src/AllThingsTalk/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 Klimerko_Firmware/src/AllThingsTalk/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
2 changes: 1 addition & 1 deletion Klimerko_Firmware/src/AllThingsTalk/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AllThingsTalk WiFi SDK
version=2.1
version=2.1.2
author=AllThingsTalk <support@allthingstalk.com>
maintainer=Vanja <vanja@allthingstalk.com>
sentence=Connect and control your device with AllThingsTalk
Expand Down

0 comments on commit e61381f

Please sign in to comment.