* Fix issue with % in log output conflicting with templating character

* Fix issue with % in log output conflicting with templating character

- Split index_html string in header and footer part
- Use header and footer for index html template page
- Fix missing html and head tags in minified index html.
- Do not use templating engine for debug and can log pages, by using index html header and footer directly in generated content.

* Change pct to %.

* Revert "Fix crash caused by percentage char"

This reverts commit 04a68fc89e.
The original commit only fixed the symptoms, the cause has been fixed,
now we ran revert these.

* Revert "Remove percentage sign from logging"

This reverts commit af05f28755.
The original commit only fixed the symptoms, the cause has been fixed,
now we ran revert these.
This commit is contained in:
mvgalen 2025-01-02 13:22:52 +01:00 committed by GitHub
parent 850031ccf9
commit 3d1f535b09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 111 additions and 93 deletions

View file

@ -106,8 +106,8 @@ void update_values_battery() {
/*Finally print out values to serial if configured to do so*/
#ifdef DEBUG_LOG
logging.println("Values going to inverter");
print_units("SOH: ", (datalayer.battery.status.soh_pptt * 0.01), "pct ");
print_units(", SOC: ", (datalayer.battery.status.reported_soc * 0.01), "pct ");
print_units("SOH%: ", (datalayer.battery.status.soh_pptt * 0.01), "% ");
print_units(", SOC%: ", (datalayer.battery.status.reported_soc * 0.01), "% ");
print_units(", Voltage: ", (datalayer.battery.status.voltage_dV * 0.1), "V ");
print_units(", Max discharge power: ", datalayer.battery.status.max_discharge_power_W, "W ");
print_units(", Max charge power: ", datalayer.battery.status.max_charge_power_W, "W ");

View file

@ -695,11 +695,11 @@ void update_values_battery() { //This function maps all the values fetched via
logging.println("Values from battery: ");
logging.print("SOC BMS: ");
logging.print((uint16_t)SOC_BMS / 10.0, 1);
logging.print("pct | SOC Display: ");
logging.print("% | SOC Display: ");
logging.print((uint16_t)SOC_Display / 10.0, 1);
logging.print("pct | SOH ");
logging.print("% | SOH ");
logging.print((uint16_t)batterySOH / 10.0, 1);
logging.println("pct");
logging.println("%");
logging.print((int16_t)batteryAmps / 10.0, 1);
logging.print(" Amps | ");
logging.print((uint16_t)batteryVoltage / 10.0, 1);

View file

@ -147,11 +147,11 @@ void update_values_battery() { //This function maps all the values fetched via
logging.println("Values from battery: ");
logging.print("SOC BMS: ");
logging.print((uint16_t)SOC_BMS / 10.0, 1);
logging.print("pct | SOC Display: ");
logging.print("% | SOC Display: ");
logging.print((uint16_t)SOC_Display / 10.0, 1);
logging.print("pct | SOH ");
logging.print("% | SOH ");
logging.print((uint16_t)batterySOH / 10.0, 1);
logging.println("pct");
logging.println("%");
logging.print((int16_t)batteryAmps / 10.0, 1);
logging.print(" Amps | ");
logging.print((uint16_t)batteryVoltage / 10.0, 1);

View file

@ -105,9 +105,9 @@ void update_values_battery() { //This function maps all the values fetched via
#ifdef DEBUG_LOG
logging.println("Values going to inverter:");
logging.print("SOH: ");
logging.print("SOH%: ");
logging.print(datalayer.battery.status.soh_pptt);
logging.print(", SOC scaled: ");
logging.print(", SOC% scaled: ");
logging.print(datalayer.battery.status.reported_soc);
logging.print(", Voltage: ");
logging.print(datalayer.battery.status.voltage_dV);

View file

@ -2713,7 +2713,7 @@ void print_SOC(char* header, int SOC) {
if (hundredth < 10)
logging.print(0);
logging.print(hundredth);
logging.println("pct");
logging.println("%");
}
void printFaultCodesIfActive() {

View file

@ -56,8 +56,8 @@ void update_values_battery() { /* This function puts fake values onto the parame
/*Finally print out values to serial if configured to do so*/
#ifdef DEBUG_LOG
logging.println("FAKE Values going to inverter");
print_units("SOH: ", (datalayer.battery.status.soh_pptt * 0.01), "pct ");
print_units(", SOC: ", (datalayer.battery.status.reported_soc * 0.01), "pct ");
print_units("SOH%: ", (datalayer.battery.status.soh_pptt * 0.01), "% ");
print_units(", SOC%: ", (datalayer.battery.status.reported_soc * 0.01), "% ");
print_units(", Voltage: ", (datalayer.battery.status.voltage_dV * 0.1), "V ");
print_units(", Max discharge power: ", datalayer.battery.status.max_discharge_power_W, "W ");
print_units(", Max charge power: ", datalayer.battery.status.max_charge_power_W, "W ");
@ -109,8 +109,8 @@ void update_values_battery2() { // Handle the values coming in from battery #2
/*Finally print out values to serial if configured to do so*/
#ifdef DEBUG_LOG
logging.println("FAKE Values battery 2 going to inverter");
print_units("SOH 2: ", (datalayer.battery2.status.soh_pptt * 0.01), "pct ");
print_units(", SOC 2: ", (datalayer.battery2.status.reported_soc * 0.01), "pct ");
print_units("SOH 2 %: ", (datalayer.battery2.status.soh_pptt * 0.01), "% ");
print_units(", SOC 2 %: ", (datalayer.battery2.status.reported_soc * 0.01), "% ");
print_units(", Voltage 2: ", (datalayer.battery2.status.voltage_dV * 0.1), "V ");
print_units(", Max discharge power 2: ", datalayer.battery2.status.max_discharge_power_W, "W ");
print_units(", Max charge power 2: ", datalayer.battery2.status.max_charge_power_W, "W ");

View file

@ -95,11 +95,11 @@ void update_values_battery() { //This function maps all the values fetched via
}
#ifdef DEBUG_LOG
logging.print("BMS reported SOC: ");
logging.print("BMS reported SOC%: ");
logging.println(SOC_BMS);
logging.print("Calculated SOC: ");
logging.print("Calculated SOC%: ");
logging.println(SOC_CALC);
logging.print("Rescaled SOC: ");
logging.print("Rescaled SOC%: ");
logging.println(datalayer.battery.status.reported_soc / 100);
logging.print("Battery current: ");
logging.println(BATT_I);

View file

@ -101,6 +101,9 @@ void map_can_frame_to_variable_charger(CAN_frame rx_frame) {
case 0x308:
break;
default:
#ifdef DEBUG_LOG
logging.printf("CAN Rcv unknown frame MsgID=%x\n", rx_frame.MsgID);
#endif
break;
}
}

View file

@ -90,7 +90,7 @@ void init_CAN() {
logging.println(settings2517.exactArbitrationBitRate() ? "yes)" : "no)");
logging.print("Arbitration Sample point: ");
logging.print(settings2517.arbitrationSamplePointFromBitStart());
logging.println("pct");
logging.println("%");
#endif // DEBUG_LOG
} else {
#ifdef DEBUG_LOG

View file

@ -1,16 +1,16 @@
#include "can_logging_html.h"
#include <Arduino.h>
#include "../../datalayer/datalayer.h"
#include "index_html.h"
String can_logger_processor(const String& var) {
if (var == "X") {
String can_logger_processor(void) {
if (!datalayer.system.info.can_logging_active) {
datalayer.system.info.logged_can_messages_offset = 0;
datalayer.system.info.logged_can_messages[0] = '\0';
}
datalayer.system.info.can_logging_active =
true; // Signal to main loop that we should log messages. Disabled by default for performance reasons
String content = "";
String content = index_html_header;
// Page format
content += "<style>";
content += "body { background-color: black; color: white; font-family: Arial, sans-serif; }";
@ -27,7 +27,7 @@ String can_logger_processor(const String& var) {
#ifdef LOG_CAN_TO_SD
content += "<button onclick='deleteLogFile()'>Delete log file</button> ";
#endif
content += "<button onclick='stopLoggingAndGoToMainPage()'>Back to main page</button>";
content += "<button onclick='stopLoggingAndGoToMainPage()'>Stop &amp; Back to main page</button>";
// Start a new block for the CAN messages
content += "<div style='background-color: #303E47; padding: 20px; border-radius: 15px'>";
@ -62,7 +62,6 @@ String can_logger_processor(const String& var) {
content += " fetch('/stop_can_logging').then(() => window.location.href = '/');";
content += "}";
content += "</script>";
content += index_html_footer;
return content;
}
return String();
}

View file

@ -11,6 +11,6 @@
*
* @return String
*/
String can_logger_processor(const String& var);
String can_logger_processor(void);
#endif

View file

@ -1,10 +1,11 @@
#include "debug_logging_html.h"
#include <Arduino.h>
#include "../../datalayer/datalayer.h"
#include "index_html.h"
#ifdef DEBUG_VIA_WEB
String debug_logger_processor(const String& var) {
String content = "";
String debug_logger_processor(void) {
String content = String(index_html_header);
// Page format
content += "<style>";
content += "body { background-color: black; color: white; font-family: Arial, sans-serif; }";
@ -31,6 +32,7 @@ String debug_logger_processor(const String& var) {
content += "function exportLog() { window.location.href = '/export_log'; }";
content += "function goToMainPage() { window.location.href = '/'; }";
content += "</script>";
content += index_html_footer;
return content;
}
#endif // DEBUG_VIA_WEB

View file

@ -11,6 +11,6 @@
*
* @return String
*/
String debug_logger_processor(const String& var);
String debug_logger_processor(void);
#endif

View file

@ -1,6 +1,12 @@
const char index_html[] = R"rawliteral(
<!doctypehtml><title>Battery Emulator</title><meta content="width=device-width"name=viewport><style>html{font-family:Arial;display:inline-block;text-align:center}h2{font-size:3rem}body{max-width:800px;margin:0 auto}</style>%X%
)rawliteral";
#include "index_html.h"
#define INDEX_HTML_HEADER \
R"rawliteral(<!doctype html><html><head><title>Battery Emulator</title><meta content="width=device-width"name=viewport><style>html{font-family:Arial;display:inline-block;text-align:center}h2{font-size:3rem}body{max-width:800px;margin:0 auto}</style><body>)rawliteral"
#define INDEX_HTML_FOOTER R"rawliteral(</body></html>)rawliteral";
const char index_html[] = INDEX_HTML_HEADER "%X%" INDEX_HTML_FOOTER;
const char index_html_header[] = INDEX_HTML_HEADER;
const char index_html_footer[] = INDEX_HTML_FOOTER;
/* The above code is minified (https://kangax.github.io/html-minifier/) to increase performance. Here is the full HTML function:
<!DOCTYPE HTML><html>

View file

@ -0,0 +1,8 @@
#ifndef INDEX_HTML_H
#define INDEX_HTML_H
extern const char index_html[];
extern const char index_html_header[];
extern const char index_html_footer[];
#endif // INDEX_HTML_H

View file

@ -21,7 +21,7 @@ unsigned long ota_progress_millis = 0;
#include "cellmonitor_html.h"
#include "debug_logging_html.h"
#include "events_html.h"
#include "index_html.cpp"
#include "index_html.h"
#include "settings_html.h"
MyTimer ota_timeout_timer = MyTimer(15000);
@ -31,8 +31,6 @@ const char get_firmware_info_html[] = R"rawliteral(%X%)rawliteral";
void init_webserver() {
String content = index_html;
server.on("/logout", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(401); });
// Route for firmware info from ota update page
@ -63,13 +61,15 @@ void init_webserver() {
// Route for going to CAN logging web page
server.on("/canlog", HTTP_GET, [](AsyncWebServerRequest* request) {
request->send_P(200, "text/html", index_html, can_logger_processor);
AsyncWebServerResponse* response = request->beginResponse(200, "text/html", can_logger_processor());
request->send(response);
});
#ifdef DEBUG_VIA_WEB
// Route for going to debug logging web page
server.on("/log", HTTP_GET, [](AsyncWebServerRequest* request) {
request->send_P(200, "text/html", index_html, debug_logger_processor);
AsyncWebServerResponse* response = request->beginResponse(200, "text/html", debug_logger_processor());
request->send(response);
});
#endif // DEBUG_VIA_WEB