From 2b66688710d859d727ce8f286038ea80310ab524 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 4 Feb 2019 00:32:50 +0100 Subject: [PATCH] 1.5.1 - fixes some bugs in 1.5.0 --- CHANGELOG.md | 10 ++++++++ lib/myESP/MyESP.cpp | 13 ++++++++-- lib/myESP/MyESP.h | 1 + platformio.ini-example | 2 +- src/ems-esp.ino | 58 ++++++++++++++++++++++++++---------------- src/ems.cpp | 2 +- src/version.h | 2 +- 7 files changed, 61 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b261f43..c8caf990c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ 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.5.1] 2019-02-03 + +### Fixed + +- issue with Serial monitoring conflicting with UART when both running + +### Changed + +- `thermostat temp` now except floats (e.g. 20.5). Some thermostats may round up or down if they use 0.5 intervals. + ## [1.5.0] 2019-02-03 ### Added diff --git a/lib/myESP/MyESP.cpp b/lib/myESP/MyESP.cpp index 498da1b3c..9d1a86fba 100644 --- a/lib/myESP/MyESP.cpp +++ b/lib/myESP/MyESP.cpp @@ -102,6 +102,11 @@ void MyESP::myDebug_P(PGM_P format_P, ...) { delete[] buffer; } +// use Serial? +bool MyESP::getUseSerial() { + return (_use_serial); +} + // called when WiFi is connected, and used to start MDNS void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) { if ((code == MESSAGE_CONNECTED)) { @@ -629,6 +634,9 @@ void MyESP::_telnetHandle() { if (charsRead > 0) { charsRead = 0; // is static, so have to reset _suspendOutput = false; + if (_use_serial) { + SerialAndTelnet.println(); // force newline if in Telnet + } _telnetCommand(_command); } break; @@ -814,9 +822,10 @@ void MyESP::_fs_printConfig() { // format File System void MyESP::_fs_eraseConfig() { - myDebug_P(PSTR("[FS] Erasing settings, please wait. ESP will automatically restart when finished.")); + myDebug_P(PSTR("[FS] Erasing settings, please wait a few seconds. ESP will automatically restart when finished.")); if (SPIFFS.format()) { + delay(2000); // wait 2 seconds resetESP(); } } @@ -833,7 +842,7 @@ bool MyESP::_fs_loadConfig() { myDebug_P(PSTR("[FS] Failed to open config file")); // file does not exist, so assume its the first install. Set serial to on _use_serial = true; - return false; + return false; // this will trigger a new file being created } size_t size = configFile.size(); diff --git a/lib/myESP/MyESP.h b/lib/myESP/MyESP.h index 5732d4c88..e244abfda 100644 --- a/lib/myESP/MyESP.h +++ b/lib/myESP/MyESP.h @@ -113,6 +113,7 @@ class MyESP { void myDebug(const char * format, ...); void myDebug_P(PGM_P format_P, ...); void setTelnet(command_t * cmds, uint8_t count, telnetcommand_callback_f callback_cmd, telnet_callback_f callback); + bool getUseSerial(); // FS void setSettings(fs_callback_f callback, fs_settings_callback_f fs_settings_callback); diff --git a/platformio.ini-example b/platformio.ini-example index 101dba8ec..616a52e45 100644 --- a/platformio.ini-example +++ b/platformio.ini-example @@ -10,7 +10,7 @@ build_flags = -g -w wifi_settings = ; hard code if you prefer. Recommendation is to set from within the app when in Serial or AP mode -;wifi_settings = -DWIFI_SSID="your_ssid" -DWIFI_PASSWORD="your_pw" +;wifi_settings = '-DWIFI_SSID="XXXX"' '-DWIFI_PASSWORD="XXXX"' lib_deps = CRC32 diff --git a/src/ems-esp.ino b/src/ems-esp.ino index 97af88608..3a2b9fae7 100644 --- a/src/ems-esp.ino +++ b/src/ems-esp.ino @@ -78,7 +78,7 @@ typedef struct { command_t PROGMEM project_cmds[] = { {"set led ", "toggle status LED on/off"}, - {"set led_gpio ", "set the LED pin (onboard=2)"}, + {"set led_gpio ", "set the LED pin (onboard=16)"}, {"set dallas_gpio ", "set the pin for the external Dallas temperature sensor (D5=14)"}, {"set thermostat_type ", "set the thermostat type id (e.g. 10 for 0x10)"}, {"set boiler_type ", "set the boiler type id (e.g. 8 for 0x08)"}, @@ -384,10 +384,9 @@ void showInfo() { myDebug(" Mode is set to ?"); } } + myDebug(""); // newline } - myDebug(""); // newline - // Dallas if (EMSESP_Status.dallas_sensors != 0) { myDebug("%sExternal temperature sensors:%s", COLOR_BOLD_ON, COLOR_BOLD_OFF); @@ -396,10 +395,9 @@ void showInfo() { snprintf(s, sizeof(s), "Sensor #%d", i + 1); _renderFloatValue(s, "C", ds18.getValue(i)); } + myDebug(""); // newline } - myDebug(""); // newline - // show the Shower Info if (EMSESP_Status.shower_timer) { myDebug("%sShower stats:%s", COLOR_BOLD_ON, COLOR_BOLD_OFF); @@ -545,6 +543,15 @@ uint8_t _readIntNumber() { return atoi(numTextPtr); } +// used to read the next string from an input buffer and convert to a double +float _readFloatNumber() { + char * numTextPtr = strtok(NULL, ", \n"); + if (numTextPtr == nullptr) { + return 0; + } + return atof(numTextPtr); +} + // used to read the next string from an input buffer as a hex value and convert to an 8 bit int uint8_t _readHexNumber() { char * numTextPtr = strtok(NULL, ", \n"); @@ -572,7 +579,6 @@ void startThermostatScan(uint8_t start) { scanThermostat.attach(SCANTHERMOSTAT_TIME, do_scanThermostat); } - // callback for loading/saving settings to the file system (SPIFFS) bool FSCallback(MYESP_FSACTION action, JsonObject & json) { bool ok = true; @@ -581,21 +587,24 @@ bool FSCallback(MYESP_FSACTION action, JsonObject & json) { if (json.containsKey("led")) { EMSESP_Status.led_enabled = (bool)json["led"]; } else { - ok = false; + EMSESP_Status.led_enabled = LED_BUILTIN; // default value + ok = false; } // led_gpio if (json.containsKey("led_gpio")) { EMSESP_Status.led_gpio = json["led_gpio"]; } else { - ok = false; + EMSESP_Status.led_gpio = EMSESP_LED_GPIO; // default value + ok = false; } // dallas_gpio if (json.containsKey("dallas_gpio")) { EMSESP_Status.dallas_gpio = json["dallas_gpio"]; } else { - ok = false; + EMSESP_Status.dallas_gpio = EMSESP_DALLAS_GPIO; // default value + ok = false; } // thermostat_type @@ -780,7 +789,7 @@ void TelnetCommandCallback(uint8_t wc, const char * commandLine) { if (wc == 3) { char * second_cmd = _readWord(); if (strcmp(second_cmd, "temp") == 0) { - ems_setThermostatTemp(_readIntNumber()); + ems_setThermostatTemp(_readFloatNumber()); ok = true; } else if (strcmp(second_cmd, "mode") == 0) { ems_setThermostatMode(_readIntNumber()); @@ -910,11 +919,14 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) { void WIFICallback() { // This is where we enable the UART service to scan the incoming serial Tx/Rx bus signals // This is done after we have a WiFi signal to avoid any resource conflicts - emsuart_init(); - myDebug("[UART] Opened Rx/Tx connection"); - - // go and find the boiler and thermostat types - ems_discoverModels(); + if (myESP.getUseSerial()) { + myDebug("EMS UART disabled when in Serial mode. Use 'set serial off' to change."); + } else { + emsuart_init(); + myDebug("[UART] Opened Rx/Tx connection"); + // go and find the boiler and thermostat types + ems_discoverModels(); + } } // Initialize the boiler settings and shower settings @@ -922,7 +934,7 @@ void initEMSESP() { // general settings EMSESP_Status.shower_timer = BOILER_SHOWER_TIMER; EMSESP_Status.shower_alert = BOILER_SHOWER_ALERT; - EMSESP_Status.led_enabled = false; + EMSESP_Status.led_enabled = true; // LED is on by default EMSESP_Status.timestamp = millis(); EMSESP_Status.dallas_sensors = 0; @@ -939,7 +951,7 @@ void initEMSESP() { // call PublishValues without forcing, so using CRC to see if we really need to publish void do_publishValues() { // don't publish if we're not connected to the EMS bus - if (ems_getBusConnected()) { + if ((ems_getBusConnected()) && (!myESP.getUseSerial())) { publishValues(false); } } @@ -959,14 +971,16 @@ void do_ledcheck() { // Thermostat scan void do_scanThermostat() { - myDebug("> Scanning thermostat message type #0x%02X..", scanThermostat_count); - ems_doReadCommand(scanThermostat_count, EMS_Thermostat.type_id); - scanThermostat_count++; + if ((ems_getBusConnected()) && (!myESP.getUseSerial())) { + myDebug("> Scanning thermostat message type #0x%02X..", scanThermostat_count); + ems_doReadCommand(scanThermostat_count, EMS_Thermostat.type_id); + scanThermostat_count++; + } } // do a system health check every now and then to see if we all connections void do_systemCheck() { - if (!ems_getBusConnected()) { + if ((!ems_getBusConnected()) && (!myESP.getUseSerial())) { myDebug("Error! Unable to read from EMS bus. Retrying in %d seconds...", SYSTEMCHECK_TIME); } } @@ -974,7 +988,7 @@ void do_systemCheck() { // force calls to get data from EMS for the types that aren't sent as broadcasts // only if we have a EMS connection void do_regularUpdates() { - if (ems_getBusConnected()) { + if ((ems_getBusConnected()) && (!myESP.getUseSerial())) { myDebugLog("Calling scheduled data refresh from EMS devices.."); ems_getThermostatValues(); ems_getBoilerValues(); diff --git a/src/ems.cpp b/src/ems.cpp index 5b4062fd8..24f520399 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -975,7 +975,7 @@ void _process_UBAMonitorSlow(uint8_t type, uint8_t * data, uint8_t length) { */ void _process_RC10StatusMessage(uint8_t type, uint8_t * data, uint8_t length) { EMS_Thermostat.setpoint_roomTemp = ((float)data[EMS_TYPE_RC10StatusMessage_setpoint]) / (float)2; - EMS_Thermostat.curr_roomTemp = _toFloat(EMS_TYPE_RC10StatusMessage_curr, data); + EMS_Thermostat.curr_roomTemp = ((float)data[EMS_TYPE_RC10StatusMessage_curr]) / (float)10; EMS_Sys_Status.emsRefreshed = true; // triggers a send the values back via MQTT } diff --git a/src/version.h b/src/version.h index 0f280b006..647e3714f 100644 --- a/src/version.h +++ b/src/version.h @@ -6,5 +6,5 @@ #pragma once #define APP_NAME "EMS-ESP" -#define APP_VERSION "1.5.0" +#define APP_VERSION "1.5.1" #define APP_HOSTNAME "ems-esp"