void handleFirmwarePage() {
  String html = pageStart(tr("firmware_update"), "firmware");

  html += "<div class='card'><h2>" + tr("upload_new_firmware") + "</h2>";
  html += "<p>" + tr("firmware_help") + "</p>";
  html += "<form method='POST' action='/update' enctype='multipart/form-data'>";
  html += "<input type='file' name='firmware' accept='.bin'><br><br>";
  html += "<button type='submit'>" + tr("upload_restart") + "</button>";
  html += "</form></div>";

  html += "<div class='card'><h2>" + tr("important") + "</h2>";
  html += "<p>" + tr("firmware_warning") + "</p>";
  html += "<p><b>" + tr("current_version") + ":</b> 20.0</p>";
  html += "</div>";

  html += pageEnd();
  server.send(200, "text/html", html);
}

void handleFirmwareUploadDone() {
  bool ok = !Update.hasError();
  String html = pageStart(ok ? tr("firmware_saved") : tr("firmware_error"), "firmware");

  if (ok) {
    html += "<div class='card'><h2>" + tr("update_complete") + "</h2>";
    html += "<p>" + tr("esp_restarts") + "</p></div>";
  } else {
    html += "<div class='card'><h2>" + tr("update_failed") + "</h2>";
    html += "<p>" + String(Update.errorString()) + "</p>";
    html += "<p><a class='btn' href='/firmware'>" + tr("back") + "</a></p></div>";
  }

  html += pageEnd();
  server.send(ok ? 200 : 500, "text/html", html);

  if (ok) {
    delay(1000);
    ESP.restart();
  }
}

void handleFirmwareUpload() {
  HTTPUpload& upload = server.upload();

  if (upload.status == UPLOAD_FILE_START) {
    Serial.printf("Firmware upload starter: %s\n", upload.filename.c_str());
    if (mqttClient.connected()) mqttClient.disconnect();

    if (!Update.begin(UPDATE_SIZE_UNKNOWN)) {
      Update.printError(Serial);
    }
  } else if (upload.status == UPLOAD_FILE_WRITE) {
    if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
      Update.printError(Serial);
    }
  } else if (upload.status == UPLOAD_FILE_END) {
    if (Update.end(true)) {
      Serial.printf("Firmware upload faerdig: %u bytes\n", upload.totalSize);
    } else {
      Update.printError(Serial);
    }
  } else if (upload.status == UPLOAD_FILE_ABORTED) {
    Update.end();
    Serial.println("Firmware upload afbrudt");
  }
}
