mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
fix up event log page and add hostname to output of webserver
This commit is contained in:
parent
ce0e52142a
commit
0993b52553
3 changed files with 30 additions and 21 deletions
|
@ -7,6 +7,7 @@ static unsigned long previous_millis = 0;
|
|||
static uint32_t time_seconds = 0;
|
||||
static uint8_t total_led_color = GREEN;
|
||||
static char event_message[256];
|
||||
EVENTS_STRUCT_TYPE entries[EVENT_NOF_EVENTS];
|
||||
|
||||
/* Local function prototypes */
|
||||
static void set_event_message(EVENTS_ENUM_TYPE event);
|
||||
|
@ -34,10 +35,10 @@ void set_event(EVENTS_ENUM_TYPE event, uint8_t data) {
|
|||
}
|
||||
entries[event].timestamp = time_seconds;
|
||||
entries[event].data = data;
|
||||
entries[event].occurences++;
|
||||
++entries[event].occurences;
|
||||
set_event_message(event);
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println(event_message);
|
||||
Serial.println("Set event: " + String(get_event_enum_string(event)) + ". Has occured " + String(entries[event].occurences) + " times");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,11 @@ const char* get_event_message(EVENTS_ENUM_TYPE event) {
|
|||
}
|
||||
|
||||
const char* get_event_enum_string(EVENTS_ENUM_TYPE event) {
|
||||
return EVENTS_ENUM_TYPE_STRING[event];
|
||||
const char* fullString = EVENTS_ENUM_TYPE_STRING[event];
|
||||
if (strncmp(fullString, "EVENT_", 6) == 0) {
|
||||
return fullString + 6; // Skip the first 6 characters
|
||||
}
|
||||
return fullString;
|
||||
}
|
||||
|
||||
static void set_event_message(EVENTS_ENUM_TYPE event) {
|
||||
|
|
|
@ -53,6 +53,6 @@ typedef struct {
|
|||
uint8_t occurences; // Number of occurrences since startup
|
||||
uint8_t led_color; // Weirdly indented comment
|
||||
} EVENTS_STRUCT_TYPE;
|
||||
static EVENTS_STRUCT_TYPE entries[EVENT_NOF_EVENTS];
|
||||
extern EVENTS_STRUCT_TYPE entries[EVENT_NOF_EVENTS];
|
||||
|
||||
#endif // __MYTIMER_H__
|
||||
|
|
|
@ -318,9 +318,10 @@ void wifi_monitor() {
|
|||
wifi_reconnect_interval = DEFAULT_WIFI_RECONNECT_INTERVAL;
|
||||
// Print local IP address and start web server
|
||||
Serial.print("Connected to WiFi network: " + String(ssid));
|
||||
Serial.print("IP address: " + WiFi.localIP().toString());
|
||||
Serial.print("Signal Strength: " + String(WiFi.RSSI()) + " dBm ");
|
||||
Serial.println("Channel: " + String(WiFi.channel()));
|
||||
Serial.print(" IP address: " + WiFi.localIP().toString());
|
||||
Serial.print(" Signal Strength: " + String(WiFi.RSSI()) + " dBm");
|
||||
Serial.println(" Channel: " + String(WiFi.channel()));
|
||||
Serial.println(" Hostname: " + String(WiFi.getHostname()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -945,17 +946,19 @@ String cellmonitor_processor(const String& var) {
|
|||
const char EVENTS_HTML_START[] PROGMEM = R"=====(
|
||||
<style>
|
||||
body { background-color: black; color: white; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { border: 1px solid white; padding: 10px; text-align: left; }
|
||||
.event-log { display: flex; flex-direction: column; }
|
||||
.event { display: flex; flex-wrap: wrap; border: 1px solid white; padding: 10px; }
|
||||
.event > div { flex: 1; min-width: 100px; max-width: 90%; word-break: break-word; }
|
||||
</style>
|
||||
<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>
|
||||
<h4 style='color: white;'>Event log:</h4>
|
||||
<table>
|
||||
<tr><th>Event Type</th><th>LED Color</th><th>Last Event (seconds ago)</th><th>Count</th><th>Data</th><th>Message</th></tr>
|
||||
<div class="event-log">
|
||||
<div class="event">
|
||||
<div>Event Type</div><div>LED Color</div><div>Last Event (seconds ago)</div><div>Count</div><div>Data</div><div>Message</div>
|
||||
</div>
|
||||
)=====";
|
||||
const char EVENTS_HTML_END[] PROGMEM = R"=====(
|
||||
</table>
|
||||
</div>
|
||||
</div></div>
|
||||
<button onclick='goToMainPage()'>Back to main page</button>
|
||||
<script>
|
||||
function goToMainPage() {
|
||||
|
@ -971,15 +974,16 @@ String events_processor(const String& var) {
|
|||
// Page format
|
||||
content.concat(FPSTR(EVENTS_HTML_START));
|
||||
for(int i = 0; i < EVENT_NOF_EVENTS; i++) {
|
||||
Serial.println("Event: " + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) + " count: " + String(entries[i].occurences) + " seconds: " + String(entries[i].timestamp) + " data: " + String(entries[i].data));
|
||||
if (entries[i].occurences > 0) {
|
||||
content.concat("<tr>");
|
||||
content.concat("<td>" + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) + "</td>");
|
||||
content.concat("<td>" + String(get_led_color_display_text(entries[i].led_color)) + "</td>");
|
||||
content.concat("<td>" + String((millis() / 1000) - entries[i].timestamp) + "</td>");
|
||||
content.concat("<td>" + String(entries[i].occurences) + "</td>");
|
||||
content.concat("<td>" + String(entries[i].data) + "</td>");
|
||||
content.concat("<td>" + String(get_event_message(static_cast<EVENTS_ENUM_TYPE>(i))) + "</td>");
|
||||
content.concat("</tr>");
|
||||
content.concat("<div class='event'>");
|
||||
content.concat("<div>" + String(get_event_enum_string(static_cast<EVENTS_ENUM_TYPE>(i))) + "</div>");
|
||||
content.concat("<div>" + String(get_led_color_display_text(entries[i].led_color)) + "</div>");
|
||||
content.concat("<div>" + String((millis() / 1000) - entries[i].timestamp) + "</div>");
|
||||
content.concat("<div>" + String(entries[i].occurences) + "</div>");
|
||||
content.concat("<div>" + String(entries[i].data) + "</div>");
|
||||
content.concat("<div>" + String(get_event_message(static_cast<EVENTS_ENUM_TYPE>(i))) + "</div>");
|
||||
content.concat("</div>"); // End of event row
|
||||
}
|
||||
}
|
||||
content.concat(FPSTR(EVENTS_HTML_END));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue