Skip to content

Commit

Permalink
webrepl.html: Display MicroPython version on connect/authenticate
Browse files Browse the repository at this point in the history
After connecting and authenticating, get the version after receiving
the first message that contains `WebREPL connected` and slap it in a
`<span>`.
  • Loading branch information
mcauser committed Oct 26, 2016
1 parent f8dbf12 commit 8e59ff0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions webrepl.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<form>
<input type="text" name="webrepl_url" id="url" value="ws://192.168.4.1:8266/" />
<input type="submit" id="button" value="Connect" onclick="button_click(); return false;" />
<span id="version"></span>
</form>
<div id="term">
</div>
Expand Down Expand Up @@ -88,6 +89,7 @@
var put_file_data = null;
var get_file_name = null;
var get_file_data = null;
var version = null;

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

ws.onmessage = function(event) {
if (version == undefined && typeof event.data == 'string' && event.data.indexOf('WebREPL connected') > 0) {
get_ver();
}
if (event.data instanceof ArrayBuffer) {
var data = new Uint8Array(event.data);
switch (binary_state) {
Expand Down Expand Up @@ -224,6 +229,8 @@
case 31:
// first (and last) response for GET_VER
console.log('GET_VER', data);
version = data.join('.');
document.getElementById('version').innerText = 'MicroPython ' + version;
binary_state = 0;
break;
}
Expand Down

0 comments on commit 8e59ff0

Please sign in to comment.