mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 18:29:48 +02:00
Add battery statistics to webserver
This commit is contained in:
parent
430da0e0bd
commit
c121f774d5
2 changed files with 87 additions and 4 deletions
|
@ -9,9 +9,9 @@ unsigned long ota_progress_millis = 0;
|
||||||
const char index_html[] PROGMEM = R"rawliteral(
|
const char index_html[] PROGMEM = R"rawliteral(
|
||||||
<!DOCTYPE HTML><html>
|
<!DOCTYPE HTML><html>
|
||||||
<head>
|
<head>
|
||||||
<title>Battery Emulator Web Server</title>
|
<title>Battery Emulator</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" href="data:,">
|
<link rel="icon" type="image/png" href="favicon.png">
|
||||||
<style>
|
<style>
|
||||||
html {font-family: Arial; display: inline-block; text-align: center;}
|
html {font-family: Arial; display: inline-block; text-align: center;}
|
||||||
h2 {font-size: 3.0rem;}
|
h2 {font-size: 3.0rem;}
|
||||||
|
@ -26,7 +26,7 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>Battery Emulator Web Server</h2>
|
<h2>Battery Emulator</h2>
|
||||||
%PLACEHOLDER%
|
%PLACEHOLDER%
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -120,6 +120,11 @@ void init_ElegantOTA() {
|
||||||
String processor(const String& var) {
|
String processor(const String& var) {
|
||||||
if (var == "PLACEHOLDER") {
|
if (var == "PLACEHOLDER") {
|
||||||
String content = "";
|
String content = "";
|
||||||
|
//Page format
|
||||||
|
content += "<style>";
|
||||||
|
content += "body { background-color: black; color: white; }";
|
||||||
|
content += "</style>";
|
||||||
|
|
||||||
// Display LED color
|
// Display LED color
|
||||||
content += "<h4>LED color: ";
|
content += "<h4>LED color: ";
|
||||||
switch (LEDcolor) {
|
switch (LEDcolor) {
|
||||||
|
@ -147,6 +152,67 @@ String processor(const String& var) {
|
||||||
if (wifi_connected == true) {
|
if (wifi_connected == true) {
|
||||||
content += "<h4>IP: " + WiFi.localIP().toString() + "</h4>";
|
content += "<h4>IP: " + WiFi.localIP().toString() + "</h4>";
|
||||||
}
|
}
|
||||||
|
// Assuming SOC is an integer
|
||||||
|
float socFloat = static_cast<float>(SOC) / 100.0; // Convert to float and divide by 100
|
||||||
|
float sohFloat = static_cast<float>(StateOfHealth) / 100.0; // Convert to float and divide by 100
|
||||||
|
float voltageFloat = static_cast<float>(battery_voltage) / 10.0; // Convert to float and divide by 10
|
||||||
|
float tempMaxFloat = static_cast<float>(temperature_max) / 10.0; // Convert to float and divide by 10
|
||||||
|
float tempMinFloat = static_cast<float>(temperature_min) / 10.0; // Convert to float and divide by 10
|
||||||
|
char socString[10];
|
||||||
|
char sohString[10];
|
||||||
|
char voltageString[10];
|
||||||
|
char tempMaxString[10];
|
||||||
|
char tempMinString[10];
|
||||||
|
|
||||||
|
// Format decimals
|
||||||
|
dtostrf(socFloat, 6, 2, socString);
|
||||||
|
dtostrf(sohFloat, 6, 2, sohString);
|
||||||
|
dtostrf(voltageFloat, 6, 1, voltageString);
|
||||||
|
dtostrf(tempMaxFloat, 6, 1, tempMaxString);
|
||||||
|
dtostrf(tempMinFloat, 6, 1, tempMinString);
|
||||||
|
|
||||||
|
//Display battery statistics
|
||||||
|
content += "<h4>SOC: " + String(socString) +"</h4>";
|
||||||
|
content += "<h4>SOH: " + String(sohString) +"</h4>";
|
||||||
|
content += "<h4>Voltage: " + String(voltageString) + " V</h4>";
|
||||||
|
content += "<h4>Current: " + String(battery_current) + " A</h4>";
|
||||||
|
content += "<h4>Power: " + String(stat_batt_power) + " W</h4>";
|
||||||
|
content += "<h4>Total capacity: " + String(capacity_Wh) + " Wh</h4>";
|
||||||
|
content += "<h4>Remaining capacity: " + String(remaining_capacity_Wh) + " Wh</h4>";
|
||||||
|
content += "<h4>Max discharge power: " + String(max_target_discharge_power) + " W</h4>";
|
||||||
|
content += "<h4>Max charge power: " + String(max_target_charge_power) + " W</h4>";
|
||||||
|
content += "<h4>Cell max: " + String(cell_max_voltage) + " mV</h4>";
|
||||||
|
content += "<h4>Cell min: " + String(cell_min_voltage) + " mV</h4>";
|
||||||
|
content += "<h4>Temperature max: " + String(tempMaxString) + " C</h4>";
|
||||||
|
content += "<h4>Temperature min: " + String(tempMinString) + " C</h4>";
|
||||||
|
content += "<h4>BMS Status: " + String(bms_status) + " -</h4>";
|
||||||
|
if(bms_status == 3){
|
||||||
|
content += "<h4>BMS Status: OK </h4>";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
content += "<h4>BMS Status: FAULT </h4>";
|
||||||
|
}
|
||||||
|
if(bms_char_dis_status == 2){
|
||||||
|
content += "<h4>Battery charging!</h4>";
|
||||||
|
}
|
||||||
|
else if (bms_char_dis_status == 1){
|
||||||
|
content += "<h4>Battery discharging!</h4>";
|
||||||
|
}
|
||||||
|
else{ //0 idle
|
||||||
|
content += "<h4>Battery idle</h4>";
|
||||||
|
}
|
||||||
|
|
||||||
|
content += "<button onclick='goToUpdatePage()'>Perform OTA update</button>";
|
||||||
|
content += "<script>";
|
||||||
|
content += "function goToUpdatePage() { window.location.href = '/update'; }";
|
||||||
|
content += "</script>";
|
||||||
|
|
||||||
|
|
||||||
|
//Script for refreshing page
|
||||||
|
content += "<script>";
|
||||||
|
content += "setTimeout(function(){ location.reload(true); }, 5000);";
|
||||||
|
content += "</script>";
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
return String();
|
return String();
|
||||||
|
|
|
@ -9,7 +9,24 @@
|
||||||
#include "../../lib/me-no-dev-ESPAsyncWebServer/src/ESPAsyncWebServer.h"
|
#include "../../lib/me-no-dev-ESPAsyncWebServer/src/ESPAsyncWebServer.h"
|
||||||
#include "../config.h" // Needed for LED defines
|
#include "../config.h" // Needed for LED defines
|
||||||
|
|
||||||
extern uint8_t LEDcolor; // Enum, 0-10
|
extern uint16_t SOC; //SOC%, 0-100.00 (0-10000)
|
||||||
|
extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000)
|
||||||
|
extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
|
||||||
|
extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485)
|
||||||
|
extern uint16_t capacity_Wh; //Wh, 0-60000
|
||||||
|
extern uint16_t remaining_capacity_Wh; //Wh, 0-60000
|
||||||
|
extern uint16_t max_target_discharge_power; //W, 0-60000
|
||||||
|
extern uint16_t max_target_charge_power; //W, 0-60000
|
||||||
|
extern uint16_t bms_status; //Enum, 0-5
|
||||||
|
extern uint16_t bms_char_dis_status; //Enum, 0-2
|
||||||
|
extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530)
|
||||||
|
extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
|
||||||
|
extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
|
||||||
|
extern uint16_t cell_max_voltage; //mV, 0-4350
|
||||||
|
extern uint16_t cell_min_voltage; //mV, 0-4350
|
||||||
|
extern uint8_t LEDcolor; //Enum, 0-10
|
||||||
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
||||||
extern const char* ssid;
|
extern const char* ssid;
|
||||||
extern const char* password;
|
extern const char* password;
|
||||||
extern const char* ssidAP;
|
extern const char* ssidAP;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue