Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to micropython-ctl #58

Open
metachris opened this issue Feb 26, 2021 · 0 comments
Open

Link to micropython-ctl #58

metachris opened this issue Feb 26, 2021 · 0 comments

Comments

@metachris
Copy link

I've build https://github.com/metachris/micropython-ctl, a TypeScript library (and cli) for talking to MicroPython devices from websites/webapps, Node.js and Electron apps, VS code extensions (and more).

I'm hoping it is useful and furthers the MicroPython developer ecosystem and convenience, and thought it might be beneficial for developers that want to build something to know this exists. Do you want to add a reference to micropython-ctl from this repository?

micropython-ctl is fully async, allowing developers to await code executions and doing things with the response. Here is more documentation: https://metachris.github.io/micropython-ctl/classes/micropythondevice.html

Code samples:

const micropython = new MicroPythonDevice()

// Connect to micropython device over network
await micropython.connectNetwork('DEVICE_IP', 'WEBREPL_PASSWORD')

// Or connect to micropython device over serial interface
await micropython.connectSerial('/dev/ttyUSB0')

// Run a Python script and capture the output
const output = await micropython.runScript('import os; print(os.listdir())')
console.log('runScript output:', output)

// List all files in the root
const files = await micropython.listFiles()
console.log('files:', files)

// Get file contents
const fileContents = await micropython.getFile('boot.py')
console.log(fileContents)

// Set a terminal (REPL) data handler, and send data to the REPL
micropython.onTerminalData = (data) => process.stdout.write(data)
micropython.sendData('\x03\x02')  // Ctrl+C and Ctrl+B to enter friendly repl and print version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant