(由Hori推荐)
MicroPython-Ctl:一个用于与MicroPython设备(例如ESP32 / 8266,Raspberry Pi Pico,Pyboard,WiPy等)进行通信的TypeScript库。
使用micropython-ctl快速构建应用程序与MicroPython设备交互:网站/ webapps中,Node.js的程序,电子应用,Visual Studio代码扩展(例如使用,移动应用阵营原住民)等等。
- 通过串行或网络接口连接到设备
- 运行Python脚本,接收输出
- 处理文件和目录
- 终端(REPL)交互
- mctl 命令行实用程序
- 在本地安装MicroPython设备(使用FUSE,实验性)
- 类型化且完全异步(可以await与任何命令一起使用)。
- 适用于Linux,macOS和Windows
安装
对于Node.js和Electron,请l从npm安装micropython-ct:
代码: 全选
# Install with yarn
$ yarn add micropython-ctl
# or with npm
$ npm install micropython-ctl
用法示例
代码: 全选
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('print("Hello world")')
console.log('runScript output:', output) // -> Hello world
// List all files in the root
const files = await micropython.listFiles()
console.log('files:', files)
/* [
{ filename: '/boot.py', size: 31, isDir: false },
{ filename: '/files', size: 0, isDir: true }
] */
// Get information about the board:
const boardInfo = await micropython.getBoardInfo()
console.log(boardInfo)
/* {
sysname: 'esp32',
nodename: 'esp32',
release: '1.13.0',
version: 'v1.13 on 2020-09-02',
machine: 'ESP32 module with ESP32',
uniqueId: 'c44f3312f529',
memFree: 108736,
fsBlockSize: 4096,
fsBlocksTotal: 512,
fsBlocksFree: 438
} */
// 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
// Trigger a hard reset of the device
await micropython.reset()