mirror of
https://github.com/esphome/esp-web-tools.git
synced 2025-07-27 05:36:40 +00:00
Allow configuring improv timeout (#139)
This commit is contained in:
parent
58c76e98bc
commit
ebef0688c8
12
index.html
12
index.html
@ -362,12 +362,22 @@
|
||||
</p>
|
||||
<p>
|
||||
By default a new installation will erase all data before installation.
|
||||
If you want to leave this choice to the user, set the optional key
|
||||
If you want to leave this choice to the user, set the optional manifest
|
||||
key
|
||||
<code>new_install_prompt_erase</code> to <code>true</code>. ESP Web
|
||||
Tools offers users a new installation if it is unable to detect the
|
||||
current firmware of the device (via Improv Serial) or if the detected
|
||||
firmware does not match the name specififed in the manifest.
|
||||
</p>
|
||||
<p>
|
||||
When a firmware is first installed on a device, it might need to do some
|
||||
time consuming tasks like initializing the file system. By default ESP
|
||||
Web Tools will wait 10 seconds to receive an Improv Serial response to
|
||||
indicate that the boot is completed. You can increase this timeout by
|
||||
setting the optional manifest key
|
||||
<code>new_install_improv_wait_time</code> to the number of seconds to
|
||||
wait. Set to <code>0</code> to disable Improv Serial detection.
|
||||
</p>
|
||||
<h2 id="improv">Configuring Wi-Fi</h2>
|
||||
<p>
|
||||
ESP Web Tools supports the
|
||||
|
@ -19,6 +19,8 @@ export interface Manifest {
|
||||
/** @deprecated use `new_install_prompt_erase` instead */
|
||||
new_install_skip_erase?: boolean;
|
||||
new_install_prompt_erase?: boolean;
|
||||
/* Time to wait to detect Improv Wi-Fi. Set to 0 to disable. */
|
||||
new_install_improv_wait_time?: number;
|
||||
builds: Build[];
|
||||
}
|
||||
|
||||
|
@ -661,18 +661,25 @@ class EwtInstallDialog extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private async _fetchManifest() {
|
||||
if (this._manifest) {
|
||||
return;
|
||||
private async _initialize(justInstalled = false) {
|
||||
if (this.port.readable === null || this.port.writable === null) {
|
||||
this._state = "ERROR";
|
||||
this._error =
|
||||
"Serial port is not readable/writable. Close any other application using it and try again.";
|
||||
}
|
||||
|
||||
const manifestURL = new URL(
|
||||
this.manifestPath,
|
||||
location.toString()
|
||||
).toString();
|
||||
this._manifest = await fetch(manifestURL).then(
|
||||
(resp): Promise<Manifest> => resp.json()
|
||||
);
|
||||
try {
|
||||
this._manifest = await fetch(manifestURL).then(
|
||||
(resp): Promise<Manifest> => resp.json()
|
||||
);
|
||||
} catch (err: any) {
|
||||
this._state = "ERROR";
|
||||
this._error = "Failed to download manifest";
|
||||
}
|
||||
if ("new_install_skip_erase" in this._manifest) {
|
||||
console.warn(
|
||||
'Manifest option "new_install_skip_erase" is deprecated. Use "new_install_prompt_erase" instead.'
|
||||
@ -681,26 +688,25 @@ class EwtInstallDialog extends LitElement {
|
||||
this._manifest.new_install_prompt_erase = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async _initialize(justErased = false) {
|
||||
if (this.port.readable === null || this.port.writable === null) {
|
||||
this._state = "ERROR";
|
||||
this._error =
|
||||
"Serial port is not readable/writable. Close any other application using it and try again.";
|
||||
if (this._manifest.new_install_improv_wait_time === 0) {
|
||||
this._client = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const manifestProm = this._fetchManifest();
|
||||
|
||||
const client = new ImprovSerial(this.port!, this.logger);
|
||||
client.addEventListener("state-changed", () => {
|
||||
this.requestUpdate();
|
||||
});
|
||||
client.addEventListener("error-changed", () => this.requestUpdate());
|
||||
try {
|
||||
// If a device was just erased, the new firmware might need some time to
|
||||
// format the rest of the flash.
|
||||
const timeout = justErased ? 10000 : 1000;
|
||||
// If a device was just installed, give new firmware 10 seconds (overridable) to
|
||||
// format the rest of the flash and do other stuff.
|
||||
const timeout = !justInstalled
|
||||
? 1000
|
||||
: this._manifest.new_install_improv_wait_time !== undefined
|
||||
? this._manifest.new_install_improv_wait_time
|
||||
: 10000;
|
||||
this._info = await client.initialize(timeout);
|
||||
this._client = client;
|
||||
client.addEventListener("disconnect", this._handleDisconnect);
|
||||
@ -716,13 +722,6 @@ class EwtInstallDialog extends LitElement {
|
||||
this.logger.error("Improv initialization failed.", err);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await manifestProm;
|
||||
} catch (err: any) {
|
||||
this._state = "ERROR";
|
||||
this._error = "Failed to download manifest";
|
||||
}
|
||||
}
|
||||
|
||||
private _startInstall(erase: boolean) {
|
||||
@ -745,7 +744,7 @@ class EwtInstallDialog extends LitElement {
|
||||
|
||||
if (state.state === FlashStateType.FINISHED) {
|
||||
sleep(100)
|
||||
.then(() => this._initialize(this._installErase))
|
||||
.then(() => this._initialize(true))
|
||||
.then(() => this.requestUpdate());
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user