Working on migrating to using websockets for the UI
This commit is contained in:
+1
-1
@@ -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
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// Contains configuration constants:
|
||||||
|
|
||||||
|
#define FIRMWARE_VERSION "1.0.2"
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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
@@ -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);
|
||||||
|
|||||||
@@ -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++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public:
|
|||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
void update();
|
void tick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user