Working on migrating to using websockets for the UI

This commit is contained in:
2026-08-08 22:07:25 -06:00
parent 3946e464c9
commit 8c53ba5298
10 changed files with 79 additions and 14 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ platform = espressif32
board = esp32dev board = esp32dev
framework = arduino framework = arduino
;lib_deps = ;lib_deps =
;; esp32async/ESPAsyncWebServer@^3.12.0
; upload via OTA ; upload via OTA
upload_protocol = espota upload_protocol = espota
+3
View File
@@ -0,0 +1,3 @@
// Contains configuration constants:
#define FIRMWARE_VERSION "1.0.2"
+36
View File
@@ -0,0 +1,36 @@
#include "dashboard_state.h"
void DashboardState::begin() {}
void DashboardState::update()
{
unsigned long seconds = millis() / 1000;
unsigned long days = seconds / 86400;
seconds %= 86400;
unsigned long hours = seconds / 3600;
seconds %= 3600;
unsigned long minutes = seconds / 60;
seconds %= 60;
char buffer[64];
snprintf(
buffer,
sizeof(buffer),
"%lu days %02lu:%02lu:%02lu",
days,
hours,
minutes,
seconds
);
uptime = String(buffer);
firmwareVersion = FIRMWARE_VERSION;
}
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include <Arduino.h>
#include "configuration.h"
class DashboardState
{
public:
void begin();
void update();
String uptime;
String firmwareVersion;
};
+6 -3
View File
@@ -3,8 +3,9 @@
#include <Arduino.h> #include <Arduino.h>
#include "services/service_manager.h" #include "core/dashboard_state.h"
#include "services/service_manager.h"
#include "services/wifi_service.h" #include "services/wifi_service.h"
#include "services/ota_service.h" #include "services/ota_service.h"
#include "services/web_service.h" #include "services/web_service.h"
@@ -12,12 +13,15 @@
#include "tasks/system_task.h" #include "tasks/system_task.h"
DashboardState dashboardState;
ServiceManager services; ServiceManager services;
WiFiService wifi; WiFiService wifi;
OTAService ota; OTAService ota;
WebService web; WebService web(dashboardState);
SystemTask systemTask(services); SystemTask systemTask(services);
@@ -28,7 +32,6 @@ void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
services.add(&wifi); services.add(&wifi);
services.add(&ota); services.add(&ota);
services.add(&web); services.add(&web);
+1 -1
View File
@@ -18,7 +18,7 @@ void ServiceManager::begin()
} }
void ServiceManager::update() void ServiceManager::tick()
{ {
for(uint8_t i = 0; i < count; i++) for(uint8_t i = 0; i < count; i++)
{ {
+1 -1
View File
@@ -11,7 +11,7 @@ public:
void begin(); void begin();
void update(); void tick();
private: private:
+5 -5
View File
@@ -1,10 +1,9 @@
#include "web_service.h" #include "web_service.h"
#define FIRMWARE_VERSION "1.0.1" WebService::WebService(DashboardState& state)
WebService::WebService()
: :
Service("Web", 10), Service("Web", 10),
dashboardState(state),
server(80) server(80)
{ {
} }
@@ -134,7 +133,7 @@ void WebService::begin() {
server.send( server.send(
200, 200,
"text/plain", "text/plain",
FIRMWARE_VERSION dashboardState.firmwareVersion
); );
}); });
@@ -143,7 +142,7 @@ void WebService::begin() {
server.send( server.send(
200, 200,
"text/plain", "text/plain",
formatUptime() dashboardState.uptime
); );
}); });
@@ -157,5 +156,6 @@ void WebService::begin() {
void WebService::update() void WebService::update()
{ {
dashboardState.update();
server.handleClient(); server.handleClient();
} }
+3 -1
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "service.h" #include "service.h"
#include "../core/dashboard_state.h"
#include <WebServer.h> #include <WebServer.h>
@@ -8,7 +9,7 @@ class WebService : public Service {
public: public:
WebService(); WebService(DashboardState& state);
void begin() override; void begin() override;
void update() override; void update() override;
@@ -16,4 +17,5 @@ public:
private: private:
WebServer server; WebServer server;
DashboardState dashboardState;
}; };
+4 -2
View File
@@ -47,14 +47,16 @@ void SystemTask::run()
{ {
serviceManager.begin(); serviceManager.begin();
TickType_t lastWakeTime = TickType_t lastWakeTime =
xTaskGetTickCount(); xTaskGetTickCount();
while(true) while(true)
{ {
serviceManager.update(); // Time the length of the task:
uint32_t start = micros();
serviceManager.tick();
uint32_t elapsed = micros() - start;
vTaskDelayUntil( vTaskDelayUntil(