From 61350954dcaf6385868be29bd02d574af6a89d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Thu, 18 Apr 2019 04:13:34 +0200 Subject: [PATCH] Document passing arguments to main() (#408) * Document passing arguments to main() Addresses #406] --- README.md | 14 ++++++++++++++ esptool.py | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 40f3fed29..c5be2d1f3 100644 --- a/README.md +++ b/README.md @@ -416,6 +416,20 @@ Note that not every serial program supports the unusual ESP8266 74880bps "boot l Running `esptool.py --trace` will dump all serial interactions to the standard output (this is *a lot* of output). This can be helpful when debugging issues with the serial connection, or when providing information for bug reports. +## Using esptool.py from Python + +esptool.py can easily be integrated into Python applications or called from other Python scripts. + +While it currently does have a poor Python API, something which [#208](https://github.com/espressif/esptool/issues/208) will address, it allows for passing CLI +arguments to `esptool.main()`. This workaround makes integration very straightforward as you can pass exactly the +same arguments as you would on the CLI. + +```python +command = ['--baud', '460800', 'read_flash', '0', '0x200000', 'flash_contents.bin'] +print('Using command %s' % ' '.join(command)) +esptool.main(command) +``` + ## Internal Technical Documentation The [repository wiki](https://github.com/espressif/esptool/wiki) contains some technical documentation regarding the serial protocol and file format used by the ROM bootloader. This may be useful if you're developing esptool.py or hacking system internals: diff --git a/esptool.py b/esptool.py index b56e2157a..c09a800e9 100755 --- a/esptool.py +++ b/esptool.py @@ -2548,7 +2548,8 @@ def main(custom_commandline=None): Main function for esptool custom_commandline - Optional override for default arguments parsing (that uses sys.argv), can be a list of custom arguments - as strings. + as strings. Arguments and their values need to be added as individual items to the list e.g. "-b 115200" thus + becomes ['-b', '115200']. """ parser = argparse.ArgumentParser(description='esptool.py v%s - ESP8266 ROM Bootloader Utility' % __version__, prog='esptool')