Aquarium Cooling Controller
ESP32 firmware for aquarium cooling fan control, monitoring, telemetry, and fault handling.
Loading...
Searching...
No Matches
ota_upload_server.h
Go to the documentation of this file.
1#pragma once
2
8#include <Arduino.h>
9#include <WebServer.h>
10
14enum class OtaUploadState {
15 kDisabled,
16 kArmed,
19 kFailed,
20 kTimedOut,
21};
22
27 public:
32
43 void begin(const char* firmwareName,
44 const char* firmwareVersion,
45 const char* firmwareIdentityTag,
46 const char* firmwareVersionTag);
47
53 void update(uint32_t nowMs);
54
62 bool enable(uint32_t nowMs, Stream& out);
63
69 void cancel(Stream& out);
70
76 void printStatus(Stream& out) const;
77
83 bool active() const;
84
90 OtaUploadState state() const;
91
97 const char* statusLabel() const;
98
104 const char* lastMessage() const;
105
106 private:
107 static constexpr uint32_t kUploadWindowMs = 5UL * 60UL * 1000UL;
108 static constexpr uint16_t kHttpPort = 80;
109 static constexpr size_t kMessageBufferSize = 96;
110 static constexpr size_t kIdentityBufferSize = 32;
111
112 void configureRoutes();
113 void stopServer(OtaUploadState finalState, const char* message);
114 void failUpload(const char* message);
115 bool validateUploadedImage();
116 void handleRoot();
117 void handleUpdateForm();
118 void handleUpdateFinished();
119 void handleUploadChunk();
120 const char* stateLabel() const;
121
122 WebServer server_;
123 const char* firmwareName_;
124 const char* firmwareVersion_;
125 const char* firmwareIdentityTag_;
126 const char* firmwareVersionTag_;
127 OtaUploadState state_;
128 bool initialized_;
129 bool serverRunning_;
130 bool uploadStarted_;
131 bool uploadFinished_;
132 bool rebootPending_;
133 bool updateWriteError_;
134 uint32_t enabledAtMs_;
135 size_t maxImageSize_;
136 size_t expectedSize_;
137 size_t writtenSize_;
138 char currentVersion_[kIdentityBufferSize];
139 char lastMessage_[kMessageBufferSize];
140};
Hosts a short-lived HTTP form for uploading firmware binaries.
Definition ota_upload_server.h:26
const char * lastMessage() const
Returns the latest OTA status message.
Definition ota_upload_server.cpp:386
void printStatus(Stream &out) const
Prints OTA upload status to a stream.
Definition ota_upload_server.cpp:345
OtaUploadServer()
Creates a disabled OTA upload server.
Definition ota_upload_server.cpp:227
void update(uint32_t nowMs)
Handles HTTP clients and closes timed-out upload windows.
Definition ota_upload_server.cpp:266
bool active() const
Indicates whether the upload server is accepting or handling uploads.
Definition ota_upload_server.cpp:374
bool enable(uint32_t nowMs, Stream &out)
Opens the temporary OTA upload window.
Definition ota_upload_server.cpp:285
const char * statusLabel() const
Returns a stable text label for the current OTA upload state.
Definition ota_upload_server.cpp:382
void begin(const char *firmwareName, const char *firmwareVersion, const char *firmwareIdentityTag, const char *firmwareVersionTag)
Configures HTTP routes and firmware identity strings.
Definition ota_upload_server.cpp:247
void cancel(Stream &out)
Cancels any active OTA upload window.
Definition ota_upload_server.cpp:328
OtaUploadState state() const
Returns the current OTA upload state.
Definition ota_upload_server.cpp:378
OtaUploadState
Runtime state of the temporary OTA upload server.
Definition ota_upload_server.h:14
@ kSucceeded
Firmware upload finished successfully.
@ kDisabled
OTA upload is disabled and the HTTP server is stopped.
@ kTimedOut
Upload window elapsed before completion.
@ kFailed
Firmware upload failed.
@ kUploading
Firmware upload is in progress.
@ kArmed
Upload window is open and waiting for a browser upload.