Skip to content

Commit 5869ef1

Browse files
committed
Display MicroPython version on connect/authenticate
After connecting and authenticating, get the version after receiving the first message that contains `WebREPL connected` and slap it in a `<span>`.
1 parent f8dbf12 commit 5869ef1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

webrepl.html

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<form>
4949
<input type="text" name="webrepl_url" id="url" value="ws://192.168.4.1:8266/" />
5050
<input type="submit" id="button" value="Connect" onclick="button_click(); return false;" />
51+
<span id="version"></span>
5152
</form>
5253
<div id="term">
5354
</div>
@@ -88,6 +89,7 @@
8889
var put_file_data = null;
8990
var get_file_name = null;
9091
var get_file_data = null;
92+
var version = null;
9193

9294
function calculate_size(win) {
9395
var cols = Math.max(80, Math.min(150, (win.innerWidth - 280) / 7)) | 0;
@@ -154,6 +156,9 @@
154156
term.write('\x1b[31mWelcome to MicroPython!\x1b[m\r\n');
155157

156158
ws.onmessage = function(event) {
159+
if (version == undefined && typeof event.data == 'string' && event.data.indexOf('WebREPL connected') > 0) {
160+
get_ver();
161+
}
157162
if (event.data instanceof ArrayBuffer) {
158163
var data = new Uint8Array(event.data);
159164
switch (binary_state) {
@@ -224,6 +229,8 @@
224229
case 31:
225230
// first (and last) response for GET_VER
226231
console.log('GET_VER', data);
232+
version = data.join('.');
233+
document.getElementById('version').innerText = 'MicroPython ' + version;
227234
binary_state = 0;
228235
break;
229236
}

0 commit comments

Comments
 (0)