1 Commits

8 changed files with 10 additions and 216 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
// Contains configuration constants:
#define FIRMWARE_VERSION "1.0.6"
#define FIRMWARE_VERSION "1.0.3"
-41
View File
@@ -1,41 +0,0 @@
#include "diagnostics_state.h"
void DiagnosticsState::update()
{
current.timestamp = millis();
current.freeHeap =
ESP.getFreeHeap();
current.minimumFreeHeap =
ESP.getMinFreeHeap();
current.cpuFrequency =
ESP.getCpuFreqMHz();
history[historyIndex] = current;
historyIndex++;
if(historyIndex >= DIAGNOSTIC_HISTORY_SIZE)
{
historyIndex = 0;
}
}
DiagnosticSample DiagnosticsState::getCurrent()
{
return current;
}
DiagnosticSample DiagnosticsState::getHistory(uint8_t index)
{
if(index >= DIAGNOSTIC_HISTORY_SIZE)
{
return current;
}
return history[index];
}
-34
View File
@@ -1,34 +0,0 @@
#pragma once
#include <Arduino.h>
#define DIAGNOSTIC_HISTORY_SIZE 60
struct DiagnosticSample
{
uint32_t timestamp;
uint32_t freeHeap;
uint32_t minimumFreeHeap;
uint32_t cpuFrequency;
};
class DiagnosticsState
{
public:
void update();
DiagnosticSample getCurrent();
DiagnosticSample getHistory(uint8_t index);
private:
DiagnosticSample current;
DiagnosticSample history[DIAGNOSTIC_HISTORY_SIZE];
uint8_t historyIndex = 0;
};
+4 -8
View File
@@ -4,7 +4,6 @@
#include <Arduino.h>
#include "core/dashboard_state.h"
#include "core/diagnostics_state.h"
#include "services/service_manager.h"
#include "services/wifi_service.h"
@@ -12,24 +11,22 @@
#include "services/web_service.h"
#include "tasks/system_task.h"
#include "tasks/diagnostics_task.h"
DashboardState dashboardState;
DiagnosticsState diagnosticsState;
// Simple service scheduler nice for grouping tasks
ServiceManager services;
WiFiService wifi;
OTAService ota;
WebService web(dashboardState, diagnosticsState);
WebService web(dashboardState);
// Actual FreeRTOS tasks that are scheduled
SystemTask systemTask(services);
DiagnosticsTask diagnosticsTask(diagnosticsState);
void setup()
{
@@ -41,7 +38,6 @@ void setup()
systemTask.start();
diagnosticsTask.start();
}
+4 -46
View File
@@ -1,10 +1,9 @@
#include "web_service.h"
WebService::WebService(DashboardState& state, DiagnosticsState& diag_state)
WebService::WebService(DashboardState& state)
:
Service("Web", 10),
dashboardState(state),
diagnosticsState(diag_state),
server(80),
webSocket(81)
{
@@ -82,11 +81,8 @@ function connectWebSocket() {
socket.onmessage = function(event) {
const data = JSON.parse(event.data);
document.getElementById("uptime").innerHTML = data.system.uptime;
document.getElementById("firmware_version").innerHTML = data.system.version;
document.getElementById("free_heap").innerHTML = data.diagnostics.free_heap;
document.getElementById("minimum_free_heap").innerHTML = data.diagnostics.minimum_free_heap;
document.getElementById("cpu_frequency").innerHTML = data.diagnostics.cpu_frequency;
document.getElementById("uptime").innerHTML = data.uptime;
document.getElementById("firmware_version").innerHTML = data.version;
};
socket.onclose = function() {
@@ -107,32 +103,17 @@ window.onload = connectWebSocket;
<p>Device uptime:</p>
<div id="uptime">Loading...</div>
</div>
<div class="card">
<h1>Hub Diagnostics:</h1>
<p>Free heap:</p>
<div id=free_heap>Loading...</div>
<p>Minimum free heap:</p>
<div id=minimum_free_heap>Loading...</div>
<p>CPU Frequency:</p>
<div id=cpu_frequency>Loading...</div>
</div>
</body>
<footer>
Firmware Version: <div id="firmware_version">Loading...</div>
</footer>
</body>
</html>
)rawliteral";
void WebService::broadcastState()
{
DiagnosticSample diagnostics = diagnosticsState.getCurrent();
String json = "{";
// Opening system tag:
json += "\"system\":{";
json += "\"uptime\":\"";
json += dashboardState.uptime;
json += "\",";
@@ -141,31 +122,8 @@ void WebService::broadcastState()
json += dashboardState.firmwareVersion;
json += "\"";
json += "},"; // Close system tag
// Opening diagnostic tag:
json += "\"diagnostics\":{";
json += "\"free_heap\":\"";
json += diagnostics.freeHeap;
json += "\",";
json += "\"minimum_free_heap\":\"";
json += diagnostics.minimumFreeHeap;
json += "\",";
json += "\"cpu_frequency\":\"";
json += diagnostics.cpuFrequency;
json += "\"";
json += "}"; // Clost diagnostic tag
// Final close bracket
json += "}";
Serial.println(json);
webSocket.broadcastTXT(json);
}
+1 -4
View File
@@ -6,13 +6,12 @@
#include "service.h"
#include "../core/dashboard_state.h"
#include "../core/diagnostics_state.h"
class WebService : public Service {
public:
WebService(DashboardState& state, DiagnosticsState& diag_state);
WebService(DashboardState& state);
void begin() override;
void update() override;
@@ -21,9 +20,7 @@ private:
WebServer server;
WebSocketsServer webSocket;
DashboardState dashboardState;
DiagnosticsState diagnosticsState;
void handleWebSocketMessage(uint8_t clientNum, uint8_t *payload, size_t length);
void broadcastState();
-54
View File
@@ -1,54 +0,0 @@
#include "diagnostics_task.h"
DiagnosticsTask::DiagnosticsTask(
DiagnosticsState& state
)
:
diagnostics(state)
{
}
void DiagnosticsTask::start()
{
xTaskCreatePinnedToCore(
taskEntry,
"DiagnosticsTask",
4096,
this,
1,
&taskHandle,
1
);
}
void DiagnosticsTask::taskEntry(void* parameter)
{
DiagnosticsTask* task =
static_cast<DiagnosticsTask*>(parameter);
task->run();
}
void DiagnosticsTask::run()
{
TickType_t lastWake =
xTaskGetTickCount();
while(true)
{
diagnostics.update();
vTaskDelayUntil(
&lastWake,
pdMS_TO_TICKS(1000)
);
}
}
-28
View File
@@ -1,28 +0,0 @@
#pragma once
#include <Arduino.h>
#include "../core/diagnostics_state.h"
class DiagnosticsTask
{
public:
DiagnosticsTask(
DiagnosticsState& state
);
void start();
private:
static void taskEntry(void* parameter);
void run();
DiagnosticsState& diagnostics;
TaskHandle_t taskHandle = nullptr;
};