1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
|
.TH mpremote 1
.
.SH NAME
mpremote \- MicroPython remote control
.
.
.SH SYNOPSIS
.SY mpremote
command
.OP options
.OP "+ command" ...
.YS
.
.SY mpremote
.OP \-\-help
.YS
.
.SY mpremote
.OP \-\-version
.YS
.
.
.SH DESCRIPTION
The
.B mpremote
command line tool provides an integrated set of utilities to remotely interact
with and automate a MicroPython device over a serial connection.
.
.PP
The simplest way to use this tool is just by invoking it without any arguments:
.
.RS
.PP
.EX
mpremote
.EE
.RE
.
.PP
This command automatically detects and connects to the first available serial
device and provides an interactive REPL.
Serial ports are opened in exclusive mode, so running a second (or third, etc)
instance of
.B mpremote
will connect to subsequent serial devices, if any are available.
.
.
.SH OPTIONS
.
.TP
.B \-\-help
Show a help message and exit.
.
.TP
.B \-\-version
Show the program version and exit.
.
.
.SH COMMANDS
For REPL access, running
.B mpremote
without any arguments is usually all that is
needed.
.B mpremote
also supports a set of commands given at the command line which will perform
various actions on remote MicroPython devices.
.
.PP
For commands that support multiple arguments (e.g. a list of files), the
argument list can be terminated with
.BR + .
.
The full list of supported commands are:
.
.TP
.BR connect " [\fIdevice\fR]"
Connect to a specified device via a device-name shortcut.
.I device
may be one of:
.
.RS
.TP
auto
connect to the first available device
.
.TP
list
list the available devices
.
.TP
.RI id: serial
connect to the device with USB serial number
.I serial
(the second entry in the output from the
.B connect list
command)
.
.TP
.RI port: path
connect to the device with the given path
.RE
.
.IP
If the
.I device
is not specified, auto is assumed.
.
.TP
.B disconnect
Disconnects the current device. After a disconnect, auto
.B soft-reset
is enabled (see
.B AUTO-CONNECTION AND SOFT-RESET
below).
.
.TP
.B resume
Resume a previous
.B mpremote
session. This disables auto
.B soft-reset
(see
.B AUTO-CONNECTION AND SOFT-RESET
below).
.
.TP
.B soft-reset
Perform a soft-reset of the device.
This will clear out the Python heap and restart the interpreter.
It also disables auto
.B soft-reset
(see
.B AUTO-CONNECTION AND SOFT-RESET
below).
.
.TP
.BR repl " [\fIoptions\fR]"
Enter the REPL on the connected device.
The available
.I options
are:
.
.RS
.TP
.BI \-\-capture " file"
to capture output of the REPL session to the given file
.
.TP
.BI \-\-inject\-code " string"
to specify characters to inject at the REPL when
.B Ctrl-J
is pressed
.
.TP
.BI \-\-inject\-file " file"
to specify a file to inject at the REPL when
.B Ctrl-K
is pressed
.RE
.
.TP
.BI eval " string"
Evaluate ahd print the result of a Python expression.
.
.TP
.BI exec " string"
Execute the given Python code.
.
.TP
.BI run " file"
Run a script from the local filesystem.
.
.TP
.BI fs " subcommand"
Execute filesystem commands on the device.
.I subcommand
may be:
.
.RS
.TP
.BI cat " files..."
to show the contents of a file or files on the device
.
.TP
.B ls
.TQ
.BI ls " dirs..."
to list the current, or specified directories
.
.TP
.BR cp " [\fI-r\fR]\fI src... dest"
to copy files; use ":" as a prefix to specify a file on the device
.
.TP
.BI rm " src..."
to remove files on the device
.
.TP
.BI mkdir " dirs..."
to create directories on the device
.
.TP
.BI rmdir " dirs..."
to remove directories on the device
.
.TP
.BI touch " files..."
to create empty files (if they don't already exist)
.RE
.
.TP
.BI edit " files..."
Edit a file (or files) on the device. The
.B edit
command will copy each file from the device to a local temporary directory and
then launch your editor (defined by the environment variable
.IR $EDITOR ).
If the editor exits successfully, the updated file will be copied back to the
device.
.
.TP
.BR "mip install" " [\fIoptions\fR]\fI packages..."
Install packages from micropython-lib (or GitHub) using the
.B mip
tool.
The available
.I options
are:
.
.RS
.TP
.BI \-\-target " path"
Install under
.I path
instead of the default location (the first entry in
.B sys.path
ending in
.BR /lib ).
Please note that
.I
must exist in
.B sys.path
for you to be able to subsequently import the package.
.
.TP
.B \-\-no\-mpy
Install the source version
.I .py
files rather than
.IR .mpy).
.
.TP
.BI \-\-index " URL"
Use the specified
.I URL
instead of the default package index at
.BR https://\:micropython.org/\:pi .
.RE
.
.TP
.BR mount " [\fIoptions\fR]\fI local-dir"
Mount a local directory on the remote device (under the path
.BR /remote ).
During usage,
.B Ctrl-D
will soft-reboot and normally reconnect the mount automatically.
If the unit has a
.I main.py
running at startup however, the remount cannot occur.
In this case a raw mode soft reboot can be used:
.B Ctrl-A Ctrl-D
to reboot, then
.B Ctrl-B
to get back to normal repl at which point the mount will be ready.
.
.IP
The available
.I options
are:
.
.RS
.TP
.BR \-l ", " \-\-unsafe\-links
By default an error will be raised if the device accesses a file or directory
which is outside (up one or more directory levels) the local directory that is
mounted.
This option disables this check for symbolic links, allowing the device to
follow symbolic links outside of the local directory.
.RE
.
.TP
.B umount
Unmount the local directory from the remote device.
.
.
.SH AUTO-CONNECTION AND SOFT-RESET
Connection and disconnection will be done automatically at the start and end of
the execution of the tool, if such commands are not explicitly given.
Automatic connection will search for the first available serial device.
If no action is specified then the REPL will be entered.
.
.PP
Once connected to a device,
.B mpremote
will automatically soft-reset the device if needed.
This clears the Python heap and restarts the interpreter, making sure that
subsequent Python code executes in a fresh environment.
Auto soft-reset is performed the first time one of the following commands are
executed:
.BR mount ", " eval ", " exec ", " run ", " fs .
After doing a soft-reset for the first time, it will not be done again
automatically, until a disconnect command is issued.
.
.PP
Auto soft-reset behaviour can be controlled by the
.B resume
command. And the
.B soft-reset
command can be used to perform an explicit soft reset.
.
.
.SH SHORTCUTS
Shortcuts can be defined using the macro system. Built-in shortcuts are:
.
.RS
.TP
.B devs
list available devices (shortcut for
.BR "connect list" )
.
.TP
.BR a0 ", " a1 ", " a2 ", " a3
connect to
.RI /dev/ttyACM n
.
.TP
.BR u0 ", " u1 ", " u2 ", " u3
connect to
.RI /dev/ttyUSB n
.
.TP
.BR c0 ", " c1 ", " c2 ", " c3
connect to
.RI COM n
.
.TP
.BR cat ", " ls ", " cp ", " rm ", " mkdir ", " rmdir ", " touch ", " df
filesystem commands (mostly aliases for the
.B fs
equivalent)
.
.TP
.B reset
reset the device
.
.TP
.B bootloader
make the device enter its bootloader
.RE
.
.PP
Any user configuration, including user-defined shortcuts, can be placed in the
file
.BR ~/.config/mpremote/config.py .
For example:
.
.RS
.PP
.EX
commands = {
"c33": "connect id:334D335C3138",
"bl": "bootloader",
"double x=4": "eval x*2", # x is an argument, with default 4
"wl_scan": ["exec", """
import network
wl = network.WLAN()
wl.active(1)
for ap in wl.scan():
print(ap)
""",],
"test": ["mount", ".", "exec", "import test"],
}
.EE
.RE
.
.
.SH EXAMPLES
.TP
.B mpremote
Launch a repl on the automatically detected device.
.
.TP
.B mpremote a1
Launch a repl on the device connected to port
.B /dev/ttyACM1
(using the built-in
.B a1
shortcut).
.
.TP
.B mpremote connect /dev/ttyUSB0 repl
Launch a repl on the device connect to port
.BR /dev/ttyUSB0 .
.
.TP
.B mpremote ls
List files on the automatically detected device.
.
.TP
.B mpremote a1 ls
List files on the device connected to port
.B /dev/ttyACM1
(using the built-in
.B a1
shortcut).
.
.TP
.B mpremote exec "import micropython; micropython.mem_info()"
Execute some Python code on the remote board to obtain various memory
statistics.
.
.TP
.B mpremote eval 1/2 eval 3/4
Execute (and show the output of) two simple Python statements on the remote
board. Note that no
.B +
was required because
.B eval
accepts a single string argument.
.
.TP
.B mpremote mount .
Mount the local directory under
.B /remote
on the automatically detected device.
.
.TP
.B mpremote mount . exec \(dqimport localscript\(dq
Mount the local directory under
.B /remote
on the MicroPython board, then import the "localscript" module
.
.TP
.B mpremote cat boot.py
Show the contents of
.B boot.py
on the MicroPython board.
.
.TP
.B mpremote cp :main.py .
Copy the
.B main.py
file from the (remote) MicroPython board to the current (local) directory.
.
.TP
.B mpremote cp main.py :
Copy the
.B main.py
from the current (local) directory to the (remote) MicroPython board.
.
.TP
.B mpremote cp :a.py :b.py
On the MicroPython board, copy
.B a.py
to
.BR b.py .
.
.TP
.B mpremote cp -r dir/ :
Recursively copy the local directory
.B dir/
to the root directory of the (remote) MicroPython board.
.
.TP
.B mpremote cp a.py b.py : + repl
Copy the local files
.B a.py
and
.B b.py
to the root directory of the (remote) MicroPython board, then launch a repl.
Note that the
.B +
terminator is required here as the
.B cp
command takes an arbitrary number of parameters.
.
.TP
.B mpremote mip install aioble
Install the asyncio-based wrapper for the Bluetooth API.
.
.TP
.B mpremote mip install github:org/repo@branch
Install the
.B branch
of the MicroPython package located under
.B org/repo
on GitHub.
.
.TP
.B mpremote mip install --target /flash/third-party functools
Install the
.B functools
package under the
.B /flash/third-party
directory on the MicroPython board.
.
.
.SH SEE ALSO
.BR micropython (1)
|