From af5c54f610d66575e0182c7d51131e0a5990f73b Mon Sep 17 00:00:00 2001 From: tuzzmaniandevil Date: Tue, 5 Sep 2017 16:31:04 +1200 Subject: [PATCH 01/12] Add an option to query relay status --- code/espurna/relay.ino | 7 ++++--- code/espurna/web.ino | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 456b6b06..7f476572 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -335,13 +335,14 @@ unsigned char relayParsePayload(const char * payload) { value = 1; } else if (strcmp(p, "toggle") == 0) { value = 2; + } else if (strcmp(p, "query") == 0) { + value = 3; } else { value = p[0] - '0'; } - if (0 <= value && value <=2) return value; - return 0x99; - + if (0 <= value && value <=3) return value; + return 0xFF; } //------------------------------------------------------------------------------ // REST API diff --git a/code/espurna/web.ino b/code/espurna/web.ino index eed32a45..4f349897 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -142,7 +142,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { if (data.containsKey("status")) { unsigned char value = relayParsePayload(data["status"]); - if (value == 0xFF) { + if (value == 3) { relayWS(); From cdc98e1cb54253e742160c9b0112b5a36c6c6106 Mon Sep 17 00:00:00 2001 From: "Mitchell A. Cox" Date: Sun, 8 Oct 2017 14:42:11 +0200 Subject: [PATCH 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 + } } From a4de1ddecf47f3f59bc79e38c14ea66dc71b1275 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Mon, 9 Oct 2017 00:07:08 +0200 Subject: [PATCH 09/12] Make building the web interface easier by automatically installing the dependencies. --- code/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/build.sh b/code/build.sh index 3c051dc8..7dec02e2 100755 --- a/code/build.sh +++ b/code/build.sh @@ -28,6 +28,12 @@ echo "Building for version $version" # Create output folder mkdir -p firmware +if [ ! -e node_modules/gulp/bin/gulp.js ]; then + echo "--------------------------------------------------------------" + echo "Installing dependencies..." + npm install --only=dev +fi + # Recreate web interface echo "--------------------------------------------------------------" echo "Building web interface..." From e9687b5ca29930890a4295b049253e8019099b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 9 Oct 2017 18:32:17 +0200 Subject: [PATCH 10/12] Support for ESPurna board v0.7 --- code/espurna/config/hardware.h | 69 ++++++++++++++++++++++++++++------ code/espurna/hardware.ino | 15 +++++++- code/html/index.html | 12 +++--- code/platformio.ini | 30 +++++++++++++-- 4 files changed, 104 insertions(+), 22 deletions(-) diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index fe35cd67..4c50b0e6 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -63,26 +63,32 @@ // ESPurna // ----------------------------------------------------------------------------- -#elif defined(TINKERMAN_ESPURNA_H) +#elif defined(TINKERMAN_ESPURNA_H06) // Info #define MANUFACTURER "TINKERMAN" - #define DEVICE "ESPURNA_H" + #define DEVICE "ESPURNA_H06" // Buttons #define BUTTON1_PIN 4 #define BUTTON1_RELAY 1 - // Normal pushbutton - //#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + #ifdef USE_TOUCH_BUTTON - // Touch button - #define BUTTON1_MODE BUTTON_PUSHBUTTON - #define BUTTON1_PRESS BUTTON_MODE_TOGGLE - #define BUTTON1_CLICK BUTTON_MODE_NONE - #define BUTTON1_DBLCLICK BUTTON_MODE_NONE - #define BUTTON1_LNGCLICK BUTTON_MODE_NONE - #define BUTTON1_LNGLNGCLICK BUTTON_MODE_NONE + // Touch button + #define BUTTON1_MODE BUTTON_PUSHBUTTON + #define BUTTON1_PRESS BUTTON_MODE_TOGGLE + #define BUTTON1_CLICK BUTTON_MODE_NONE + #define BUTTON1_DBLCLICK BUTTON_MODE_NONE + #define BUTTON1_LNGCLICK BUTTON_MODE_NONE + #define BUTTON1_LNGLNGCLICK BUTTON_MODE_NONE + + #else + + // Normal pushbutton + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + + #endif // Relays @@ -99,6 +105,47 @@ #define HLW8012_CF1_PIN 13 #define HLW8012_CF_PIN 14 +#elif defined(TINKERMAN_ESPURNA_H07) + + // Info + #define MANUFACTURER "TINKERMAN" + #define DEVICE "ESPURNA_H07" + + // Buttons + #define BUTTON1_PIN 4 + #define BUTTON1_RELAY 1 + + #ifdef USE_TOUCH_BUTTON + + // Touch button + #define BUTTON1_MODE BUTTON_PUSHBUTTON + #define BUTTON1_PRESS BUTTON_MODE_TOGGLE + #define BUTTON1_CLICK BUTTON_MODE_NONE + #define BUTTON1_DBLCLICK BUTTON_MODE_NONE + #define BUTTON1_LNGCLICK BUTTON_MODE_NONE + #define BUTTON1_LNGLNGCLICK BUTTON_MODE_NONE + + #else + + // Normal pushbutton + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + + #endif + + // Relays + #define RELAY1_PIN 12 + #define RELAY1_TYPE RELAY_TYPE_NORMAL + + // LEDs + #define LED1_PIN 2 + #define LED1_PIN_INVERSE 0 + + // HLW8012 + #define POWER_PROVIDER POWER_PROVIDER_HLW8012 + #define HLW8012_SEL_PIN 5 + #define HLW8012_CF1_PIN 13 + #define HLW8012_CF_PIN 14 + // ----------------------------------------------------------------------------- // Itead Studio boards // ----------------------------------------------------------------------------- diff --git a/code/espurna/hardware.ino b/code/espurna/hardware.ino index d11f6a7d..4b0b1095 100644 --- a/code/espurna/hardware.ino +++ b/code/espurna/hardware.ino @@ -252,7 +252,7 @@ void hwUpwardsCompatibility() { setSetting("relayGPIO", 1, 12); setSetting("relayType", 1, RELAY_TYPE_NORMAL); - #elif defined(TINKERMAN_ESPURNA_H) + #elif defined(TINKERMAN_ESPURNA_H06) setSetting("board", 23); setSetting("ledGPIO", 1, 5); @@ -442,6 +442,19 @@ void hwUpwardsCompatibility() { setSetting("board", 38); + #elif defined(TINKERMAN_ESPURNA_H07) + + setSetting("board", 39); + setSetting("ledGPIO", 1, 2); + setSetting("ledLogic", 1, 0); + setSetting("btnGPIO", 1, 4); + setSetting("btnRelay", 1, 1); + setSetting("relayGPIO", 1, 12); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("selGPIO", 5); + setSetting("cf1GPIO", 13); + setSetting("cfGPIO", 14); + #else #error "UNSUPPORTED HARDWARE!" diff --git a/code/html/index.html b/code/html/index.html index 1e7dc867..e1a34fe1 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -401,12 +401,6 @@
Fahrenheit (°F)
-
- -
-
-
- @@ -475,6 +469,12 @@
This name address of the NoFUSS server for automatic remote updates (see https://bitbucket.org/xoseperez/nofuss).
+
+ +
+
+
+
diff --git a/code/platformio.ini b/code/platformio.ini index 912b203b..2219350f 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -100,23 +100,45 @@ monitor_baud = 115200 # ------------------------------------------------------------------------------ -[env:tinkerman-espurna-h] +[env:tinkerman-espurna-h06] platform = espressif8266 framework = arduino board = esp12e lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H +build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H06 upload_speed = 460800 monitor_baud = 115200 -[env:tinkerman-espurna-h-ota] +[env:tinkerman-espurna-h06-ota] platform = espressif8266 framework = arduino board = esp12e lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H +build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H06 +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266 +monitor_baud = 115200 + +[env:tinkerman-espurna-h07] +platform = espressif8266 +framework = arduino +board = esp12e +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H07 +upload_speed = 460800 +monitor_baud = 115200 + +[env:tinkerman-espurna-h07-ota] +platform = espressif8266 +framework = arduino +board = esp12e +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags} -DTINKERMAN_ESPURNA_H07 upload_speed = 115200 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 From a964d84c42b648b1277665a392af9be3eed5aeac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 9 Oct 2017 18:41:02 +0200 Subject: [PATCH 11/12] Check relayParsePayload output --- code/espurna/relay.ino | 21 +++++++++++++++------ code/espurna/web.ino | 12 ++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 7f476572..c1c54a29 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -343,6 +343,7 @@ unsigned char relayParsePayload(const char * payload) { if (0 <= value && value <=3) return value; return 0xFF; + } //------------------------------------------------------------------------------ // REST API @@ -366,16 +367,22 @@ void relaySetupAPI() { snprintf_P(buffer, len, PSTR("%d"), relayStatus(relayID) ? 1 : 0); }, [relayID](const char * payload) { + unsigned char value = relayParsePayload(payload); + if (value == 0xFF) { DEBUG_MSG_P(PSTR("[RELAY] Wrong payload (%s)\n"), payload); return; } - if (value == 2) { + + if (value == 0) { + relayStatus(relayID, false); + } elseif (value == 1) { + relayStatus(relayID, true); + } elseif (value == 2) { relayToggle(relayID); - } else { - relayStatus(relayID, value == 1); } + } ); @@ -461,10 +468,12 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo } // Action to perform - if (value == 2) { + if (value == 0) { + relayStatus(relayID, false, mqttForward()); + } elseif (value == 1) { + relayStatus(relayID, true, mqttForward()); + } elseif (value == 2) { relayToggle(relayID); - } else { - relayStatus(relayID, value == 1, mqttForward()); } } diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 34a2e60c..4d3d2ba3 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -143,11 +143,12 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { if (data.containsKey("status")) { unsigned char value = relayParsePayload(data["status"]); + if (value == 3) { relayWS(); - } else { + } elseif (value < 3) { unsigned int relayID = 0; if (data.containsKey("id")) { @@ -155,10 +156,13 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { relayID = value.toInt(); } - if (value == 2) { + // Action to perform + if (value == 0) { + relayStatus(relayID, false); + } elseif (value == 1) { + relayStatus(relayID, true); + } elseif (value == 2) { relayToggle(relayID); - } else { - relayStatus(relayID, value == 1); } } From f165ab93390d87ff2fef7ce2d8694ed56c96a8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 9 Oct 2017 18:55:43 +0200 Subject: [PATCH 12/12] Beta version 1.9.6b --- code/espurna/config/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index 59903d2e..28004f7a 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.9.5" +#define APP_VERSION "1.9.6b" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat"