From e3d90d9579a6e57c777865052d32911e61807b2d Mon Sep 17 00:00:00 2001 From: fvanroie Date: Wed, 4 May 2022 22:59:43 +0200 Subject: [PATCH] Add Firmware Upgrade From URL #300 --- src/sys/svc/hasp_http.cpp | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index febf097c..f5b367a0 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1,7 +1,6 @@ /* MIT License - Copyright (c) 2019-2022 Francis Van Roie For full license information read the LICENSE file in the project folder */ -//#include "webServer.h" #include "hasplib.h" #include "ArduinoLog.h" @@ -2021,7 +2020,26 @@ static void webHandleFirmware() { if(!httpIsAuthenticated(F("firmware"))) return; - { // Send Content + if(webServer.method() == HTTP_POST && webServer.hasArg(PSTR("url"))) { + String url = webServer.arg(PSTR("url")); + { + String httpMessage((char*)0); + httpMessage.reserve(HTTP_PAGE_SIZE); + httpMessage += F("

"); + httpMessage += haspDevice.get_hostname(); + httpMessage += F("


"); + + httpMessage += F("

ESP update

Updating ESP firmware from: "); + httpMessage += url; + + webSendHeader(haspDevice.get_hostname(), httpMessage.length(), true); + webServer.sendContent(httpMessage); + } + + LOG_TRACE(TAG_HTTP, F("Updating ESP firmware from: %s"), url.c_str()); + dispatch_web_update(NULL, url.c_str(), TAG_HTTP); + } else { + // Send Firmware page String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage += F("

"); @@ -2047,19 +2065,18 @@ static void webHandleFirmware() httpMessage += F(""); httpMessage += F(""); - /* Update from URL - // Form - httpMessage += F("
"); + // Update from URL + // Form + httpMessage += F("
"); - // URL - httpMessage += - F("
"); - httpMessage += F("
"); + // URL + httpMessage += + F("
"); + httpMessage += F("
"); - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - */ + // Submit & End Form + httpMessage += F(""); + httpMessage += F("
"); httpMessage += FPSTR(MAIN_MENU_BUTTON); @@ -2270,7 +2287,7 @@ void httpSetup() LOG_VERBOSE(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str()); }, webHandleFirmwareUpload); - // webServer.on(F("/espfirmware"), httpHandleEspFirmware); + // webServer.on(F("/espfirmware"), httpHandleEspFirmware); #endif #if HASP_USE_WIFI > 0