From 2abe3b0aea4f2239b95f54785cc04d675f9bc937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 10 Feb 2017 12:37:22 +0100 Subject: [PATCH 1/2] Fix variable name bug --- code/espurna/emon.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/espurna/emon.ino b/code/espurna/emon.ino index 1f2edd99..bebd70f0 100644 --- a/code/espurna/emon.ino +++ b/code/espurna/emon.ino @@ -160,14 +160,14 @@ void powerMonitorLoop() { while ((unsigned char) *c == ' ') ++c; // Calculate average apparent power from current and create C-string - _power = (int) (current_avgd * mainsVoltage); + _power = (int) (average * mainsVoltage); char power[6]; snprintf(power, 6, "%d", _power); // Calculate energy increment (ppower times time) and create C-string double energy_inc = (double) _power * EMON_INTERVAL * EMON_MEASUREMENTS / 1000.0 / 3600.0; char energy_buf[11]; - dtostrf(energy_inc, 11, 3, energy_buf); + dtostrf(energy_inc, 10, 3, energy_buf); char *e = energy_buf; while ((unsigned char) *e == ' ') ++e; From b14f5cf6e6b8205bcde4008d8432d86a470144a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 10 Feb 2017 23:28:34 +0100 Subject: [PATCH 2/2] Check if there is an MQTT broker defined before the MQTT_MAX_TRIES check --- CHANGELOG.md | 4 ++++ README.md | 2 +- code/espurna/config/general.h | 2 +- code/espurna/config/version.h | 2 +- code/espurna/mqtt.ino | 6 ++++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e470cad0..0373ea6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.6.2] 2017-02-10 +### Fix +- Check if there is an MQTT broker defined before the MQTT_MAX_TRIES check + ## [1.6.1] 2017-02-10 ### Added - Added support for [Jorge Garcia's Wifi+Relay Board Kit](https://www.tindie.com/products/jorgegarciadev/wifi--relays-board-kit/) diff --git a/README.md b/README.md index 8276514d..5a997bbf 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8266 based smart switch It was originally developed with the **[IteadStudio Sonoff](https://www.itead.cc/sonoff-wifi-wireless-switch.html)** in mind but now it supports a growing number of ESP8266-based boards. It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. -**Current Release Version is 1.6.1**, read the [changelog](https://bitbucket.org/xoseperez/espurna/src/master/CHANGELOG.md). +**Current Release Version is 1.6.2**, read the [changelog](https://bitbucket.org/xoseperez/espurna/src/master/CHANGELOG.md). ## Features diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 1c1c29f9..53f65857 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -103,7 +103,7 @@ #define MQTT_KEEPALIVE 30 #define MQTT_RECONNECT_DELAY 10000 #define MQTT_TRY_INTERVAL 30000 -#define MQTT_MAX_TRIES 5 +#define MQTT_MAX_TRIES 12 #define MQTT_SKIP_RETAINED 1 #define MQTT_SKIP_TIME 1000 #define MQTT_ACTION_TOPIC "/action" diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index d1118691..772d985a 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "ESPurna" -#define APP_VERSION "1.6.1" +#define APP_VERSION "1.6.2" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 417aa252..23b3e458 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -139,12 +139,16 @@ void mqttConnect() { if (!mqtt.connected()) { + char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); + if (strlen(host) == 0) return; + // Last option: reconnect to wifi after MQTT_MAX_TRIES attemps in a row #if MQTT_MAX_TRIES > 0 static unsigned int tries = 0; static unsigned long last_try = millis(); if (millis() - last_try < MQTT_TRY_INTERVAL) { if (++tries > MQTT_MAX_TRIES) { + DEBUG_MSG("[MQTT] MQTT_MAX_TRIES met, disconnecting from WiFi\n"); wifiDisconnect(); tries = 0; return; @@ -157,8 +161,6 @@ void mqttConnect() { mqtt.disconnect(); - char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); - if (strlen(host) == 0) return; unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); char * user = strdup(getSetting("mqttUser").c_str()); char * pass = strdup(getSetting("mqttPassword").c_str());