@@ -65,7 +65,7 @@ <h1>micropython-ctl Browser Example</h1>
6565</ html >
6666
6767< script >
68- let micropythonDevice = null ;
68+ let micropython = null ;
6969
7070 const DIV_STATUS = document . getElementById ( 'status' )
7171 const DIV_OUTPUT = document . getElementById ( 'output' )
@@ -88,9 +88,9 @@ <h1>micropython-ctl Browser Example</h1>
8888 localStorage . setItem ( 'MicroPythonCtl:Password' , password )
8989
9090 // Connect
91- micropythonDevice = new MicroPythonCtl . MicroPythonDevice ( )
91+ micropython = new MicroPythonCtl . MicroPythonDevice ( )
9292 try {
93- await micropythonDevice . connectNetwork ( host , password )
93+ await micropython . connectNetwork ( host , password )
9494 } catch ( e ) {
9595 DIV_STATUS . innerHTML = `Error: ${ e . message } `
9696 BTN_CONNECT . textContent = 'Connect'
@@ -99,22 +99,24 @@ <h1>micropython-ctl Browser Example</h1>
9999 DIV_STATUS . innerHTML = BTN_CONNECT . textContent = 'Connected'
100100
101101 // onclose is a function which is called when the connection is closed
102- micropythonDevice . onclose = ( ) => DIV_STATUS . textContent = BTN_CONNECT . textContent = "Disconnected"
102+ micropython . onclose = ( ) => DIV_STATUS . textContent = BTN_CONNECT . textContent = "Disconnected"
103+
104+ // Display board info
105+ DIV_OUTPUT . innerHTML += `<p>Getting board info...</p>`
106+ const boardInfo = await micropython . getBoardInfo ( )
107+ DIV_OUTPUT . innerHTML += '<pre>' + JSON . stringify ( boardInfo , null , 4 ) + '</pre> <hr>'
103108
104109 // Run a Python script and capture the output
105110 const script = 'import os; print(os.listdir())'
106111 DIV_OUTPUT . innerHTML += `<p>Running a Python script: <tt>${ script } </tt> ...</p>`
107- const output = await micropythonDevice . runScript ( script )
108- DIV_OUTPUT . innerHTML += '<p>output: ' + output + '</p > <hr>'
112+ const output = await micropython . runScript ( script )
113+ DIV_OUTPUT . innerHTML += '<pre> ' + output + '</pre > <hr>'
109114
110115 // List all files in the root
111116 DIV_OUTPUT . innerHTML += '<p>Listing files...</p>'
112- const files = await micropythonDevice . listFiles ( '/' , { recursive : true } )
117+ const files = await micropython . listFiles ( '/' , { recursive : true } )
113118 console . log ( 'files' , files )
114- files . map ( file => {
115- if ( ! file . isDir ) {
116- DIV_OUTPUT . innerHTML += `<div style='padding-left:20px;'>${ file . filename } (${ file . size } b)</div>`
117- }
118- } )
119+ const s = files . map ( file => `${ file . size } b\t${ file . filename } ` ) . join ( '\n' )
120+ DIV_OUTPUT . innerHTML += '<pre>' + s + '</pre> <hr>'
119121 }
120122</ script >
0 commit comments