Skip to content

Commit

Permalink
allow patching ssid/pass nvm variables (experimental)
Browse files Browse the repository at this point in the history
enable reconnection to serial port if communication failed
  • Loading branch information
g3gg0 committed Jul 26, 2024
1 parent 01da2dc commit c0ecf18
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions contrib/data/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,8 @@ <h3>Encode to {this.props.path}</h3>
showDownload: false,
showFlash: false,
connected: false,
wifi_ssid: '',
wifi_pass: '',
hostname: window.location.hostname
};
this.fileInputRef = React.createRef();
Expand Down Expand Up @@ -1993,7 +1995,7 @@ <h3>Encode to {this.props.path}</h3>
} catch (err) {
this.setState({ state: `Failed to connect: ${err.message}`, connected: false });
alert(err.message);
await port.close();
this.state.port = null;
return;
}

Expand All @@ -2018,7 +2020,7 @@ <h3>Encode to {this.props.path}</h3>
this.setState({ state: `Failed to communicate: ${err.message}`, connected: false });
console.error(err);
alert(err.message);
await port.close();
this.state.port = null;
return;
}
};
Expand Down Expand Up @@ -2079,7 +2081,7 @@ <h3>Encode to {this.props.path}</h3>
} catch (err) {
this.setState({ state: `Failed to connect: ${err.message}`, connected: false });
alert(err.message);
await port.close();
this.state.port = null;
return;
}

Expand Down Expand Up @@ -2149,15 +2151,15 @@ <h3>Encode to {this.props.path}</h3>
this.setState({ state: `Failed to communicate: ${err.message}`, connected: false });
console.error(err);
alert(err.message);
await port.close();
this.state.port = null;
return;
}
}

async patchFlash() {
this.setState({ showProgress: false, showFlash: false });
this.setState({ state: `Patching flash image...` });
const response = await fetch(`/api/patchFirmware?filename=${this.state.filename}&hostname=${this.state.hostname}`, {
const response = await fetch(`/api/patchFirmware?filename=${this.state.filename}&hostname=${this.state.hostname}&wifi_ssid=${this.state.wifi_ssid}&wifi_pass=${this.state.wifi_pass}`, {
method: 'GET'
});
this.setState({ state: `Payload received` });
Expand Down Expand Up @@ -2194,7 +2196,7 @@ <h3>Encode to {this.props.path}</h3>
} catch (err) {
this.setState({ state: `Failed to connect: ${err.message}`, connected: false });
alert(err.message);
await port.close();
this.state.port = null;
return;
}

Expand Down Expand Up @@ -2236,7 +2238,7 @@ <h3>Encode to {this.props.path}</h3>
this.setState({ state: `Failed to communicate: ${err.message}`, connected: false });
console.error(err);
alert(err.message);
await port.close();
this.state.port = null;
return;
}

Expand Down Expand Up @@ -2310,6 +2312,7 @@ <h3>ESP32 box flashing</h3>

<div className="center-content">
{this.state.showDownload && (
<div>
<div>
<label>
TeddyCloud hostname:
Expand All @@ -2333,8 +2336,40 @@ <h3>ESP32 box flashing</h3>
}}
/>
</label>
</div>
<div>
<label>
WiFi SSID:
<input
type="text"
defaultValue=""
onChange={(e) => {
let value = e.target.value;
this.setState({
wifi_ssid: value
});
}}
/> (leave empty to skip patching)
</label>
</div>
<div>
<label>
WiFi Password:
<input
type="text"
defaultValue=""
onChange={(e) => {
let value = e.target.value;
this.setState({
wifi_pass: value
});
}}
/>
</label>

{this.state.warningText && <p style={{ color: '#CC3010' }}>{this.state.warningText}</p>}
</div>
</div>
)}

{/* Hidden file input to handle file selection */}
Expand Down

0 comments on commit c0ecf18

Please sign in to comment.