Skip to content

Link to micropython-ctl #58

Open
Open
@metachris

Description

@metachris

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions