Some changes after testing

This commit is contained in:
Gunnar Skjold 2023-01-12 20:17:37 +01:00
parent 870617f780
commit 365061df29
4 changed files with 62 additions and 6 deletions

View File

@ -108,7 +108,7 @@
Gateway: {sysinfo.net.gw}
</div>
<div class="my-2">
DNS: {sysinfo.net.dns1} {#if sysinfo.net.dns2 != '0.0.0.0'}/ {sysinfo.net.dns2}{/if}
DNS: {sysinfo.net.dns1} {#if sysinfo.net.dns2 && sysinfo.net.dns2 != '0.0.0.0'}/ {sysinfo.net.dns2}{/if}
</div>
</div>
{/if}

View File

@ -61,6 +61,11 @@ private:
bool performUpgrade = false;
bool rebootForUpgrade = false;
String priceRegion = "";
#if defined(AMS2MQTT_FIRMWARE_URL)
String customFirmwareUrl = AMS2MQTT_FIRMWARE_URL;
#else
String customFirmwareUrl;
#endif
static const uint16_t BufferSize = 2048;
char* buf;

View File

@ -1,6 +1,9 @@
<html>
<form action="/firmware" enctype="multipart/form-data" method="post" autocomplete="off">
<input name="file" type="file" accept=".bin">
<button type="submit" class="">Upload</button>
File: <input name="file" type="file" accept=".bin"><br/>
or<br/>
URL: <input name="url" type="text"/><br/>
<br/>
<button type="submit" class="">Install</button>
</form>
</html>

View File

@ -1429,7 +1429,6 @@ void AmsWebServer::upgrade() {
server.handleClient();
delay(250);
String customFirmwareUrl = "";
if(server.hasArg(F("url"))) {
customFirmwareUrl = server.arg(F("url"));
}
@ -1493,8 +1492,55 @@ void AmsWebServer::firmwarePost() {
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(PSTR("Handling firmware post..."));
if(!checkSecurity(1))
return;
if(rebootForUpgrade) {
server.send(200);
} else {
if(server.hasArg(F("url"))) {
String url = server.arg(F("url"));
if(!url.isEmpty() && (url.startsWith(F("http://")) || url.startsWith(F("https://")))) {
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(PSTR("Custom firmware URL was provided"));
server.send(200);
WiFiClient client;
#if defined(ESP8266)
String chipType = F("esp8266");
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
String chipType = F("esp32s2");
#elif defined(ESP32)
#if defined(CONFIG_FREERTOS_UNICORE)
String chipType = F("esp32solo");
#else
String chipType = F("esp32");
#endif
#endif
#if defined(ESP8266)
ESPhttpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, url, VERSION);
#elif defined(ESP32)
HTTPUpdate httpUpdate;
httpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
HTTPUpdateResult ret = httpUpdate.update(client, url, String(VERSION) + "-" + chipType);
#endif
switch(ret) {
case HTTP_UPDATE_FAILED:
debugger->printf(PSTR("Update failed"));
break;
case HTTP_UPDATE_NO_UPDATES:
debugger->printf(PSTR("No Update"));
break;
case HTTP_UPDATE_OK:
debugger->printf(PSTR("Update OK"));
break;
}
server.send(200, MIME_PLAIN, "OK");
return;
}
}
server.sendHeader(HEADER_LOCATION,F("/firmware"));
server.send(303);
}
}
@ -1503,7 +1549,9 @@ void AmsWebServer::firmwareUpload() {
return;
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START) {
if(upload.totalSize == 0) {
return;
} else if(upload.status == UPLOAD_FILE_START) {
String filename = upload.filename;
if(!filename.endsWith(".bin")) {
server.send(500, MIME_PLAIN, "500: couldn't create file");