This commit is contained in:
File diff suppressed because one or more lines are too long
41
data/update_progress.html
Normal file
41
data/update_progress.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="/chota.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="card bd-success">
|
||||
<header class="is-center">
|
||||
<h4>Update running</h4>
|
||||
</header>
|
||||
<div class="is-center" id="progress">
|
||||
Running update...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
const ws = new WebSocket('ws://' + window.location.host + '/ws');
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log('WebSocket connection opened.');
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
console.log('Progress:', event.data);
|
||||
// Update the progress bar
|
||||
let progress = parseInt(event.data);
|
||||
document.getElementById('progress').textContent = progress + '%';
|
||||
};
|
||||
|
||||
ws.onerror = function(error) {
|
||||
console.error('WebSocket error:', error);
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
console.log('WebSocket connection closed.');
|
||||
};
|
||||
</script>
|
||||
@@ -1 +1 @@
|
||||
2
|
||||
3
|
||||
@@ -7,7 +7,7 @@
|
||||
#define water_level_min_key "water_level_min"
|
||||
#define water_level_max_key "water_level_max"
|
||||
#define water_volume_key "water_volume"
|
||||
#define current_software_version Version{0, 0, 15}
|
||||
#define REQUIRED_SPIFFS_VERSION Version{2, 0, 0}
|
||||
#define current_software_version Version{0, 0, 16}
|
||||
#define REQUIRED_SPIFFS_VERSION Version{3, 0, 0}
|
||||
|
||||
#define RESISTOR_VALUE 4
|
||||
@@ -39,6 +39,7 @@ extern "C" int rom_phy_get_vdd33();
|
||||
Version current_spiffs_version;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
AsyncWebSocket ws("/ws");
|
||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||
|
||||
void setup()
|
||||
@@ -96,6 +97,8 @@ void setup()
|
||||
|
||||
server.on("/logic.js", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/logic.js", "application/javascript", false, processor); });
|
||||
|
||||
server.on("/update", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/update_progress.html", "text/html", false, processor); });
|
||||
|
||||
// API stuff - internal
|
||||
server.on("/update_wifi_credentials", HTTP_POST, [](AsyncWebServerRequest* request) {
|
||||
int params = request->params();
|
||||
@@ -167,13 +170,16 @@ void setup()
|
||||
|
||||
setup_api_endpoints();
|
||||
|
||||
|
||||
ws.onEvent(onWsEvent);
|
||||
server.addHandler(&ws);
|
||||
|
||||
|
||||
|
||||
server.on("/chota.css", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/chota.css", "text/css", false); });
|
||||
server.on("/gauge.js", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/gauge.js", "application/javascript", false); });
|
||||
|
||||
|
||||
|
||||
display_error_code(23);
|
||||
|
||||
display_error_code(24);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <ArduinoLog.h>
|
||||
#include "json_builder.h"
|
||||
#include "../tools/tools.h"
|
||||
#include <SPIFFS.h>
|
||||
|
||||
extern WaterData water_data;
|
||||
extern DeviceTelemetry telemetry;
|
||||
@@ -59,6 +60,6 @@ void setup_api_endpoints(){
|
||||
};
|
||||
|
||||
xTaskCreate(run_ota_update_task, "RunOTAUpdate", 1024 * 8, (void *)&args, 1, NULL);
|
||||
request->send(200, "text/plain", "OTA Update started");
|
||||
request->send(SPIFFS, "/update_progress.html", "text/html", false, processor);
|
||||
});
|
||||
}
|
||||
@@ -4,9 +4,11 @@
|
||||
#include "../global_data/defines.h"
|
||||
#include <Preferences.h>
|
||||
#include <fetchOTA.h>
|
||||
#include <AsyncWebSocket.h>
|
||||
|
||||
extern Preferences prefs;
|
||||
extern OTAStatus ota_status;
|
||||
extern AsyncWebSocket ws;
|
||||
|
||||
extern Version current_spiffs_version;
|
||||
|
||||
@@ -59,7 +61,7 @@ void update_progress(int cur, int total) {
|
||||
if (cur != 0 ) {
|
||||
ota_status.update_progress = total/cur;
|
||||
}
|
||||
|
||||
ws.textAll(String(ota_status.update_progress).c_str());
|
||||
Log.verbose("OTA Update progress: %d/%d", cur, total);
|
||||
}
|
||||
|
||||
@@ -131,4 +133,15 @@ void run_ota_update_task(void* parameter) {
|
||||
Log.verbose("Running OTA upgrade now with URL: %s", args->ota_status.update_url.c_str());
|
||||
run_ota_update(args->ota_status.update_url, update_started, update_finished, update_progress, update_error);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type,
|
||||
void *arg, uint8_t *data, size_t len) {
|
||||
if (type == WS_EVT_CONNECT) {
|
||||
Serial.println("WebSocket client connected");
|
||||
} else if (type == WS_EVT_DISCONNECT) {
|
||||
Serial.println("WebSocket client disconnected");
|
||||
} else if (type == WS_EVT_DATA) {
|
||||
// Optionally process data received from the client
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <Arduino.h>
|
||||
#include "../global_data/global_data.h"
|
||||
#include <fetchOTA.h>
|
||||
#include <AsyncWebSocket.h>
|
||||
|
||||
|
||||
void printSuffix(Print* _logOutput, int logLevel);
|
||||
void print_prefix(Print* _logOutput, int logLevel);
|
||||
@@ -8,7 +10,7 @@ bool is_error(ActiveErrors active_errors);
|
||||
String processor(const String& var);
|
||||
void check_update_task(void* parameter);
|
||||
void run_ota_update_task(void* parameter);
|
||||
|
||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type,void *arg, uint8_t *data, size_t len);
|
||||
|
||||
typedef struct {
|
||||
OTAStatus ota_status;
|
||||
|
||||
Reference in New Issue
Block a user