MCPcopy Create free account
hub / github.com/OpenEPaperLink/OpenEPaperLink / updateFirmware

Function updateFirmware

ESP32_AP-Flasher/src/ota.cpp:226–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226void updateFirmware(const char* url, const char* expectedMd5, const size_t size) {
227 util::printHeap();
228
229 config.runStatus = RUNSTATUS_STOP;
230 vTaskDelay(3000 / portTICK_PERIOD_MS);
231 saveDB("/current/tagDB.json");
232 // destroyDB();
233
234 HTTPClient httpClient;
235
236 wsSerial("start downloading");
237 wsSerial(url);
238
239 httpClient.begin(url);
240 httpClient.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
241 util::printHeap();
242 const int httpCode = httpClient.GET();
243 util::printHeap();
244
245 if (httpCode == HTTP_CODE_OK) {
246 if (Update.begin(size)) {
247 Update.setMD5(expectedMd5);
248
249 unsigned long progressTimer = millis();
250 Update.onProgress([&progressTimer](size_t progress, size_t total) {
251 if (millis() - progressTimer > 500 || progress == total) {
252 char buffer[50];
253 sprintf(buffer, "Progress: %u%% %d %d", progress * 100 / total, progress, total);
254 wsSerial(String(buffer));
255 progressTimer = millis();
256 vTaskDelay(1 / portTICK_PERIOD_MS);
257 }
258 });
259
260 const size_t written = Update.writeStream(httpClient.getStream());
261 if (written == httpClient.getSize()) {
262 if (Update.end(true)) {
263 wsSerial("Firmware update successful");
264 wsSerial("Reboot system now");
265 wsSerial("[reboot]");
266 vTaskDelay(1000 / portTICK_PERIOD_MS);
267 } else {
268 wsSerial("Error updating firmware:");
269 wsSerial(Update.errorString());
270 }
271 } else {
272 wsSerial("Error writing firmware data:");
273 wsSerial(Update.errorString());
274 }
275 } else {
276 wsSerial("Failed to begin firmware update");
277 wsSerial(Update.errorString());
278 }
279 } else {
280 wsSerial("Failed to download firmware file (HTTP code " + String(httpCode) + ")");
281 wsSerial(httpClient.errorToString(httpCode));
282 }
283

Callers 1

firmwareUpdateTaskFunction · 0.85

Calls 5

printHeapFunction · 0.85
saveDBFunction · 0.85
wsSerialFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected