Skip to content

Commit

Permalink
1.1.6 calculate electro correct
Browse files Browse the repository at this point in the history
  • Loading branch information
dontsovcmc committed Oct 31, 2024
1 parent e75ff79 commit ac54052
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ESP8266/data/input_electro_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2 id="counter_title-2"></h2>
</select>
</div>
<div class="f-row">
<label for="factor">Количество импульсов на литр</label>
<label for="factor">Количество импульсов на кВт</label>
<input pattern="^\s*[\d]+([,\.][\d]+)?\s*$" id="factor" name="factor" placeholder="0" value="%factor%">
<p class="error hd" id="factor-error">Некорректное значение</p>
</div>
Expand Down
3 changes: 2 additions & 1 deletion ESP8266/data/input_setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ <h2 id="input_color">Синий вход</h2>
<option value="1">Горячую воду</option>
<option value="2">Электричество</option>
<option value="3">Газ</option>
<option value="4">Тепло</option>
<option value="4">Тепло (Гкал)</option>
<option value="5">Питьевую воду</option>
<option value="6">Другой</option>
<option value="7">Тепло (кВт)</option>
</select>
<p class="error hd" id="counter_name-error">Некорректное значение</p>
</div>
Expand Down
22 changes: 10 additions & 12 deletions ESP8266/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@ bool load_config(Settings &sett)
LOG_INFO(F("wifi_channel=") << sett.wifi_channel);
LOG_INFO(F("wifi_phy_mode=") << wifi_phy_mode_title((WiFiPhyMode_t)sett.wifi_phy_mode));

// Всегда одно и тоже будет
LOG_INFO(F("--- Counters ---- "));
LOG_INFO(F("channel0 start=") << sett.channel0_start << F(", impulses=") << sett.impulses0_start << F(", factor=") << sett.factor0 << F(", name=") << sett.counter0_name);
LOG_INFO(F("channel1 start=") << sett.channel1_start << F(", impulses=") << sett.impulses1_start << F(", factor=") << sett.factor1 << F(", name=") << sett.counter1_name);

LOG_INFO(F("Config succesfully loaded"));
return true;
}
Expand All @@ -256,8 +251,6 @@ bool load_config(Settings &sett)
void calculate_values(Settings &sett, const SlaveData &data, CalculatedData &cdata)
{
LOG_INFO(F("Calculating values..."));
LOG_INFO(F("new impulses=") << data.impulses0 << " " << data.impulses1);
LOG_INFO(F("factor0=") << sett.factor0 << F(" factor1=") << sett.factor1);

if (sett.factor0 > 0)
{
Expand All @@ -270,7 +263,7 @@ void calculate_values(Settings &sett, const SlaveData &data, CalculatedData &cda
if (sett.counter0_name == CounterName::ELECTRO)
{
// factor0 кол-во импульсов на 1 кВт * ч
cdata.channel0 = sett.channel0_start + (data.impulses0 - sett.impulses0_start) / sett.factor0;
cdata.channel0 = sett.channel0_start + (data.impulses0 - sett.impulses0_start) / 1.0 * sett.factor0;
cdata.delta0 = (data.impulses0 - sett.impulses0_previous) / sett.factor0;
}
else
Expand All @@ -279,9 +272,12 @@ void calculate_values(Settings &sett, const SlaveData &data, CalculatedData &cda
cdata.channel0 = sett.channel0_start + (data.impulses0 - sett.impulses0_start) / 1000.0 * sett.factor0;
cdata.delta0 = (data.impulses0 - sett.impulses0_previous) * sett.factor0;
}
LOG_INFO(F("new value0=") << cdata.channel0 << F(" delta0=") << cdata.delta0);
}

LOG_INFO(F("channel0 name=") << sett.counter0_name);
LOG_INFO(F("impulses0 start=") << sett.impulses0_start << F(" current=") << data.impulses0 << F(" factor=") << sett.factor0);
LOG_INFO(F("value0 start=") << sett.channel0_start << F(" current=") << cdata.channel0 << F(" delta=") << cdata.delta0);

if (sett.factor1 > 0)
{
if (data.impulses1 < sett.impulses1_start) {
Expand All @@ -292,18 +288,20 @@ void calculate_values(Settings &sett, const SlaveData &data, CalculatedData &cda
if (sett.counter1_name == CounterName::ELECTRO)
{
// factor1 кол-во импульсов на 1 кВт * ч
cdata.channel1 = sett.channel1_start + (data.impulses1 - sett.impulses1_start) / sett.factor1;
cdata.delta1 = (data.impulses1 - sett.impulses1_previous) / sett.factor1;
cdata.channel1 = sett.channel1_start + (data.impulses1 - sett.impulses1_start) / (sett.factor1 * 1.0);
cdata.delta1 = (data.impulses1 - sett.impulses1_previous) / (sett.factor1 * 1.0);
}
else
{
// factor1 кол-во литров на 1 импульс, переводим в кубометры
cdata.channel1 = sett.channel1_start + (data.impulses1 - sett.impulses1_start) / 1000.0 * sett.factor1;
cdata.delta1 = (data.impulses1 - sett.impulses1_previous) * sett.factor1;
}
LOG_INFO(F("new value1=") << cdata.channel1 << F(" delta1=") << cdata.delta1);
}

LOG_INFO(F("channel1 name=") << sett.counter1_name);
LOG_INFO(F("impulses1 start=") << sett.impulses1_start << F(" current=") << data.impulses1 << F(" factor=") << sett.factor1);
LOG_INFO(F("value1 start=") << sett.channel1_start << F(" current=") << cdata.channel1 << F(" delta=") << cdata.delta1);
}

/* Обновляем значения в конфиге*/
Expand Down

0 comments on commit ac54052

Please sign in to comment.