Skip to content

Commit

Permalink
Merge pull request #708 from visualapproach/development_v4
Browse files Browse the repository at this point in the history
Development v4
  • Loading branch information
visualapproach authored May 17, 2024
2 parents d3cef1b + e941072 commit 8a9b79f
Show file tree
Hide file tree
Showing 12 changed files with 1,481 additions and 476 deletions.
34 changes: 26 additions & 8 deletions Code/data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@
</tr>
<tr>
<td><label for="finterval">Filter change (Days):</label></td>
<td><input type="text" id="finterval" value="30" maxlength="3" size="3"></td>
<td><input type="text" id="freplaceinterval" value="60" maxlength="3" size="3"></td>
</tr>
<tr>
<td><label for="finterval">Filter clean (Days):</label></td>
<td><input type="text" id="fcleaninterval" value="20" maxlength="3" size="3"></td>
</tr>
<tr>
<td><label for="finterval">Filter rinse (Days):</label></td>
<td><input type="text" id="frinseinterval" value="7" maxlength="3" size="3"></td>
</tr>
<tr>
<td><label for="audio">Audio:</label></td>
Expand All @@ -76,7 +84,7 @@
</tr>
<tr>
<td><label for="calibration">Calibrated:</label><span data-text="If checked, the virtual temperature is calibrated. Redo calibration by unchecking and hitting SAVE button." class="tooltip">?</span></td>
<td><input type="checkbox" id="calibration" onclick="toggleCalibration()"><span data-text="Calibrate by keeping heat OFF and pump ON until temperature has dropped a couple of degrees. Do not toggle jets, bubbles etc meanwhile. Water temp must differ several degrees from ambient from start." class="tooltip">?</span></td>
<td><input type="checkbox" id="calibration" onclick="toggleCalibration()"><span data-text="Calibrate by keeping heat OFF and pump ON until temperature has dropped a couple of degrees. Do not toggle jets, bubbles etc meanwhile. Water temp must differ several degrees from ambient from start." class="tooltip left">?</span></td>
<td><a href="calib.html">manual cal.</a></td>
</tr>
</table>
Expand Down Expand Up @@ -119,7 +127,7 @@
<option value="7">Internal command (get target) (-)</option>
<option value="8">Reset times (-)</option>
<option value="9">Reset Cl timer (-)</option>
<option value="10">Reset filter timer (-)</option>
<option value="10">Reset filter change timer (-)</option>
<option value="11">Set hydrojets (0/1)</option>
<option value="12">Set display brightness (0-8)</option>
<option value="13">Set beep (0/1 or 2+text=filename)</option>
Expand All @@ -130,6 +138,9 @@
<option value="18">Set full power (0/1)</option>
<option value="19">Print (text)</option>
<option value="20">Set ready time (-)</option>
<option value="21">Set R (internal use)</option>
<option value="22">Reset filter rinse timer (-)</option>
<option value="23">Reset filter clean timer (-)</option>
</select>
</td>
</tr>
Expand Down Expand Up @@ -188,7 +199,7 @@ <h2>Command queue</h2>
const gettarget = 7;
const resettimes = 8;
const resetcl = 9;
const resetfilter = 10;
const resetreplacefilter = 10;
const setjets = 11;
const setbrightness = 12;
const setbeep = 13;
Expand All @@ -199,12 +210,15 @@ <h2>Command queue</h2>
const fullpower = 18;
const printtext = 19;
const setready = 20;
const setR = 21;
const resetrinsefiltertimer = 22;
const resetcleanfiltertimer = 23;

const commandlist = [
'Set target', 'Set unit', 'Set bubbles', 'Set heat', 'Set pump', 'Reset queue', 'Reboot ESP',
'Internal cmd', 'Reset times', 'Reset Cl timer', 'Reset filter timer', 'Set jets', 'Set brightness',
'Internal cmd', 'Reset times', 'Reset Cl timer', 'Reset change filter timer', 'Set jets', 'Set brightness',
'Beep', 'Set ambient temp F.', 'Set ambient temp C.', 'Reset daily meter', 'Take control', 'Full power',
'Print text', 'Set ready'
'Print text', 'Set ready', 'Set R', 'Reset rinse filter timer', 'Reset clean filter timer'
];

function totimestamp()
Expand All @@ -226,7 +240,9 @@ <h2>Command queue</h2>
console.log(json);
//document.getElementById('timezone').value = json.TIMEZONE.toString();
document.getElementById('price').value = json.PRICE.toString();
document.getElementById('finterval').value = json.FINT.toString();
document.getElementById('freplaceinterval').value = json.FREPI.toString();
document.getElementById('frinseinterval').value = json.FRINI.toString();
document.getElementById('fcleaninterval').value = json.FCLEI.toString();
document.getElementById('clinterval').value = json.CLINT.toString();
document.getElementById('audio').checked = json.AUDIO;
document.getElementById('notification').checked = json.NOTIFY;
Expand Down Expand Up @@ -266,7 +282,9 @@ <h2>Command queue</h2>
//'TIMEZONE':parseInt(document.getElementById('timezone').value),
'TIMEZONE':0,
'PRICE':parseFloat(document.getElementById('price').value),
'FINT':parseInt(document.getElementById('finterval').value),
'FREPI':parseInt(document.getElementById('freplaceinterval').value),
'FRINI':parseInt(document.getElementById('frinseinterval').value),
'FCLEI':parseInt(document.getElementById('fcleaninterval').value),
'CLINT':parseInt(document.getElementById('clinterval').value),
'AUDIO':document.getElementById('audio').checked,
'NOTIFY':document.getElementById('notification').checked,
Expand Down
12 changes: 10 additions & 2 deletions Code/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,16 @@ <h2>Timer</h2>
<td><button id="cltimerbtn" class="button" onclick="buttonConfirm(this);sendCommand('resetTimerChlorine')">reset</button></td>
</tr>
<tr>
<td>Last filter change was <span id="ftimer">n/a</span> ago.</td>
<td><button id="ftimerbtn" class="button" onclick="buttonConfirm(this);sendCommand('resetTimerFilter')">reset</button></td>
<td>Last filter change was <span id="freplacetimer">n/a</span> ago.</td>
<td><button id="freplacetimerbtn" class="button" onclick="buttonConfirm(this);sendCommand('resetTimerReplaceFilter')">reset</button></td>
</tr>
<tr>
<td>Last filter clean was <span id="fcleantimer">n/a</span> ago.</td>
<td><button id="fcleantimerbtn" class="button" onclick="buttonConfirm(this);sendCommand('resetTimerCleanFilter')">reset</button></td>
</tr>
<tr>
<td>Last filter rinse was <span id="frinsetimer">n/a</span> ago.</td>
<td><button id="frinsetimerbtn" class="button" onclick="buttonConfirm(this);sendCommand('resetTimerRinseFilter')">reset</button></td>
</tr>
</table>
</section>
Expand Down
25 changes: 20 additions & 5 deletions Code/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const cmdMap = {
//gettarget: 7,
resetTotals: 8,
resetTimerChlorine: 9,
resetTimerFilter: 10,
resetTimerReplaceFilter: 10,
toggleHydroJets: 11,
setBrightness: 12,
setBrightnessSelector: 12,
Expand All @@ -28,6 +28,9 @@ const cmdMap = {
setFullpower: 18,
printText: 19,
setReady: 20,
setR: 21,
resetTimerRinseFilter: 22,
resetTimerCleanFilter: 23
};

// button element ID mapping
Expand All @@ -37,7 +40,7 @@ const btnMap = {
toggleHeater: "HTR",
togglePump: "FLT",
toggleHydroJets: "HJT",
toggleGodmode: "GOD",
toggleGodmode: "GOD"
};

// to be used for setting the control values once after loading original values from the web socket
Expand Down Expand Up @@ -227,10 +230,22 @@ function handlemsg(e) {
document.getElementById("cltimerbtn").className = clDate > msgobj.CLINT ? "button_red" : "button";

// filter change reset timer
var fDate = (Date.now() / 1000 - msgobj.FTIME) / (24 * 3600.0);
var fDate = (Date.now() / 1000 - msgobj.FREP) / (24 * 3600.0);
var fDateRound = Math.round(fDate);
document.getElementById("ftimer").innerHTML = fDateRound + " day" + (fDateRound != 1 ? "s" : "");
document.getElementById("ftimerbtn").className = fDate > msgobj.FINT ? "button_red" : "button";
document.getElementById("freplacetimer").innerHTML = fDateRound + " day" + (fDateRound != 1 ? "s" : "");
document.getElementById("freplacetimerbtn").className = fDate > msgobj.FREPI ? "button_red" : "button";

// filter clean reset timer
var fDate = (Date.now() / 1000 - msgobj.FCLE) / (24 * 3600.0);
var fDateRound = Math.round(fDate);
document.getElementById("fcleantimer").innerHTML = fDateRound + " day" + (fDateRound != 1 ? "s" : "");
document.getElementById("fcleantimerbtn").className = fDate > msgobj.FCLEI ? "button_red" : "button";

// filter rinse reset timer
var fDate = (Date.now() / 1000 - msgobj.FRIN) / (24 * 3600.0);
var fDateRound = Math.round(fDate);
document.getElementById("frinsetimer").innerHTML = fDateRound + " day" + (fDateRound != 1 ? "s" : "");
document.getElementById("frinsetimerbtn").className = fDate > msgobj.FRINI ? "button_red" : "button";

// statistics
document.getElementById("heatingtime").innerHTML = s2dhms(msgobj.HEATINGTIME);
Expand Down
2 changes: 1 addition & 1 deletion Code/lib/BWC_unified/FW_VERSION.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define FW_VERSION "2023-11-19-1330"
#define FW_VERSION "2024-05-09-1955"
96 changes: 65 additions & 31 deletions Code/lib/BWC_unified/bwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ BWC::BWC()

_dsp_brightness = 7;
_cl_timestamp_s = time(nullptr);
_filter_timestamp_s = time(nullptr);
_filter_replace_timestamp_s = time(nullptr);
_filter_clean_timestamp_s = _filter_replace_timestamp_s;
_filter_rinse_timestamp_s = _filter_replace_timestamp_s;
_uptime = 0;
_pumptime = 0;
_heatingtime = 0;
_airtime = 0;
_jettime = 0;
_price = 1;
_filter_interval = 30;
_filter_rinse_interval = 7;
_filter_clean_interval = 20;
_filter_replace_interval = 60;
_cl_interval = 14;
_audio_enabled = true;
_restore_states_on_start = false;
Expand Down Expand Up @@ -466,6 +470,7 @@ bool BWC::_handlecommand(Commands cmd, int64_t val, const String& txt="")
_heatingtime_ms = 0;
_airtime_ms = 0;
_energy_total_kWh = 0;
_energy_cost = 0;
_save_settings_needed = true;
_new_data_available = true;
break;
Expand All @@ -474,8 +479,18 @@ bool BWC::_handlecommand(Commands cmd, int64_t val, const String& txt="")
_save_settings_needed = true;
_new_data_available = true;
break;
case RESETFTIMER:
_filter_timestamp_s = _timestamp_secs;
case RESETFREPLACETIMER:
_filter_replace_timestamp_s = _timestamp_secs;
_save_settings_needed = true;
_new_data_available = true;
break;
case RESETFCLEANTIMER:
_filter_clean_timestamp_s = _timestamp_secs;
_save_settings_needed = true;
_new_data_available = true;
break;
case RESETFRINSETIMER:
_filter_rinse_timestamp_s = _timestamp_secs;
_save_settings_needed = true;
_new_data_available = true;
break;
Expand Down Expand Up @@ -949,14 +964,18 @@ void BWC::getJSONTimes(String &rtn) {
doc[F("CONTENT")] = F("TIMES");
doc[F("TIME")] = _timestamp_secs;
doc[F("CLTIME")] = _cl_timestamp_s;
doc[F("FTIME")] = _filter_timestamp_s;
doc[F("FREP")] = _filter_replace_timestamp_s;
doc[F("FRIN")] = _filter_rinse_timestamp_s;
doc[F("FCLE")] = _filter_clean_timestamp_s;
doc[F("UPTIME")] = _uptime + _uptime_ms/1000;
doc[F("PUMPTIME")] = _pumptime + _pumptime_ms/1000;
doc[F("HEATINGTIME")] = _heatingtime + _heatingtime_ms/1000;
doc[F("AIRTIME")] = _airtime + _airtime_ms/1000;
doc[F("JETTIME")] = _jettime + _jettime_ms/1000;
doc[F("COST")] = _energy_total_kWh * _price;
doc[F("FINT")] = _filter_interval;
doc[F("COST")] = _energy_cost;
doc[F("FREPI")] = _filter_replace_interval;
doc[F("FRINI")] = _filter_rinse_interval;
doc[F("FCLEI")] = _filter_clean_interval;
doc[F("CLINT")] = _cl_interval;
doc[F("KWH")] = _energy_total_kWh;
doc[F("KWHD")] = _energy_daily_Ws / 3600000.0; //Ws -> kWh
Expand Down Expand Up @@ -994,7 +1013,9 @@ void BWC::getJSONSettings(String &rtn){
// Set the values in the document
doc[F("CONTENT")] = F("SETTINGS");
doc[F("PRICE")] = _price;
doc[F("FINT")] = _filter_interval;
doc[F("FREPI")] = _filter_replace_interval;
doc[F("FRINI")] = _filter_rinse_interval;
doc[F("FCLEI")] = _filter_clean_interval;
doc[F("CLINT")] = _cl_interval;
doc[F("AUDIO")] = _audio_enabled;
#ifdef ESP8266
Expand Down Expand Up @@ -1075,25 +1096,27 @@ void BWC::setJSONSettings(const String& message){
return;
}

// Copy values from the JsonDocument to the variables
_price = doc[F("PRICE")];
_filter_interval = doc[F("FINT")];
_cl_interval = doc[F("CLINT")];
_audio_enabled = doc[F("AUDIO")];
_restore_states_on_start = doc[F("RESTORE")];
_notify = doc[F("NOTIFY")];
_notification_time = doc[F("NOTIFTIME")];
_vt_calibrated = doc[F("VTCAL")];
dsp->EnabledButtons[LOCK] = doc[F("LCK")];
dsp->EnabledButtons[TIMER] = doc[F("TMR")];
dsp->EnabledButtons[BUBBLES] = doc[F("AIR")];
dsp->EnabledButtons[UNIT] = doc[F("UNT")];
dsp->EnabledButtons[HEAT] = doc[F("HTR")];
dsp->EnabledButtons[PUMP] = doc[F("FLT")];
dsp->EnabledButtons[DOWN] = doc[F("DN")];
dsp->EnabledButtons[UP] = doc[F("UP")];
dsp->EnabledButtons[POWER] = doc[F("PWR")];
dsp->EnabledButtons[HYDROJETS] = doc[F("HJT")];
// Copy existing values from the JsonDocument to the variables
_price = doc[F("PRICE")] | _price;
_filter_replace_interval = doc[F("FREPI")] | _filter_replace_interval;
_filter_rinse_interval = doc[F("FRINI")] | _filter_rinse_interval;
_filter_clean_interval = doc[F("FCLEI")] | _filter_clean_interval;
_cl_interval = doc[F("CLINT")] | _cl_interval;
_audio_enabled = doc[F("AUDIO")] | _audio_enabled;
_restore_states_on_start = doc[F("RESTORE")] | _restore_states_on_start;
_notify = doc[F("NOTIFY")] | _notify;
_notification_time = doc[F("NOTIFTIME")] | _notification_time;
_vt_calibrated = doc[F("VTCAL")] | _vt_calibrated;
dsp->EnabledButtons[LOCK] = doc[F("LCK")] | dsp->EnabledButtons[LOCK];
dsp->EnabledButtons[TIMER] = doc[F("TMR")] | dsp->EnabledButtons[TIMER];
dsp->EnabledButtons[BUBBLES] = doc[F("AIR")] | dsp->EnabledButtons[BUBBLES];
dsp->EnabledButtons[UNIT] = doc[F("UNT")] | dsp->EnabledButtons[UNIT];
dsp->EnabledButtons[HEAT] = doc[F("HTR")] | dsp->EnabledButtons[HEAT];
dsp->EnabledButtons[PUMP] = doc[F("FLT")] | dsp->EnabledButtons[PUMP];
dsp->EnabledButtons[DOWN] = doc[F("DN")] | dsp->EnabledButtons[DOWN];
dsp->EnabledButtons[UP] = doc[F("UP")] | dsp->EnabledButtons[UP];
dsp->EnabledButtons[POWER] = doc[F("PWR")] | dsp->EnabledButtons[POWER];
dsp->EnabledButtons[HYDROJETS] = doc[F("HJT")] | dsp->EnabledButtons[HYDROJETS];
saveSettings();
}

Expand Down Expand Up @@ -1160,6 +1183,7 @@ void BWC::_updateTimes(){
_energy_power_W += cio->cio_states.jets * cio->getPower().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

if(_notes.size())
{
Expand Down Expand Up @@ -1245,20 +1269,25 @@ void BWC::_loadSettings(){

// Copy values from the JsonDocument to the variables
_cl_timestamp_s = doc[F("CLTIME")];
_filter_timestamp_s = doc[F("FTIME")];
_filter_replace_timestamp_s = doc[F("FREP")];
_filter_rinse_timestamp_s = doc[F("FRIN")];
_filter_clean_timestamp_s = doc[F("FCLE")];
_uptime = doc[F("UPTIME")];
_pumptime = doc[F("PUMPTIME")];
_heatingtime = doc[F("HEATINGTIME")];
_airtime = doc[F("AIRTIME")];
_jettime = doc[F("JETTIME")];
_price = doc[F("PRICE")];
_filter_interval = doc[F("FINT")];
_filter_replace_interval = doc[F("FREPI")] | _filter_replace_interval;
_filter_rinse_interval = doc[F("FRINI")] | _filter_rinse_interval;
_filter_clean_interval = doc[F("FCLEI")] | _filter_clean_interval;
_cl_interval = doc[F("CLINT")];
_audio_enabled = doc[F("AUDIO")];
_notify = doc[F("NOTIFY")];
_notification_time = doc[F("NOTIFTIME")];
_energy_total_kWh = doc[F("KWH")];
_energy_daily_Ws = doc[F("KWHD")];
_energy_cost = doc[F("COST")];
_restore_states_on_start = doc[F("RESTORE")];
_R_COOLING = doc[F("R")] | 40.0f; //else use default
_ambient_temp = doc[F("AMB")] | 20;
Expand Down Expand Up @@ -1499,18 +1528,23 @@ void BWC::saveSettings(){
_uptime_ms = 0;
// Set the values in the document
doc[F("CLTIME")] = _cl_timestamp_s;
doc[F("FTIME")] = _filter_timestamp_s;
doc[F("FREP")] = _filter_replace_timestamp_s;
doc[F("FRIN")] = _filter_rinse_timestamp_s;
doc[F("FCLE")] = _filter_clean_timestamp_s;
doc[F("UPTIME")] = _uptime;
doc[F("PUMPTIME")] = _pumptime;
doc[F("HEATINGTIME")] = _heatingtime;
doc[F("AIRTIME")] = _airtime;
doc[F("JETTIME")] = _jettime;
doc[F("PRICE")] = _price;
doc[F("FINT")] = _filter_interval;
doc[F("FREPI")] = _filter_replace_interval;
doc[F("FRINI")] = _filter_rinse_interval;
doc[F("FCLEI")] = _filter_clean_interval;
doc[F("CLINT")] = _cl_interval;
doc[F("AUDIO")] = _audio_enabled;
doc[F("KWH")] = _energy_total_kWh;
doc[F("KWHD")] = _energy_daily_Ws;
doc[F("COST")] = _energy_cost;
// doc[F("SAVETIME")] = DateTime.format(DateFormatter::SIMPLE);
doc[F("RESTORE")] = _restore_states_on_start;
doc[F("R")] = _R_COOLING;
Expand Down
9 changes: 7 additions & 2 deletions Code/lib/BWC_unified/bwc.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class BWC {
std::vector<sNote> _notes;
sStates _prev_cio_states, _prev_dsp_states;
uint32_t _cl_timestamp_s;
uint32_t _filter_timestamp_s;
uint32_t _filter_rinse_timestamp_s;
uint32_t _filter_clean_timestamp_s;
uint32_t _filter_replace_timestamp_s;
uint32_t _uptime;
uint32_t _pumptime;
uint32_t _heatingtime;
Expand All @@ -152,7 +154,9 @@ class BWC {
uint32_t _heatingtime_ms;
uint32_t _airtime_ms;
uint32_t _jettime_ms;
uint32_t _filter_interval;
uint32_t _filter_rinse_interval;
uint32_t _filter_clean_interval;
uint32_t _filter_replace_interval;
uint32_t _cl_interval;
uint32_t _virtual_temp_fix_age;
int _note_duration;
Expand All @@ -164,6 +168,7 @@ class BWC {
int _deltatemp;
float _price;
float _energy_total_kWh;
double _energy_cost;
float _R_COOLING = 40;
float _heating_degperhour = 1.5; //always in C internally
float _virtual_temp; //=virtualtempfix+calculated diff, always in C internally
Expand Down
Loading

0 comments on commit 8a9b79f

Please sign in to comment.