Skip to content

Commit

Permalink
SOH config web page changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartpittaway committed Dec 8, 2023
1 parent a4abab1 commit f3f825a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
1 change: 1 addition & 0 deletions ESPController/include/webserver_json_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern void configureSNTP(long gmtOffset_sec, int daylightOffset_sec, const char
extern void DefaultConfiguration(diybms_eeprom_settings *_myset);
extern bool SaveWIFIJson(const wifi_eeprom_settings* setting);
extern void randomCharacters(char *value, int length);
extern void CalculateStateOfHealth(diybms_eeprom_settings *settings);

esp_err_t post_savebankconfig_json_handler(httpd_req_t *req, bool urlEncoded);
esp_err_t post_saventp_json_handler(httpd_req_t *req, bool urlEncoded);
Expand Down
4 changes: 4 additions & 0 deletions ESPController/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ void ValidateConfiguration(diybms_eeprom_settings *settings)
{
settings->stateofchargeresumevalue = settings->stateofchargeresumevalue;
}

if (settings->soh_discharge_depth==0 || settings->soh_discharge_depth>100) {
settings->soh_discharge_depth=80;
}
}

// Builds up a JSON document which mirrors the parameters inside "diybms_eeprom_settings"
Expand Down
33 changes: 21 additions & 12 deletions ESPController/src/webserver_json_post.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ esp_err_t post_savechargeconfig_json_handler(httpd_req_t *req, bool urlEncoded)
mysettings.canbusinverter = CanBusInverter::INVERTER_GENERIC;
}

GetKeyValue(httpbuf, "expected_cycles", &mysettings.soh_lifetime_battery_cycles, urlEncoded);
GetKeyValue(httpbuf, "dischargedepth", &mysettings.soh_discharge_depth, urlEncoded);

if (GetKeyValue(httpbuf, "total_ah_discharge", &mysettings.soh_total_milliamphour_out, urlEncoded))
{
mysettings.soh_total_milliamphour_out = mysettings.soh_total_milliamphour_out * 1000;
}
if (GetKeyValue(httpbuf, "total_ah_charge", &mysettings.soh_total_milliamphour_in, urlEncoded))
{
mysettings.soh_total_milliamphour_in = mysettings.soh_total_milliamphour_in * 1000;
}

CalculateStateOfHealth(&mysettings);

saveConfiguration();

return SendSuccess(req);
Expand Down Expand Up @@ -643,9 +657,9 @@ esp_err_t post_savecmrelay_json_handler(httpd_req_t *req, bool urlEncoded)
}

/// @brief Generates new home assistant API key and stored into flash
/// @param req
/// @param urlEncoded
/// @return
/// @param req
/// @param urlEncoded
/// @return
esp_err_t post_homeassistant_apikey_json_handler(httpd_req_t *req, bool urlEncoded)
{
char buffer[32];
Expand Down Expand Up @@ -1063,6 +1077,9 @@ esp_err_t post_saverules_json_handler(httpd_req_t *req, bool urlEncoded)

esp_err_t post_restoreconfig_json_handler(httpd_req_t *req, bool urlEncoded)
{
// Needs to be large enough to de-serialize the JSON file
DynamicJsonDocument doc(8000);

bool success = false;

if (_avrsettings.programmingModeEnabled)
Expand All @@ -1081,9 +1098,7 @@ esp_err_t post_restoreconfig_json_handler(httpd_req_t *req, bool urlEncoded)
}

uint16_t flashram = 0;
if (GetKeyValue(httpbuf, "flashram", &flashram, urlEncoded))
{
}
GetKeyValue(httpbuf, "flashram", &flashram, urlEncoded);

if (flashram == 0)
{
Expand All @@ -1098,9 +1113,6 @@ esp_err_t post_restoreconfig_json_handler(httpd_req_t *req, bool urlEncoded)
{
ESP_LOGI(TAG, "Restore SD config from %s", filename);

// Needs to be large enough to de-serialize the JSON file
DynamicJsonDocument doc(5000);

File file = SD.open(filename, "r");

// Deserialize the JSON document
Expand Down Expand Up @@ -1143,9 +1155,6 @@ esp_err_t post_restoreconfig_json_handler(httpd_req_t *req, bool urlEncoded)
{
ESP_LOGI(TAG, "Restore LittleFS config from %s", filename);

// Needs to be large enough to de-serialize the JSON file
DynamicJsonDocument doc(5500);

File file = LittleFS.open(filename, "r");

// Deserialize the JSON document
Expand Down
2 changes: 1 addition & 1 deletion ESPController/src/webserver_json_requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ esp_err_t content_handler_chargeconfig(httpd_req_t *req)
settings["equip_addr"] = mysettings.canbus_equipment_addr;
settings["nominalbatcap"] = mysettings.nominalbatcap;

settings["depthofdischarge"] = mysettings.soh_discharge_depth;
settings["dischargedepth"] = mysettings.soh_discharge_depth;
settings["expectedlifetime_cycles"] = mysettings.soh_lifetime_battery_cycles;
settings["total_mah_charge"] = mysettings.soh_total_milliamphour_in;
settings["total_mah_discharge"] = mysettings.soh_total_milliamphour_out;
Expand Down
6 changes: 5 additions & 1 deletion ESPController/web_src/default.htm
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,13 @@ <h1 id="v0">Charge/Discharge configuration</h1>
<input id="nominalbatcap" name="nominalbatcap" value="" type="number" min="1" max="9999" step="1" />
</div>
<div>
<label for="expected_cycles">Expected battery lifetime/cycles (at 80%% DOD)</label>
<label for="expected_cycles">Expected battery lifetime/cycles (at DOD)</label>
<input id="expected_cycles" name="expected_cycles" value="" type="number" min="100" max="99999" step="1" />
</div>
<div>
<label for="dischargedepth">Discharge depth %% (DOD)</label>
<input id="dischargedepth" name="dischargedepth" value="" type="number" min="10" max="100" step="1" />
</div>
<div>
<label for="total_ah_charge">Lifetime amp-hours charge (in)</label>
<input id="total_ah_charge" name="total_ah_charge" value="" type="number" min="0" step="1" />
Expand Down
19 changes: 10 additions & 9 deletions ESPController/web_src/pagecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1613,17 +1613,17 @@ $(function () {

$("#networkForm").show();


$("#rssi_now").val(data.wifi.rssi);
$("#bssid").val(data.wifi.bssid);
$("#ssid").val(data.wifi.ssid);

$("#rssi_low").val(data.wifi.rssi_low);
$("#sta_start").val(data.wifi.sta_start);
$("#sta_connected").val(data.wifi.sta_connected);
$("#sta_disconnected").val(data.wifi.sta_disconnected);
$("#sta_lost_ip").val(data.wifi.sta_lost_ip);
$("#sta_got_ip").val(data.wifi.sta_got_ip);
$("#sta_got_ip").val(data.wifi.sta_got_ip);

}).fail(function () { $.notify("Request failed", { autoHide: true, globalPosition: 'top right', className: 'error' }); }
);
Expand Down Expand Up @@ -1766,8 +1766,8 @@ $(function () {
$("#influxOrgId").val(data.influxdb.orgid);
$("#influxFreq").val(data.influxdb.frequency);

$("#haUrl").val(window.location.origin+"/ha");
$("#haAPI").val(data.ha.api);
$("#haUrl").val(window.location.origin + "/ha");
$("#haAPI").val(data.ha.api);

$("#haForm").show();
$("#mqttForm").show();
Expand Down Expand Up @@ -2004,8 +2004,9 @@ $(function () {
$("#nominalbatcap").val(data.chargeconfig.nominalbatcap);

$("#expected_cycles").val(data.chargeconfig.expectedlifetime_cycles);
$("#total_ah_charge").val(Math.trunc(data.chargeconfig.total_mah_charge/1000));
$("#total_ah_discharge").val(Math.trunc(data.chargeconfig.total_mah_discharge/1000));
$("#dischargedepth").val(data.chargeconfig.dischargedepth);
$("#total_ah_charge").val(Math.trunc(data.chargeconfig.total_mah_charge / 1000));
$("#total_ah_discharge").val(Math.trunc(data.chargeconfig.total_mah_discharge / 1000));
$("#estimate_bat_cycle").val(data.chargeconfig.estimatebatterycycle);
$("#stateofhealth").val((data.chargeconfig.stateofhealth).toFixed(2));

Expand Down Expand Up @@ -2135,7 +2136,7 @@ $(function () {
},
});
});

$("#haForm").unbind('submit').submit(function (e) {
e.preventDefault();

Expand All @@ -2152,7 +2153,7 @@ $(function () {
},
});
});


$("#rulesForm").unbind('submit').submit(function (e) {
e.preventDefault();
Expand Down

0 comments on commit f3f825a

Please sign in to comment.