From 88dfc2b79b211987b41c8a4553978ad39a4958f2 Mon Sep 17 00:00:00 2001 From: Choumarin Date: Fri, 24 May 2024 16:09:43 -0700 Subject: [PATCH 01/11] Add feature to override power usages This adds an option in the hardware configuration to override power usage for each element. With this, it is possible to better adjust power usage statistics for non standard models, especially 110V based ones. --- Code/data/hwconfig.html | 66 +++++++++++++++++++++++++++++++++++- Code/lib/BWC_unified/bwc.cpp | 43 ++++++++++++++++------- Code/lib/BWC_unified/bwc.h | 3 +- Code/lib/BWC_unified/enums.h | 9 ++++- Code/lib/cio/CIO_4W.cpp | 27 ++++++++++++--- Code/lib/cio/CIO_4W.h | 12 +++++-- Code/lib/cio/CIO_6W.h | 5 --- Code/lib/cio/CIO_BASE.cpp | 14 ++++++++ Code/lib/cio/CIO_BASE.h | 19 ++++++++++- 9 files changed, 171 insertions(+), 27 deletions(-) diff --git a/Code/data/hwconfig.html b/Code/data/hwconfig.html index 409108dd..d09aefd3 100644 --- a/Code/data/hwconfig.html +++ b/Code/data/hwconfig.html @@ -146,6 +146,35 @@

Hardware:

+
+

Power levels (in Watts) ?

+ + + + + + + + + + + + +
Override
Heat stage 1Heat stage 2Pump Idle Air Jets
+
+
@@ -162,6 +191,17 @@

Hardware:

setPins(); loadHardwareConfig(); +function onOverrideClick() +{ + let checked = document.getElementById("pwr_override").checked; + [...document.querySelectorAll("input[id^='pwr_']")] + .forEach((e) => { + if (e.type !== "checkbox") { + e.disabled = !checked; + } + }) +} + function setPins() { var cio = document.querySelector("input[name='cio_model']:checked").value; @@ -320,6 +360,20 @@

Hardware:

{ setPins(); } + + // Set power levels if override enabled + if (json.pwr_levels.override) { + [...document.querySelectorAll("input[id^='pwr_']")] + .forEach((e) => { + if (e.type !== "checkbox") { + e.value = json.pwr_levels[e.id.slice(4)]; + } + }) + document.getElementById("pwr_override").checked = true; + onOverrideClick(); + } else { + document.getElementById("pwr_override").checked = false; + } } } } @@ -350,7 +404,17 @@

Hardware:

document.getElementById('pin6').value, document.getElementById('pin7').value, document.getElementById('pin8').value - ] + ], + 'pwr_levels': + [...document.querySelectorAll("input[id^='pwr_']")] + .reduce((acc, e) => { + if (e.type === "checkbox") { + acc[e.id.slice(4)] = e.checked; + } else { + acc[e.id.slice(4)] = e.value; + } + return acc; + }, {}) }; req.send(JSON.stringify(json)); console.log(JSON.stringify(json)); diff --git a/Code/lib/BWC_unified/bwc.cpp b/Code/lib/BWC_unified/bwc.cpp index 387330a6..45f2e935 100644 --- a/Code/lib/BWC_unified/bwc.cpp +++ b/Code/lib/BWC_unified/bwc.cpp @@ -61,8 +61,9 @@ void BWC::setup(void){ if(dsp != nullptr) delete dsp; Models ciomodel; Models dspmodel; + std::optional power_levels = {}; - if(!_loadHardware(ciomodel, dspmodel, pins)){ + if(!_loadHardware(ciomodel, dspmodel, pins, power_levels)){ pins[0] = D1; pins[1] = D2; pins[2] = D3; @@ -148,6 +149,9 @@ void BWC::setup(void){ } } cio->setup(pins[0], pins[1], pins[2]); + + cio->setPowerLevels(power_levels); + dsp->setup(pins[3], pins[4], pins[5], pins[6]); tempSensorPin = pins[7]; hasjets = cio->getHasjets(); @@ -1170,17 +1174,17 @@ void BWC::_updateTimes(){ if(_override_dsp_brt_timer > 0) _override_dsp_brt_timer -= elapsedtime_ms; //counts down to or below zero // watts, kWh today, total kWh - float heatingEnergy = (_heatingtime+_heatingtime_ms/1000)/3600.0 * cio->getPower().HEATERPOWER; - float pumpEnergy = (_pumptime+_pumptime_ms/1000)/3600.0 * cio->getPower().PUMPPOWER; - float airEnergy = (_airtime+_airtime_ms/1000)/3600.0 * cio->getPower().AIRPOWER; - float idleEnergy = (_uptime+_uptime_ms/1000)/3600.0 * cio->getPower().IDLEPOWER; - float jetEnergy = (_jettime+_jettime_ms/1000)/3600.0 * cio->getPower().JETPOWER; + float heatingEnergy = (_heatingtime+_heatingtime_ms/1000)/3600.0 * cio->getHeaterPower(); + float pumpEnergy = (_pumptime+_pumptime_ms/1000)/3600.0 * cio->getPowerLevels().PUMPPOWER; + float airEnergy = (_airtime+_airtime_ms/1000)/3600.0 * cio->getPowerLevels().AIRPOWER; + float idleEnergy = (_uptime+_uptime_ms/1000)/3600.0 * cio->getPowerLevels().IDLEPOWER; + float jetEnergy = (_jettime+_jettime_ms/1000)/3600.0 * cio->getPowerLevels().JETPOWER; _energy_total_kWh = (heatingEnergy + pumpEnergy + airEnergy + idleEnergy + jetEnergy)/1000; //Wh -> kWh - _energy_power_W = cio->cio_states.heatred * cio->getPower().HEATERPOWER; - _energy_power_W += cio->cio_states.pump * cio->getPower().PUMPPOWER; - _energy_power_W += cio->cio_states.bubbles * cio->getPower().AIRPOWER; - _energy_power_W += cio->getPower().IDLEPOWER; - _energy_power_W += cio->cio_states.jets * cio->getPower().JETPOWER; + _energy_power_W = cio->cio_states.heatred * cio->getHeaterPower(); + _energy_power_W += cio->cio_states.pump * cio->getPowerLevels().PUMPPOWER; + _energy_power_W += cio->cio_states.bubbles * cio->getPowerLevels().AIRPOWER; + _energy_power_W += cio->getPowerLevels().IDLEPOWER; + _energy_power_W += cio->cio_states.jets * cio->getPowerLevels().JETPOWER; _energy_daily_Ws += elapsedtime_ms * _energy_power_W / 1000.0; _energy_cost += _price * _energy_power_W / (1000.0 * 1000.0 * 3600.0); // money/kWh @@ -1206,7 +1210,7 @@ void BWC::_updateTimes(){ /* LOADERS */ /* */ -bool BWC::_loadHardware(Models& cioNo, Models& dspNo, int pins[]) +bool BWC::_loadHardware(Models& cioNo, Models& dspNo, int pins[], std::optional& power_levels) { File file = LittleFS.open(F("/hwcfg.json"), "r"); if (!file) @@ -1243,6 +1247,21 @@ bool BWC::_loadHardware(Models& cioNo, Models& dspNo, int pins[]) pins[i] = DtoGPIO[pins[i]]; #endif } + + const auto pwr_levels_json = doc[F("pwr_levels")]; + if (pwr_levels_json[F("override")].as()) { + power_levels.emplace( + Power{ + .HEATERPOWER_STAGE1 = pwr_levels_json[F("heater_stage1")].as(), + .HEATERPOWER_STAGE2 = pwr_levels_json[F("heater_stage2")].as(), + .PUMPPOWER = pwr_levels_json[F("pump")].as(), + .AIRPOWER = pwr_levels_json[F("air")].as(), + .IDLEPOWER = pwr_levels_json[F("idle")].as(), + .JETPOWER = pwr_levels_json[F("jet")].as(), + } + ); + } + return true; } diff --git a/Code/lib/BWC_unified/bwc.h b/Code/lib/BWC_unified/bwc.h index 2fa6dc3d..12616360 100644 --- a/Code/lib/BWC_unified/bwc.h +++ b/Code/lib/BWC_unified/bwc.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "enums.h" #include "CIO_PRE2021.h" #include "CIO_2021.h" @@ -106,7 +107,7 @@ class BWC { bool hasTempSensor = false; private: - bool _loadHardware(Models& cioNo, Models& dspNo, int pins[]); + bool _loadHardware(Models& cioNo, Models& dspNo, int pins[], std::optional& power_levels); bool _handlecommand(Commands cmd, int64_t val, const String& txt); void _handleCommandQ(); void _loadSettings(); diff --git a/Code/lib/BWC_unified/enums.h b/Code/lib/BWC_unified/enums.h index 7228fef9..c950340e 100644 --- a/Code/lib/BWC_unified/enums.h +++ b/Code/lib/BWC_unified/enums.h @@ -108,13 +108,20 @@ enum Models: uint8_t struct Power { - int HEATERPOWER; + int HEATERPOWER_STAGE1; + int HEATERPOWER_STAGE2; int PUMPPOWER; int AIRPOWER; int IDLEPOWER; int JETPOWER; }; +struct HeaterStages +{ + bool stage1_on = false; + bool stage2_on = false; +}; + struct sStates { uint8_t locked = 0; diff --git a/Code/lib/cio/CIO_4W.cpp b/Code/lib/cio/CIO_4W.cpp index 6e28619f..c2114af8 100644 --- a/Code/lib/cio/CIO_4W.cpp +++ b/Code/lib/cio/CIO_4W.cpp @@ -25,6 +25,14 @@ void CIO_4W::setup(int cio_rx, int cio_tx, int dummy) _cio_serial->write(_to_CIO_buf, PAYLOADSIZE); //test } +void CIO_4W::setPowerLevels(const std::optional& power_levels) { + if (power_levels.has_value()) { + CIO::setPowerLevels(power_levels); + } else { + CIO::setPowerLevels(_default_power_levels); + } +} + void CIO_4W::stop() { _cio_serial->stopListening(); @@ -67,8 +75,13 @@ void CIO_4W::handleToggles() _to_CIO_buf[i] = _raw_payload_to_cio[i]; // _cio_serial->write(_to_CIO_buf, PAYLOADSIZE); //this is done in updateStates() cio_states.godmode = false; - _power.HEATERPOWER = ((_to_CIO_buf[COMMANDINDEX] & getHeatBitmask1()) == getHeatBitmask1()) * 950 + - ((_to_CIO_buf[COMMANDINDEX] & getHeatBitmask2()) == getHeatBitmask2()) * 950; + + HeaterStages heater_stages { + .stage1_on = (_to_CIO_buf[COMMANDINDEX] & getHeatBitmask1()) == getHeatBitmask1(), + .stage2_on = (_to_CIO_buf[COMMANDINDEX] & getHeatBitmask2()) == getHeatBitmask2(), + }; + setHeaterStages(heater_stages); + if(_readyToTransmit) { _readyToTransmit = false; @@ -259,7 +272,10 @@ void CIO_4W::regulateTemp() _heat_bitmask = getHeatBitmask1(); //half power at start cio_states.heatred = 1; //on _heater2_countdown_ms = _HEATER2_DELAY_MS; - _power.HEATERPOWER = 950; + setHeaterStages({ + .stage1_on = true, + .stage2_on = false, + }); } hysteresis = 0; } @@ -273,7 +289,10 @@ void CIO_4W::regulateTemp() if((_heater2_countdown_ms <= 0) && (cio_states.no_of_heater_elements_on == 2)) { _heat_bitmask = getHeatBitmask1() | getHeatBitmask2(); - _power.HEATERPOWER = 1900; + setHeaterStages({ + .stage1_on = true, + .stage2_on = true, + }); } } diff --git a/Code/lib/cio/CIO_4W.h b/Code/lib/cio/CIO_4W.h index c1edee05..e67a596f 100644 --- a/Code/lib/cio/CIO_4W.h +++ b/Code/lib/cio/CIO_4W.h @@ -14,7 +14,6 @@ class CIO_4W : public CIO public: CIO_4W(){}; virtual ~CIO_4W(){}; - Power getPower(){return _power;} void setup(int cio_rx, int cio_tx, int dummy); void stop(); void pause_all(bool action); @@ -25,6 +24,7 @@ class CIO_4W : public CIO virtual bool getHasair() = 0; bool getSerialReceived() override; void setSerialReceived(bool txok) override; + void setPowerLevels(const std::optional& power_levels) override; /*internal use*/ protected: @@ -44,7 +44,6 @@ class CIO_4W : public CIO private: uint64_t _prev_ms; - Power _power = {1900, 40, 800, 2, 400}; SoftwareSerial *_cio_serial; uint8_t _heat_bitmask = 0; uint8_t _from_CIO_buf[7] = {}; @@ -67,5 +66,14 @@ class CIO_4W : public CIO bool _turn_off_pump_flag = false; bool _serialreceived = false; bool _readyToTransmit = false; + + const Power _default_power_levels = { + .HEATERPOWER_STAGE1 = 950, + .HEATERPOWER_STAGE2 = 950, + .PUMPPOWER = 950, + .AIRPOWER = 950, + .IDLEPOWER = 950, + .JETPOWER = 950, + }; }; diff --git a/Code/lib/cio/CIO_6W.h b/Code/lib/cio/CIO_6W.h index 0390d569..821a41a1 100644 --- a/Code/lib/cio/CIO_6W.h +++ b/Code/lib/cio/CIO_6W.h @@ -17,7 +17,6 @@ class CIO_6W : public CIO public: CIO_6W(); virtual ~CIO_6W(){}; - Power getPower(){return power;} void handleToggles(); bool getHasgod() {return false;} virtual bool getHasjets() = 0; @@ -30,10 +29,6 @@ class CIO_6W : public CIO void _handleButtonQ(void); void unlock(); - /*These must be declared for the API to work*/ - public: - Power power = {1900, 40, 800, 2, 400}; - public: uint8_t brightness; diff --git a/Code/lib/cio/CIO_BASE.cpp b/Code/lib/cio/CIO_BASE.cpp index 5cebb166..45ce1a78 100644 --- a/Code/lib/cio/CIO_BASE.cpp +++ b/Code/lib/cio/CIO_BASE.cpp @@ -24,3 +24,17 @@ String CIO::debug() s += String(good_packets_count); return s; } + +int CIO::getHeaterPower() +{ + return + (_heater_stages.stage1_on ? 1:0) * _power_levels.HEATERPOWER_STAGE1 + + (_heater_stages.stage2_on ? 1:0) * _power_levels.HEATERPOWER_STAGE2; + +} + +void CIO::setPowerLevels(const std::optional& power_levels) { + if(power_levels.has_value()) { + _power_levels = power_levels.value(); + } +} diff --git a/Code/lib/cio/CIO_BASE.h b/Code/lib/cio/CIO_BASE.h index 144ef566..06678e83 100644 --- a/Code/lib/cio/CIO_BASE.h +++ b/Code/lib/cio/CIO_BASE.h @@ -20,13 +20,16 @@ class CIO void setRawPayload(const std::vector& pl); std::vector getRawPayload(); virtual String getModel() = 0; - virtual Power getPower() = 0; virtual bool getHasgod() = 0; virtual bool getHasjets() = 0; virtual bool getHasair() = 0; virtual bool getSerialReceived() {return false;} //"overridden" in CIO 4W virtual void setSerialReceived(bool txok) {} //"overridden" in CIO 4W String debug(); + const Power& getPowerLevels() {return _power_levels;} + virtual void setPowerLevels(const std::optional& power_levels); + void setHeaterStages(const HeaterStages& heater_stages) {_heater_stages = heater_stages;} + int getHeaterPower(); public: sStates cio_states; @@ -38,4 +41,18 @@ class CIO protected: std::vector _raw_payload_from_cio = {0,0,0,0,0,0,0,0,0,0,0}; + + private: + Power _power_levels = { + .HEATERPOWER_STAGE1 = 1900, + .HEATERPOWER_STAGE2 = 0, + .PUMPPOWER = 40, + .AIRPOWER = 800, + .IDLEPOWER = 2, + .JETPOWER = 400, + }; + HeaterStages _heater_stages = { + .stage1_on = true, + .stage2_on = true, + }; }; From 0202a457fd8b0aaf01626ed7a3fc121c407d67cb Mon Sep 17 00:00:00 2001 From: Choumarin Date: Sat, 25 May 2024 15:11:48 -0700 Subject: [PATCH 02/11] Increase json stack allocation --- Code/lib/BWC_unified/bwc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/lib/BWC_unified/bwc.cpp b/Code/lib/BWC_unified/bwc.cpp index 45f2e935..86633abd 100644 --- a/Code/lib/BWC_unified/bwc.cpp +++ b/Code/lib/BWC_unified/bwc.cpp @@ -1219,7 +1219,7 @@ bool BWC::_loadHardware(Models& cioNo, Models& dspNo, int pins[], std::optional< return false; } // DynamicJsonDocument doc(256); - StaticJsonDocument<272> doc; + StaticJsonDocument<512> doc; DeserializationError error = deserializeJson(doc, file); if (error) { // Serial.println(F("Failed to read settings.txt")); From 7a0c3ea042e1eba6f7c8a1d3688e583e93369377 Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Tue, 4 Jun 2024 22:32:46 +0200 Subject: [PATCH 03/11] updated html files internalized 2 *.js files --- Code/data/calib.html | 86 +++++- Code/data/config.html | 83 +++++- Code/data/hwconfig.html | 82 +++++- Code/data/hwtestinfo.html | 81 +++++- Code/data/index.html | 434 +++++++++++++++++++++++++++++- Code/data/index.js | 9 + Code/data/mqtt.html | 82 +++++- Code/data/remove.html | 84 +++++- Code/data/success.html | 82 +++++- Code/data/upload.html | 82 +++++- Code/data/webconfig.html | 82 +++++- Code/data/wifi.html | 82 +++++- Code/lib/BWC_unified/FW_VERSION.h | 2 +- Code/platformio.ini | 10 +- 14 files changed, 1237 insertions(+), 44 deletions(-) diff --git a/Code/data/calib.html b/Code/data/calib.html index ca82bd4f..9b4b6e7a 100644 --- a/Code/data/calib.html +++ b/Code/data/calib.html @@ -5,15 +5,15 @@ - + - - + -
+ +
+ + - + @@ -187,6 +186,83 @@

Hardware:

+ - + @@ -51,7 +50,83 @@ - + diff --git a/Code/data/index.html b/Code/data/index.html index 4772147b..e2dc62ee 100644 --- a/Code/data/index.html +++ b/Code/data/index.html @@ -5,11 +5,13 @@ - + - - + + + + @@ -255,9 +257,350 @@

Totals

+ + + diff --git a/Code/data/index.js b/Code/data/index.js index 7d11913b..f437c50f 100644 --- a/Code/data/index.js +++ b/Code/data/index.js @@ -1,3 +1,12 @@ +/* + THIS FILE IS NOT USED ANYMORE. IT IS MERGED INTO INDEX.HTML FILE +*/ + + + + + + // the web socket connection var connection; diff --git a/Code/data/mqtt.html b/Code/data/mqtt.html index b001799e..23cea464 100644 --- a/Code/data/mqtt.html +++ b/Code/data/mqtt.html @@ -5,11 +5,10 @@ - + - - + @@ -88,6 +87,83 @@ + - + @@ -51,7 +50,84 @@ - + + diff --git a/Code/data/success.html b/Code/data/success.html index d80e2c57..cb5e0ea8 100644 --- a/Code/data/success.html +++ b/Code/data/success.html @@ -5,11 +5,10 @@ - + - - + @@ -49,6 +48,83 @@

Remove a file

+ diff --git a/Code/data/upload.html b/Code/data/upload.html index 2a046dd7..49faa32a 100644 --- a/Code/data/upload.html +++ b/Code/data/upload.html @@ -5,11 +5,10 @@ - + - - + @@ -54,6 +53,83 @@ + diff --git a/Code/data/webconfig.html b/Code/data/webconfig.html index eca88f27..de0ae750 100644 --- a/Code/data/webconfig.html +++ b/Code/data/webconfig.html @@ -5,11 +5,10 @@ - + - - + @@ -77,6 +76,83 @@ + - + @@ -145,6 +144,83 @@

Reset WiFi Config:

+ - - - From ad93023708434b90d886c46c07cb339dc151ef7a Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Thu, 6 Jun 2024 09:51:47 +0200 Subject: [PATCH 06/11] prettify debug output --- Code/lib/BWC_unified/bwc.cpp | 10 +++++----- Code/src/main.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Code/lib/BWC_unified/bwc.cpp b/Code/lib/BWC_unified/bwc.cpp index 86633abd..1eb318e3 100644 --- a/Code/lib/BWC_unified/bwc.cpp +++ b/Code/lib/BWC_unified/bwc.cpp @@ -254,31 +254,31 @@ void BWC::_log() } if(++writes > 1000) return; file.print(_timestamp_secs); - file.printf_P(PSTR("SW:%s CIO-ESP:"), FW_VERSION); + file.printf_P(PSTR("SW:%s \nCIO-ESP:"), FW_VERSION); for(unsigned int i = 0; i< fromcio.size(); i++) { if(i>0)file.print(','); file.print(fromcio[i], HEX); } - file.print(F("\t DSP-ESP:")); + file.print(F("\nDSP-ESP:")); for(unsigned int i = 0; i< fromdsp.size(); i++) { if(i>0)file.print(','); file.print(fromdsp[i], HEX); } - file.print(F(" ESP-CIO:")); + file.print(F("\nESP-CIO:")); for(unsigned int i = 0; i< tocio.size(); i++) { if(i>0)file.print(','); file.print(tocio[i], HEX); } - file.print(F("\t ESP-DSP:")); + file.print(F("\nESP-DSP:")); for(unsigned int i = 0; i< todsp.size(); i++) { if(i>0)file.print(','); file.print(todsp[i], HEX); } - file.printf_P(PSTR("\ncio msg count: %d dsp msg count: %d\n"), cio->good_packets_count, dsp->good_packets_count); + file.printf_P(PSTR("\nCIO msg count: %d DSP msg count: %d\n"), cio->good_packets_count, dsp->good_packets_count); file.close(); } diff --git a/Code/src/main.cpp b/Code/src/main.cpp index 926e3aa0..2fd59bf5 100644 --- a/Code/src/main.cpp +++ b/Code/src/main.cpp @@ -837,7 +837,7 @@ void handleHWtest() delay(0); } - sprintf_P(result, PSTR("End of test!\nErrors indicated by 1 or 0 depending on test state. - is good.\n")); + sprintf_P(result, PSTR("End of test!\n\"1\" or \"0\" indicates ERROR, depending on test state. \"-\" is good.\n")); server->sendContent(result); sprintf_P(result, PSTR("Switching cio pins 5s HIGH -> 5s LOW -> input\n")); server->sendContent(result); From 0feb18b2cc9dd6dd740c1afe024aea282686aeb3 Mon Sep 17 00:00:00 2001 From: visualapproach Date: Thu, 6 Jun 2024 09:52:50 +0200 Subject: [PATCH 07/11] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 3ebda870..396fde39 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# WORK IN PROGRESS! DO NOT DOWNLOAD - WiFi-remote-for-Bestway-Lay-Z-SPA ================================= ESP8266 hack to use as WiFi remote control for Bestway Lay-Z-Spa Whirlpools (including 2021 year models)
From 48486cc32886fd9f5a9c9f195af8847ba204b505 Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Thu, 6 Jun 2024 09:54:01 +0200 Subject: [PATCH 08/11] Update FW version --- Code/lib/BWC_unified/FW_VERSION.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/lib/BWC_unified/FW_VERSION.h b/Code/lib/BWC_unified/FW_VERSION.h index 3fe65ad1..6a8375e7 100644 --- a/Code/lib/BWC_unified/FW_VERSION.h +++ b/Code/lib/BWC_unified/FW_VERSION.h @@ -1 +1 @@ -#define FW_VERSION "2024-06-04-2230" +#define FW_VERSION "2024-06-06-0950" From cccd1d1aeb01918e61b0d84ef2cdbf0a6ea2a24d Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Thu, 6 Jun 2024 11:57:50 +0200 Subject: [PATCH 09/11] platformio USB as default --- Code/platformio.ini | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Code/platformio.ini b/Code/platformio.ini index 98d9e591..085b350c 100644 --- a/Code/platformio.ini +++ b/Code/platformio.ini @@ -63,11 +63,11 @@ monitor_filters = esp8266_exception_decoder default log2file -; upload_protocol = esptool -upload_protocol = espota -upload_port = layzspa.local -upload_flags = - --auth=esp8266 +upload_protocol = esptool +; upload_protocol = espota +; upload_port = layzspa.local +; upload_flags = +; --auth=esp8266 ; [env:esp32] ; platform = espressif32 From a8beaea735df29d5c5bd73299743867328d432bb Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Sat, 8 Jun 2024 19:00:43 +0200 Subject: [PATCH 10/11] Add links.html Links to special URLs --- Code/data/links.html | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Code/data/links.html diff --git a/Code/data/links.html b/Code/data/links.html new file mode 100644 index 00000000..0dae8f0e --- /dev/null +++ b/Code/data/links.html @@ -0,0 +1,7 @@ +/resetwifi/ Be aware!
+/hwtest/ No prior instructions! Use hwtestinfo.html instead.
+/inputs/ Edge counting on pins. Debug feat.
+/restart/
+/info/
+/debug-on/
+/debug-off/
From 1b98abe7e801369dff141c36fd853cc16af62090 Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Sat, 8 Jun 2024 19:01:55 +0200 Subject: [PATCH 11/11] Add signal quality for 4-wire comms When logging using /debug-on/ --- Code/lib/BWC_unified/FW_VERSION.h | 2 +- Code/lib/BWC_unified/bwc.cpp | 26 ++++++++++++++++++++++---- Code/lib/cio/CIO_4W.cpp | 2 +- Code/lib/cio/CIO_BASE.h | 1 + Code/lib/dsp/DSP_4W.cpp | 1 + Code/lib/dsp/DSP_BASE.h | 1 + Code/platformio.ini | 6 +++--- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Code/lib/BWC_unified/FW_VERSION.h b/Code/lib/BWC_unified/FW_VERSION.h index 6a8375e7..705611ed 100644 --- a/Code/lib/BWC_unified/FW_VERSION.h +++ b/Code/lib/BWC_unified/FW_VERSION.h @@ -1 +1 @@ -#define FW_VERSION "2024-06-06-0950" +#define FW_VERSION "2024-06-08-1820" diff --git a/Code/lib/BWC_unified/bwc.cpp b/Code/lib/BWC_unified/bwc.cpp index 1eb318e3..ef3c788c 100644 --- a/Code/lib/BWC_unified/bwc.cpp +++ b/Code/lib/BWC_unified/bwc.cpp @@ -252,9 +252,17 @@ void BWC::_log() // Serial.println(F("Failed to save states.txt")); return; } - if(++writes > 1000) return; - file.print(_timestamp_secs); - file.printf_P(PSTR("SW:%s \nCIO-ESP:"), FW_VERSION); + if(++writes > 1000) + { + file.printf_P(PSTR("\n**** MAX LENGTH OF FILE REACHED. DELETE FILE TO LOG AGAIN")); + return; + } + + tm * p_time_tm = gmtime((time_t*) &_timestamp_secs); + char tm_string[64]; + strftime(tm_string, 64, "%F %T", p_time_tm); + file.print(tm_string); + file.printf_P(PSTR("UTC. SW:%s \nCIO-ESP:"), FW_VERSION); for(unsigned int i = 0; i< fromcio.size(); i++) { if(i>0)file.print(','); @@ -278,7 +286,17 @@ void BWC::_log() if(i>0)file.print(','); file.print(todsp[i], HEX); } - file.printf_P(PSTR("\nCIO msg count: %d DSP msg count: %d\n"), cio->good_packets_count, dsp->good_packets_count); + file.printf_P(PSTR("\nCIO msg count: %d DSP msg count: %d"), cio->good_packets_count, dsp->good_packets_count); + float CIO_quality, DSP_quality; + if(cio->good_packets_count == 0 && cio->bad_packets_count == 0) + CIO_quality = 0; + else + CIO_quality = 100 * cio->good_packets_count / (cio->good_packets_count + cio->bad_packets_count); + if(dsp->good_packets_count == 0 && dsp->bad_packets_count == 0) + DSP_quality = 0; + else + DSP_quality = 100 * dsp->good_packets_count / (dsp->good_packets_count + dsp->bad_packets_count); + file.printf_P(PSTR("\nCIO msg quality: %f%% DSP msg quality: %f%% (Only useful in 4 wire pumps)\n\n"), CIO_quality, DSP_quality); file.close(); } diff --git a/Code/lib/cio/CIO_4W.cpp b/Code/lib/cio/CIO_4W.cpp index c2114af8..8c0257f5 100644 --- a/Code/lib/cio/CIO_4W.cpp +++ b/Code/lib/cio/CIO_4W.cpp @@ -194,7 +194,7 @@ void CIO_4W::updateStates() calculatedChecksum = tempbuffer[1]+tempbuffer[2]+tempbuffer[3]+tempbuffer[4]; if(tempbuffer[CIO_CHECKSUMINDEX] != calculatedChecksum) { - //badCIO_checksum++; + bad_packets_count++; return; } /*message is good if we get here. Continue*/ diff --git a/Code/lib/cio/CIO_BASE.h b/Code/lib/cio/CIO_BASE.h index 06678e83..e69d3d9f 100644 --- a/Code/lib/cio/CIO_BASE.h +++ b/Code/lib/cio/CIO_BASE.h @@ -36,6 +36,7 @@ class CIO sToggles cio_toggles; int _button_que_len = 0; //length of buttonQ uint32_t good_packets_count = 0; + uint32_t bad_packets_count = 0; std::vector _raw_payload_to_cio = {0,0,0,0,0,0,0,0,0,0,0}; int write_msg_count = 0; diff --git a/Code/lib/dsp/DSP_4W.cpp b/Code/lib/dsp/DSP_4W.cpp index 601b4bb0..f0ba6fa2 100644 --- a/Code/lib/dsp/DSP_4W.cpp +++ b/Code/lib/dsp/DSP_4W.cpp @@ -56,6 +56,7 @@ void DSP_4W::updateToggles() calculatedChecksum = tempbuffer[1]+tempbuffer[2]+tempbuffer[3]+tempbuffer[4]; if(tempbuffer[DSP_CHECKSUMINDEX] != calculatedChecksum) { + bad_packets_count++; return; } /*message is good if we get here. Continue*/ diff --git a/Code/lib/dsp/DSP_BASE.h b/Code/lib/dsp/DSP_BASE.h index 1e443998..5164eb49 100644 --- a/Code/lib/dsp/DSP_BASE.h +++ b/Code/lib/dsp/DSP_BASE.h @@ -25,6 +25,7 @@ class DSP std::vector _raw_payload_to_dsp = {0,0,0,0,0,0,0,0,0,0,0}; int audiofrequency = 0; uint32_t good_packets_count = 0; + uint32_t bad_packets_count = 0; int write_msg_count = 0; /* diff --git a/Code/platformio.ini b/Code/platformio.ini index 085b350c..e32338b8 100644 --- a/Code/platformio.ini +++ b/Code/platformio.ini @@ -18,14 +18,14 @@ platform = espressif8266@^4 board = nodemcuv2 framework = arduino lib_deps = - bblanchon/ArduinoJson@6.21.2 + bblanchon/ArduinoJson@6.21.2 ; v7 is using more memory ; mcxiaoke/ESPDateTime links2004/WebSockets knolleary/PubSubClient me-no-dev/ESPAsyncTCP ; khoih-prog/ESP_WifiManager@^1.12.1 - tzapu/WifiManager - https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h in plerup/EspSoftwareSerial@8.2.0 + tzapu/WifiManager + https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h in plerup/EspSoftwareSerial@8.2.0 plerup/EspSoftwareSerial milesburton/DallasTemperature board_build.filesystem = littlefs