Skip to content

Commit

Permalink
add new battey stats to frontend stats, add battery reset buttons to …
Browse files Browse the repository at this point in the history
…settings page, fix error shown while firmware update, pushed to OWIE version 2.1.0
  • Loading branch information
Michael Retich committed Jan 10, 2024
1 parent 2f2065f commit 490bab4
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 59 deletions.
56 changes: 0 additions & 56 deletions data/battery.html

This file was deleted.

13 changes: 13 additions & 0 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
<button id="fwUpdBtn">Browse Firmware File (.bin, .bin.gz)</button>
</div>
</div>
<div class="divider"></div>
<div class="battery-status header">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="content-icon">
<path d="M16.67,4H15V2H9V4H7.33A1.33,1.33 0 0,0 6,5.33V20.67C6,21.4 6.6,22 7.33,22H16.67A1.33,1.33 0 0,0 18,20.67V5.33C18,4.6 17.4,4 16.67,4Z" />
</svg>
<span class="title">Battery Info Reset</span>
</div>
<div class="battery-status content">
<div>
<button class="battery-reset button" data-type="stats">Reset Stats</button>
<button class="battery-reset button" data-type="settings">Reset Settings</button>
</div>
</div>
</div>
</div>
<!-- Settings End -->
Expand Down
28 changes: 27 additions & 1 deletion data/owie.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let currentChargingState = null;
let statsDomWritten = false;
let updateInterval = 1000; // in ms
let currentSeverityOffset = 0;
let processUpdate = false;
// TODO: probably make the offset(s) configurable?
// offset for warning severity when battery cells are unbalanced
const batteryCellOffsetWarning = 0.4;
Expand Down Expand Up @@ -409,6 +410,19 @@ let disarmBoard = async (btn) => {
}
}

// API Call to reset battery stats/settings
let resetBatteryStats = async (type) => {
try {
let formData = new FormData();
formData.append("type", type);
await callOwieApi("POST", "battery", formData);
showAlerter("success","Successfully resetted battery "+type+" !");
} catch (e) {
handleError(e);
}
}


// handling the alerter toaster
let showAlerter = (alertType, alertText, showClose=true) => {
const alerter = document.getElementById("toaster");
Expand Down Expand Up @@ -565,6 +579,10 @@ let handleMetadata = async () => {
// this is currently set to every second and can be configured by setting "updateInterval"
let getAutoupdate = async () => {
try {
if (processUpdate) {
console.info("Firmwareupdate is in progress, autoupdate is suspended until reload of the page!");
return;
}
let data = await callOwieApi("GET", "autoupdate", null);
let jsonData = JSON.parse(data);

Expand Down Expand Up @@ -654,7 +672,7 @@ let getAutoupdate = async () => {
}
item.value.forEach((value, idx) => {
let baseEl = document.getElementsByClassName(`stats-${key}_${idx}`)[0];
baseEl.querySelector('.owie-label').innerHTML = key.toUpperCase() + "&nbsp;" + ((item.value.length > 1)?idx:"");
baseEl.querySelector('.owie-label').innerHTML = (item.label ||key.toUpperCase()) + "&nbsp;" + ((item.value.length > 1)?idx:"");
baseEl.querySelector('.value-text').innerHTML = value;
baseEl.querySelector('.value-label').innerHTML = "&nbsp;" + item.unit;
});
Expand All @@ -681,6 +699,13 @@ let startup = async () => {
await disarmBoard(unlockButton);
})

// handle clicking one of the battery reset buttons
document.querySelectorAll(".battery-reset").forEach((btn) => {
btn.addEventListener('click', async (e) => {
await resetBatteryStats(btn.dataset.type);
})
})

// firmware update section
const firmwareInput = document.getElementById("fwUpdInput");
const updateUpdateBtn = document.getElementById("fwUpdBtn");
Expand Down Expand Up @@ -712,6 +737,7 @@ let startup = async () => {
// This may be a minify problem!! (removing parenteses by function call);
let fileUploadData = new FormData();
fileUploadData.append("firmware", file);
processUpdate = true;
await callOwieApi("POST", "update", fileUploadData ,({loaded, total}) => {
let fileLoaded = Math.floor((loaded / total) * 100);
updateText.innerHTML = `File upload in progress... (${fileLoaded}%)`;
Expand Down
12 changes: 12 additions & 0 deletions data/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,14 @@ input[type=text], input[type=password], select {
margin-bottom: 21px;
}

.firmware.content {
margin-bottom: 21px;
}

.battery-reset.button {
margin-bottom: 5px;
}

.box {
flex: auto;
display: flex;
Expand Down Expand Up @@ -1119,4 +1127,8 @@ input[type=text], input[type=password], select {
border: 1px solid var(--text-color);
width: 100%;
opacity: 0.6;
}
/* every button class should have a pointer cursor */
.button {
cursor: pointer;
}
54 changes: 52 additions & 2 deletions src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AsyncWebSocket ws("/rawdata");
const String defaultPass("****");
BmsRelay *relay;

const String owie_version = "2.0.0-dev";
const String owie_version = "2.1.0";

bool lockingPreconditionsMet() {
return strlen(Settings->ap_self_password) > 0;
Expand Down Expand Up @@ -133,7 +133,7 @@ DynamicJsonDocument generateMetadataJson() {
}

DynamicJsonDocument generateOwieStatusJson() {
DynamicJsonDocument statusDoc(1024);
DynamicJsonDocument statusDoc(1512);
JsonObject root = statusDoc.to<JsonObject>();
const uint16_t *cellMillivolts = relay->getCellMillivolts();
const int8_t *thermTemps = relay->getTemperaturesCelsius();
Expand Down Expand Up @@ -199,6 +199,36 @@ DynamicJsonDocument generateOwieStatusJson() {
bms_serial["value"] = relay->getCapturedBMSSerial();
bms_serial["unit"] = "";

// add new battery status values (used only at stats page.)
// normaly there would be a reset for the stats, but as the project is more or less abandoned from the maintainer...
// (no effort is put into this any more...)
// add current read out BMS Serial Nr.
JsonObject voltage_based_soc = root.createNestedObject("voltage_based_soc");
voltage_based_soc["value"] = String(relay->getBatteryFuelGauge().getVoltageBasedSoc());
voltage_based_soc["unit"] = "%";

JsonObject bottom_soc = root.createNestedObject("bottom_soc");
bottom_soc["value"] = String(relay->getBatteryFuelGauge().getState().bottomSoc);
bottom_soc["label"] = "Lowest Ah-tracked SOC";
bottom_soc["unit"] = "%";

JsonObject top_soc = root.createNestedObject("top_soc");
top_soc["value"] = String(relay->getBatteryFuelGauge().getState().topSoc);
top_soc["label"] = "Highest Ah-tracked SOC";
top_soc["unit"] = "%";

JsonObject bottom_milliamp_hours = root.createNestedObject("bottom_milliamp_hours");
bottom_milliamp_hours["value"] = String(
relay->getBatteryFuelGauge().getState().bottomMilliampSeconds / 3600);
bottom_milliamp_hours["label"] = "Ah-tracked range size";
bottom_milliamp_hours["unit"] = "mAh";

JsonObject current_milliamp_hours = root.createNestedObject("current_milliamp_hours");
current_milliamp_hours["value"] = String(
relay->getBatteryFuelGauge().getState().currentMilliampSeconds / 3600);
current_milliamp_hours["label"] = "Current discharge depth";
current_milliamp_hours["unit"] = "mAh";

return statusDoc;

}
Expand Down Expand Up @@ -335,6 +365,26 @@ void setupWebServer(BmsRelay *bmsRelay) {
}
request->send(404);
});

webServer.on("/battery", HTTP_POST, [](AsyncWebServerRequest *request) {
const auto resetType = request->getParam("type", true);

if (strcmp(resetType->value().c_str(), "stats") == 0) {
relay->getBatteryFuelGauge().reset();
request->send(200, "text/html", "Battery stats resetted!");
return;
}
if (strcmp(resetType->value().c_str(), "settings") == 0) {
Settings->battery_state = BatteryStateMsg_init_default;
saveSettings();
request->send(200, "text/html", "Battery settings resetted!");
return;
}
request->send(400, "text/html",
"You must provide a correct type to be resettet (stats||settings)!");
return;
});

webServer.on("/lock", HTTP_GET, [](AsyncWebServerRequest *request) {
if (request->hasParam("unlock")) {
Settings->is_locked = false;
Expand Down

0 comments on commit 490bab4

Please sign in to comment.