Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webapp: disable OTA firmware dialog for unsupported devices #1152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/WebApi_firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class WebApiFirmwareClass {
void init(AsyncWebServer& server, Scheduler& scheduler);

private:
bool otaSupported() const;

void onFirmwareUpdateFinish(AsyncWebServerRequest* request);
void onFirmwareUpdateUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final);
void onFirmwareStatus(AsyncWebServerRequest* request);
};
28 changes: 28 additions & 0 deletions src/WebApi_firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "WebApi.h"
#include "helper.h"
#include <AsyncJson.h>
#include "esp_partition.h"

void WebApiFirmwareClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
Expand All @@ -22,6 +23,15 @@ void WebApiFirmwareClass::init(AsyncWebServer& server, Scheduler& scheduler)
server.on("/api/firmware/update", HTTP_POST,
std::bind(&WebApiFirmwareClass::onFirmwareUpdateFinish, this, _1),
std::bind(&WebApiFirmwareClass::onFirmwareUpdateUpload, this, _1, _2, _3, _4, _5, _6));

server.on("/api/firmware/status", HTTP_GET, std::bind(&WebApiFirmwareClass::onFirmwareStatus, this, _1));
}

bool WebApiFirmwareClass::otaSupported() const
{
const esp_partition_t* pOtaPartition = esp_partition_find_first(
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
return (pOtaPartition != nullptr);
}

void WebApiFirmwareClass::onFirmwareUpdateFinish(AsyncWebServerRequest* request)
Expand All @@ -46,6 +56,10 @@ void WebApiFirmwareClass::onFirmwareUpdateUpload(AsyncWebServerRequest* request,
return;
}

if (!otaSupported()) {
return request->send(500, "text/plain", "OTA updates not supported");
}

// Upload handler chunks in data
if (!index) {
if (!request->hasParam("MD5", true)) {
Expand Down Expand Up @@ -78,3 +92,17 @@ void WebApiFirmwareClass::onFirmwareUpdateUpload(AsyncWebServerRequest* request,
return;
}
}

void WebApiFirmwareClass::onFirmwareStatus(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentialsReadonly(request)) {
return;
}

AsyncJsonResponse* response = new AsyncJsonResponse();
auto& root = response->getRoot();

root["ota_supported"] = otaSupported();

WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}
1 change: 1 addition & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@
"firmwareupgrade": {
"FirmwareUpgrade": "Firmware-Aktualisierung",
"Loading": "@:base.Loading",
"NoOtaSupport": "Diese Plattform unterstützt keine OTA-Updates. Neue Firmware kann über die USB-Schnittstelle in den Flash-Speicher geschrieben werden.",
"OtaError": "OTA-Fehler",
"Back": "Zurück",
"Retry": "Wiederholen",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@
"firmwareupgrade": {
"FirmwareUpgrade": "Firmware Upgrade",
"Loading": "@:base.Loading",
"NoOtaSupport": "This platform does not support OTA updates. New firmware can be written to flash memory using the USB interface.",
"OtaError": "OTA Error",
"Back": "Back",
"Retry": "Retry",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@
"firmwareupgrade": {
"FirmwareUpgrade": "Mise à jour du firmware",
"Loading": "@:base.Loading",
"NoOtaSupport": "Cette plateforme ne prend pas en charge les mises à jour OTA. Les nouveaux microprogrammes peuvent être enregistrés dans la mémoire flash à l'aide de l'interface USB.",
"OtaError": "Erreur OTA",
"Back": "Retour",
"Retry": "Réessayer",
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/types/FirmwareStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FirmwareStatus {
ota_supported: boolean;
}
22 changes: 20 additions & 2 deletions webapp/src/views/FirmwareUpgradeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
</div>
</CardElement>

<CardElement
:text="$t('firmwareupgrade.OtaError')"
textVariant="text-bg-warning"
v-else-if="!loading && firmwareStatus.ota_supported === false"
>
{{ $t('firmwareupgrade.NoOtaSupport') }}
</CardElement>

<CardElement
:text="$t('firmwareupgrade.FirmwareUpload')"
textVariant="text-bg-primary"
Expand Down Expand Up @@ -83,8 +91,9 @@

<script lang="ts">
import BasePage from '@/components/BasePage.vue';
import type { FirmwareStatus } from '@/types/FirmwareStatus';
import CardElement from '@/components/CardElement.vue';
import { authHeader, isLoggedIn } from '@/utils/authentication';
import { authHeader, isLoggedIn, handleResponse } from '@/utils/authentication';
import { BIconArrowLeft, BIconArrowRepeat, BIconCheckCircle, BIconExclamationCircleFill } from 'bootstrap-icons-vue';
import SparkMD5 from 'spark-md5';
import { defineComponent } from 'vue';
Expand All @@ -108,6 +117,7 @@ export default defineComponent({
type: 'firmware',
file: {} as Blob,
hostCheckInterval: 0,
firmwareStatus: {} as FirmwareStatus,
};
},
methods: {
Expand Down Expand Up @@ -219,6 +229,14 @@ export default defineComponent({
console.log('Browser is offline. Cannot check remote host.');
}
},
getFirmwareStatus() {
fetch('/api/firmware/status', { headers: authHeader() })
.then((response) => handleResponse(response, this.$emitter, this.$router))
.then((data) => {
this.firmwareStatus = data;
this.loading = false;
});
},
},
mounted() {
if (!isLoggedIn()) {
Expand All @@ -227,7 +245,7 @@ export default defineComponent({
query: { returnUrl: this.$router.currentRoute.value.fullPath },
});
}
this.loading = false;
this.getFirmwareStatus();
},
unmounted() {
clearInterval(this.hostCheckInterval);
Expand Down
Loading