Skip to content

Commit

Permalink
Fetch flash manifest.json from backend (#91)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulus Schoutsen <[email protected]>
  • Loading branch information
jesserockz and balloob authored Oct 14, 2021
1 parent 347f0f1 commit f18072b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
7 changes: 6 additions & 1 deletion src/api/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export interface Configuration {
src_version: number;
arduino_version: string;
address: string;
esp_platform: "ESP8266" | "ESP32";
esp_platform: "esp8266" | "esp32";
board: string;
build_path: string;
firmware_bin_path: string;
loaded_integrations: string[];
}

export type Manifest = { path: string; offset: number }[];

export const createConfiguration = (params: CreateConfigParams) =>
fetchApiText("./wizard", {
method: "post",
Expand All @@ -39,3 +41,6 @@ export const deleteConfiguration = (configuration: string) =>

export const compileConfiguration = (configuration: string) =>
streamLogs("compile", { configuration });

export const getConfigurationManifest = (configuration: string) =>
fetchApiJson<Manifest>(`./manifest.json?configuration=${configuration}`);
28 changes: 15 additions & 13 deletions src/flash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ESPLoader } from "esp-web-flasher";
import { getConfiguration } from "./api/configuration";
import {
getConfiguration,
getConfigurationManifest,
Manifest,
} from "./api/configuration";
import { chipFamilyToPlatform } from "./const";

export const flashConfiguration = async (
Expand All @@ -10,23 +14,21 @@ export const flashConfiguration = async (
) => {
const config = await getConfiguration(filename);

if (chipFamilyToPlatform[esploader.chipFamily] !== config.esp_platform) {
if (
chipFamilyToPlatform[esploader.chipFamily] !==
config.esp_platform.toUpperCase()
) {
throw new Error(
`Configuration does not match the platform of the connected device. Expected a ${config.esp_platform} device.`
`Configuration does not match the platform of the connected device. Expected a ${config.esp_platform.toUpperCase()} device.`
);
}

let toFlash: { path: string; offset: number }[];
let toFlash: Manifest;

if (config.esp_platform === "ESP32") {
toFlash = [
{ path: "./static/firmware/bootloader.bin", offset: 4096 },
{ path: "./static/firmware/partitions.bin", offset: 32768 },
{ path: "./static/firmware/ota.bin", offset: 57344 },
{ path: `./download.bin?configuration=${filename}`, offset: 65536 },
];
} else {
toFlash = [{ path: `./download.bin?configuration=${filename}`, offset: 0 }];
try {
toFlash = await getConfigurationManifest(filename);
} catch (err) {
throw new Error(`Error fetching manifest.json for ${filename}: ${err}`);
}

const filePromises = toFlash.map(async (part) => {
Expand Down
4 changes: 2 additions & 2 deletions src/install-update/install-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ESPHomeInstallDialog extends LitElement {
html`
Installing<br /><br />
This will take
${this._configuration!.esp_platform === "ESP8266"
${this._configuration!.esp_platform === "esp8266"
? "a minute"
: "2 minutes"}.<br />
Keep this page visible to prevent slow down
Expand Down Expand Up @@ -347,7 +347,7 @@ class ESPHomeInstallDialog extends LitElement {
}
);
} catch (err) {
this._error = "Installation failed";
this._error = `Installation failed: ${err}`;
this._state = "done";
return;
}
Expand Down

0 comments on commit f18072b

Please sign in to comment.