From cdc98e1cb54253e742160c9b0112b5a36c6c6106 Mon Sep 17 00:00:00 2001 From: "Mitchell A. Cox" Date: Sun, 8 Oct 2017 14:42:11 +0200 Subject: [PATCH 1/7] Added ESPLive board --- code/espurna/config/hardware.h | 28 ++++++++++++++++++++++++++++ code/espurna/hardware.ino | 12 ++++++++++++ 2 files changed, 40 insertions(+) diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index fe35cd67..5b64f19a 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -876,6 +876,34 @@ #define ECH1560_MISO_PIN 5 #define ECH1560_INVERTED 0 +// ----------------------------------------------------------------------------- +// ESPLive +// https://github.com/ManCaveMade/ESP-Live +// ----------------------------------------------------------------------------- + +#elif defined(ESPLIVE) + + // Info + #define MANUFACTURER "ManCave Made" + #define DEVICE "ESPLIVE" + + // Buttons + #define BUTTON1_PIN 4 + #define BUTTON2_PIN 5 + + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + #define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + + #define BUTTON1_RELAY 1 + #define BUTTON2_RELAY 2 + + // Relays + #define RELAY1_PIN 12 + #define RELAY2_PIN 13 + + #define RELAY1_TYPE RELAY_TYPE_NORMAL + #define RELAY2_TYPE RELAY_TYPE_NORMAL + // ----------------------------------------------------------------------------- // Unknown hardware // ----------------------------------------------------------------------------- diff --git a/code/espurna/hardware.ino b/code/espurna/hardware.ino index d11f6a7d..7ede77d7 100644 --- a/code/espurna/hardware.ino +++ b/code/espurna/hardware.ino @@ -442,6 +442,18 @@ void hwUpwardsCompatibility() { setSetting("board", 38); + #elif defined(ESPLIVE) + + setSetting("board", 39); + setSetting("btnGPIO", 1, 4); + setSetting("btnGPIO", 2, 5); + setSetting("btnRelay", 1, 1); + setSetting("btnRelay", 2, 2); + setSetting("relayGPIO", 1, 12); + setSetting("relayGPIO", 2, 13); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); + #else #error "UNSUPPORTED HARDWARE!" From 0d08dbdf040eb335bcb8382b3439c269bab8eae6 Mon Sep 17 00:00:00 2001 From: "Mitchell A. Cox" Date: Sun, 8 Oct 2017 14:52:59 +0200 Subject: [PATCH 2/7] ESPlive ADC config --- code/espurna/espurna.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 24d95adc..8676a259 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -43,6 +43,11 @@ void hardwareSetup() { SPIFFS.begin(); #endif + #if defined(EPSLIVE) + //The ESPLive has an ADC MUX which needs to be configured. + pinMode(16, OUTPUT); + digitalWrite(16, HIGH); //Defualt CT input (pin B, solder jumper B) + #endif } void hardwareLoop() { From e104319a30bcdbf96d49f1aaf0b58122a82957e1 Mon Sep 17 00:00:00 2001 From: "Mitchell A. Cox" Date: Sun, 8 Oct 2017 14:59:12 +0200 Subject: [PATCH 3/7] updated platformio.ini with esplive --- code/platformio.ini | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/code/platformio.ini b/code/platformio.ini index 912b203b..1dc91d33 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -1,5 +1,5 @@ [platformio] -env_default = nodemcu-lolin +env_default = esplive src_dir = espurna data_dir = espurna/data @@ -886,6 +886,29 @@ upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 monitor_baud = 115200 +[env:esplive] +platform = espressif8266 +framework = arduino +board = nodemcuv2 +board_flash_mode = dout +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m} -DESPLIVE +monitor_baud = 115200 + +[env:esplive-ota] +platform = espressif8266 +framework = arduino +board = nodemcuv2 +board_flash_mode = dout +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m} -DESPLIVE +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266 +monitor_baud = 115200 + # ------------------------------------------------------------------------------ # GENERIC OTA ENVIRONMENTS # ------------------------------------------------------------------------------ From 5e040ec34d96d5f1d9a4537cbb873f3ca7e5b846 Mon Sep 17 00:00:00 2001 From: Mitch Cox Date: Sun, 8 Oct 2017 13:11:47 +0000 Subject: [PATCH 4/7] defualt back to nodemcu-lolin --- code/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/platformio.ini b/code/platformio.ini index 1dc91d33..a84832c5 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -1,5 +1,5 @@ [platformio] -env_default = esplive +env_default = nodemcu-lolin src_dir = espurna data_dir = espurna/data From 179d629ba71734273eedf80ab18117760cb6ee1d Mon Sep 17 00:00:00 2001 From: Mitch Cox Date: Sun, 8 Oct 2017 13:13:01 +0000 Subject: [PATCH 5/7] fixed typo --- code/espurna/espurna.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 8676a259..0921e868 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -2,7 +2,7 @@ ESPurna -Copyright (C) 2016-2017 by Xose Pérez +Copyright (C) 2016-2017 by Xose Pérez This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ void hardwareSetup() { SPIFFS.begin(); #endif - #if defined(EPSLIVE) + #if defined(ESPLIVE) //The ESPLive has an ADC MUX which needs to be configured. pinMode(16, OUTPUT); digitalWrite(16, HIGH); //Defualt CT input (pin B, solder jumper B) From 7f83ca2daf208a2e233ddb03cfc6f26eb7083cf2 Mon Sep 17 00:00:00 2001 From: "Mitchell A. Cox" Date: Sun, 8 Oct 2017 18:01:47 +0200 Subject: [PATCH 6/7] added update on change to ds18b20 temperature sensor with default 1.0 degrees change. Saves space on MQTT server as it avoids logging pointless points.. --- code/espurna/config/sensors.h | 8 +++--- code/espurna/ds18b20.ino | 49 +++++++++++++++++++++-------------- code/espurna/espurna.ino | 2 +- code/platformio.ini | 13 +++++----- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index a3498dfc..7aab200b 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -74,12 +74,14 @@ //-------------------------------------------------------------------------------- #ifndef DS18B20_SUPPORT -#define DS18B20_SUPPORT 0 +#define DS18B20_SUPPORT 1 #endif -#define DS18B20_PIN 14 -#define DS18B20_UPDATE_INTERVAL 60000 +#define DS18B20_PIN 2 +#define DS18B20_UPDATE_INTERVAL 5000 #define DS18B20_TEMPERATURE_TOPIC "temperature" +//Will only send MQTT update if the value has changed by this amount (0.0 sends every interval) +#define DS18B20_UPDATE_ON_CHANGE 1.0 //-------------------------------------------------------------------------------- // Internal power montior diff --git a/code/espurna/ds18b20.ino b/code/espurna/ds18b20.ino index ebe98160..71c6933d 100644 --- a/code/espurna/ds18b20.ino +++ b/code/espurna/ds18b20.ino @@ -51,6 +51,10 @@ void dsLoop() { // Check if we should read new data static unsigned long last_update = 0; static bool requested = false; + + static double last_temperature = 0.0; + bool send_update = false; + if ((millis() - last_update > DS18B20_UPDATE_INTERVAL) || (last_update == 0)) { if (!requested) { ds18b20.requestTemperatures(); @@ -80,6 +84,12 @@ void dsLoop() { DEBUG_MSG_P(PSTR("[DS18B20] Error reading sensor\n")); } else { + + //If the new temperature is different from the last + if (fabs(t - last_temperature) >= DS18B20_UPDATE_ON_CHANGE) { + last_temperature = t; + send_update = true; + } _dsTemperature = t; @@ -95,25 +105,26 @@ void dsLoop() { getDSTemperatureStr(), (_dsIsConnected ? ((tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF") : "")); - // Send MQTT messages - mqttSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr); - - // Send to Domoticz - #if DOMOTICZ_SUPPORT - domoticzSend("dczTmpIdx", 0, _dsTemperatureStr); - #endif - - #if INFLUXDB_SUPPORT - influxDBSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr); - #endif - - // Update websocket clients - #if WEB_SUPPORT - char buffer[100]; - snprintf_P(buffer, sizeof(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits); - wsSend(buffer); - #endif - + if (send_update) { + // Send MQTT messages + mqttSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr); + + // Send to Domoticz + #if DOMOTICZ_SUPPORT + domoticzSend("dczTmpIdx", 0, _dsTemperatureStr); + #endif + + #if INFLUXDB_SUPPORT + influxDBSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr); + #endif + + // Update websocket clients + #if WEB_SUPPORT + char buffer[100]; + snprintf_P(buffer, sizeof(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits); + wsSend(buffer); + #endif + } } } diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 8676a259..bc24b2f0 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -43,7 +43,7 @@ void hardwareSetup() { SPIFFS.begin(); #endif - #if defined(EPSLIVE) + #if defined(ESPLIVE) //The ESPLive has an ADC MUX which needs to be configured. pinMode(16, OUTPUT); digitalWrite(16, HIGH); //Defualt CT input (pin B, solder jumper B) diff --git a/code/platformio.ini b/code/platformio.ini index 1dc91d33..81fe3058 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -889,22 +889,21 @@ monitor_baud = 115200 [env:esplive] platform = espressif8266 framework = arduino -board = nodemcuv2 -board_flash_mode = dout +board = d1_mini lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m} -DESPLIVE +build_flags = ${common.build_flags} -DESPLIVE +upload_speed = 460800 monitor_baud = 115200 [env:esplive-ota] platform = espressif8266 framework = arduino -board = nodemcuv2 -board_flash_mode = dout +board = d1_mini lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m} -DESPLIVE -upload_speed = 115200 +build_flags = ${common.build_flags} -DESPLIVE +upload_speed = 460800 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 monitor_baud = 115200 From b6ece41105766843d52268fa62bb83b93488bbf4 Mon Sep 17 00:00:00 2001 From: "Mitchell A. Cox" Date: Sun, 8 Oct 2017 18:03:30 +0200 Subject: [PATCH 7/7] we can update the web insterface as often as need be since it doesn't consume resources --- code/espurna/ds18b20.ino | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/code/espurna/ds18b20.ino b/code/espurna/ds18b20.ino index 71c6933d..a93b5f5c 100644 --- a/code/espurna/ds18b20.ino +++ b/code/espurna/ds18b20.ino @@ -117,14 +117,15 @@ void dsLoop() { #if INFLUXDB_SUPPORT influxDBSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr); #endif - - // Update websocket clients - #if WEB_SUPPORT - char buffer[100]; - snprintf_P(buffer, sizeof(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits); - wsSend(buffer); - #endif } + + // Update websocket clients + #if WEB_SUPPORT + char buffer[100]; + snprintf_P(buffer, sizeof(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits); + wsSend(buffer); + #endif + } }