From dc1d797d75b773fffe6bb1621dab92384975a207 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 14 Apr 2019 13:17:48 +0200 Subject: [PATCH] added tx_delay --- CHANGELOG.md | 3 ++- README.md | 2 ++ lib/MyESP/MyESP.cpp | 14 +++++++++----- src/ems-esp.cpp | 25 ++++++++++++++++++++++--- src/ems.cpp | 30 ++++++++++++++++++------------ src/ems.h | 3 +++ src/emsuart.cpp | 7 ++++++- src/version.h | 2 +- 8 files changed, 63 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d31960b3..57eb74144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.7.0 dev] 2019-04-07 +## [1.7.0 dev] 2019-04-14 ### Added @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - MQTT 'restart' topic to reboot ESP (thanks @balk77) - Support for multiple thermostat heating circuits like the HC1/HC2 on a RC35, also via MQTT (thanks @lobocobra) - `boiler flowtemp` command to set the flow temperature [(issue 59)](https://github.com/proddy/EMS-ESP/issues/59) +- `tx_delay` setting for circuits where we needed to slow down Tx transmission ## [1.6.0] 2019-03-24 diff --git a/README.md b/README.md index a84b29387..93fddeba8 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,8 @@ The onboard LED will flash if there is no connection with the EMS bus. You can d If you want to completely erase the ESP and rebuild the firmware then do a `pio run -t erase` which will wipe the onboard flash including the SPIFFs where all the settings are stored. +If you're unable to send commands then the Tx is most likely not working. Check with `info` to see if the Tx is available and that the rx poll is less than 200ms. Then trying putting a delay in the Tx by using `set tx_delay on` and `reboot`. See if that helps. + ## Known Issues Some annoying issues that need fixing: diff --git a/lib/MyESP/MyESP.cpp b/lib/MyESP/MyESP.cpp index c8513d94b..22daa2143 100644 --- a/lib/MyESP/MyESP.cpp +++ b/lib/MyESP/MyESP.cpp @@ -854,12 +854,16 @@ void MyESP::showSystemStats() { if (_boottime != NULL) { myDebug_P(PSTR(" [APP] Boot time: %s"), _boottime); } + + // uptime uint32_t t = _getUptime(); // seconds - uint32_t h = (uint32_t)t / (uint32_t)3600L; - uint32_t rem = (uint32_t)t % (uint32_t)3600L; - uint32_t m = rem / 60; - uint32_t s = rem % 60; - myDebug_P(PSTR(" [APP] Uptime: %d seconds (%02d:%02d:%02d)"), t, h, m, s); + uint32_t d = t / 86400L; + uint32_t h = (t / 3600L) % 60; + uint32_t rem = t % 3600L; + uint8_t m = rem / 60; + uint8_t s = rem % 60; + myDebug_P(PSTR(" [APP] Uptime: %d days, %d hours, %d minutes, %d seconds"), d, h, m, s); + myDebug_P(PSTR(" [APP] System Load: %d%%"), getSystemLoadAverage()); if (isAPmode()) { diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index 179e2d113..7cd146e48 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -101,6 +101,7 @@ command_t PROGMEM project_cmds[] = { {true, "shower_alert ", "send a warning of cold water after shower time is exceeded"}, {true, "publish_wait ", "set frequency for publishing to MQTT"}, {true, "heating_circuit <1 | 2>", "set the thermostat HC to work with if using multiple heating circuits"}, + {true, "tx_delay ", "turn on if Tx not working on newer boilers"}, {false, "info", "show data captured on the EMS bus"}, {false, "log ", "set logging mode to none, basic, thermostat only, raw or verbose"}, @@ -340,7 +341,7 @@ void showInfo() { EMS_Sys_Status.emxCrcErr); if (ems_getTxCapable()) { - myDebug(" Tx: available, # Tx telegrams sent=%d", EMS_Sys_Status.emsTxPkgs); + myDebug(" Tx: available, Tx delay is %s, # Tx telegrams sent=%d", (ems_getTxDelay() ? "on" : "off"), EMS_Sys_Status.emsTxPkgs); } else { myDebug(" Tx: no signal"); } @@ -887,6 +888,9 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) { // shower_alert EMSESP_Status.shower_alert = json["shower_alert"]; + // tx delay + ems_setTxDelay(json["tx_delay"]); + // publish_wait if (!(EMSESP_Status.publish_wait = json["publish_wait"])) { EMSESP_Status.publish_wait = DEFAULT_PUBLISHWAIT; // default value @@ -914,6 +918,7 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) { json["shower_alert"] = EMSESP_Status.shower_alert; json["publish_wait"] = EMSESP_Status.publish_wait; json["heating_circuit"] = EMSESP_Status.heating_circuit; + json["tx_delay"] = ems_getTxDelay(); return true; } @@ -1043,6 +1048,19 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c myDebug("Error. Usage: set heating_circuit <1 | 2>"); } } + + // tx delay + if ((strcmp(setting, "tx_delay") == 0) && (wc == 2)) { + if (strcmp(value, "on") == 0) { + ems_setTxDelay(true); + ok = true; + } else if (strcmp(value, "off") == 0) { + ems_setTxDelay(false); + ok = true; + } else { + myDebug("Error. Usage: set tx_delay "); + } + } } if (action == MYESP_FSACTION_LIST) { @@ -1069,6 +1087,7 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c myDebug(" shower_timer=%s", EMSESP_Status.shower_timer ? "on" : "off"); myDebug(" shower_alert=%s", EMSESP_Status.shower_alert ? "on" : "off"); myDebug(" publish_wait=%d", EMSESP_Status.publish_wait); + myDebug(" tx_delay=%s", ems_getTxDelay() ? "on" : "off"); } return ok; @@ -1523,7 +1542,7 @@ void setup() { // start up all the services myESP.begin(APP_HOSTNAME, APP_NAME, APP_VERSION); - // at this point we have the settings from our internall SPIFFS config file + // at this point we have all the settings from our internall SPIFFS config file // enable regular checks if not in test mode if (!EMSESP_Status.silent_mode) { @@ -1553,7 +1572,7 @@ void loop() { myESP.loop(); // check Dallas sensors, every 2 seconds - // these values are published to MQTT seperately via the timer publishSensorValuesTimer + // these values are published to MQTT separately via the timer publishSensorValuesTimer if (EMSESP_Status.dallas_sensors != 0) { ds18.loop(); } diff --git a/src/ems.cpp b/src/ems.cpp index 32443731c..560d5d5ef 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -189,6 +189,7 @@ void ems_init() { EMS_Sys_Status.emsTxDisabled = false; EMS_Sys_Status.emsPollFrequency = 0; EMS_Sys_Status.txRetryCount = 0; + EMS_Sys_Status.emsTxDelay = false; // thermostat EMS_Thermostat.setpoint_roomTemp = EMS_VALUE_SHORT_NOTSET; @@ -295,6 +296,15 @@ bool ems_getPoll() { return EMS_Sys_Status.emsPollEnabled; } +void ems_setTxDelay(bool b) { + EMS_Sys_Status.emsTxDelay = b; + myDebug("EMS Tx delay is %s", EMS_Sys_Status.emsTxDelay ? "enabled" : "disabled"); +} + +bool ems_getTxDelay() { + return EMS_Sys_Status.emsTxDelay; +} + bool ems_getEmsRefreshed() { return EMS_Sys_Status.emsRefreshed; } @@ -718,19 +728,19 @@ void _printMessage(_EMS_RxTelegram * EMS_RxTelegram) { uint8_t * telegram = EMS_RxTelegram->telegram; // header info - uint8_t src = telegram[0] & 0x7F; - uint8_t dest = telegram[1] & 0x7F; // remove 8th bit to handle both reads and writes - uint8_t type; - bool emsp; + uint8_t src = telegram[0] & 0x7F; + uint8_t dest = telegram[1] & 0x7F; // remove 8th bit to handle both reads and writes + uint8_t type; + bool emsp; // check if EMS or EMS+ by checking 3rd byte of telegram if (telegram[2] >= 0xF0) { // EMS+ - type = telegram[3]; - emsp = true; + type = telegram[3]; + emsp = true; } else { - type = telegram[2]; - emsp = false; + type = telegram[2]; + emsp = false; } char output_str[200] = {0}; @@ -1265,7 +1275,6 @@ void _process_SM10Monitor(uint8_t src, uint8_t * data, uint8_t length) { * UBASetPoint 0x1A */ void _process_SetPoints(uint8_t src, uint8_t * data, uint8_t length) { - if (EMS_Sys_Status.emsLogging == EMS_SYS_LOGGING_VERBOSE) { if (length != 0) { uint8_t setpoint = data[0]; // flow temp @@ -1283,7 +1292,6 @@ void _process_SetPoints(uint8_t src, uint8_t * data, uint8_t length) { myDebug(" Boiler flow temperature is %d C", setpoint); } } - } /** @@ -1985,7 +1993,6 @@ void ems_setWarmWaterTemp(uint8_t temperature) { * Set the boiler flow temp */ void ems_setFlowTemp(uint8_t temperature) { - myDebug("Setting boiler flow temperature to %d C", temperature); _EMS_TxTelegram EMS_TxTelegram = EMS_TX_TELEGRAM_NEW; // create new Tx @@ -2006,7 +2013,6 @@ void ems_setFlowTemp(uint8_t temperature) { EMS_TxTelegram.forceRefresh = false; EMS_TxQueue.push(EMS_TxTelegram); - } /** diff --git a/src/ems.h b/src/ems.h index 55d40f399..c272aea81 100644 --- a/src/ems.h +++ b/src/ems.h @@ -95,6 +95,7 @@ typedef struct { bool emsTxCapable; // able to send via Tx bool emsTxDisabled; // true to prevent all Tx uint8_t txRetryCount; // # times the last Tx was re-sent + bool emsTxDelay; // if true, slows down the Tx transmit } _EMS_Sys_Status; // The Tx send package @@ -286,6 +287,7 @@ void ems_setFlowTemp(uint8_t temperature); void ems_setWarmWaterActivated(bool activated); void ems_setWarmTapWaterActivated(bool activated); void ems_setPoll(bool b); +void ems_setTxDelay(bool b); void ems_setLogging(_EMS_SYS_LOGGING loglevel); void ems_setEmsRefreshed(bool b); void ems_setWarmWaterModeComfort(uint8_t comfort); @@ -300,6 +302,7 @@ bool ems_getPoll(); bool ems_getTxEnabled(); bool ems_getThermostatEnabled(); bool ems_getBoilerEnabled(); +bool ems_getTxDelay(); bool ems_getBusConnected(); _EMS_SYS_LOGGING ems_getLogging(); bool ems_getEmsRefreshed(); diff --git a/src/emsuart.cpp b/src/emsuart.cpp index 4815d3d03..480559de0 100644 --- a/src/emsuart.cpp +++ b/src/emsuart.cpp @@ -177,7 +177,12 @@ void ICACHE_FLASH_ATTR emsuart_tx_brk() { void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) { for (uint8_t i = 0; i < len; i++) { USF(EMSUART_UART) = buf[i]; - //delayMicroseconds(EMS_TX_BRK_WAIT); + + // check if we need to force a delay to slow down Tx + // https://github.com/proddy/EMS-ESP/issues/23# + if (EMS_Sys_Status.emsTxDelay) { + delayMicroseconds(EMS_TX_BRK_WAIT); + } } emsuart_tx_brk(); } diff --git a/src/version.h b/src/version.h index 4d2ac25a2..a4f69be39 100644 --- a/src/version.h +++ b/src/version.h @@ -6,5 +6,5 @@ #pragma once #define APP_NAME "EMS-ESP" -#define APP_VERSION "1.7.0b4" +#define APP_VERSION "1.7.0b5" #define APP_HOSTNAME "ems-esp"