How use otatool.py from vscode

How change is required for use this or other esp py cmdlets from vscode terminal?
For example

otatool.py switch_ota_partition --slot 1

Going off this, you can write a script that also calls into these scripts and makes them available as a project task.

grafik

By taking the hello-world example and adding

extra_scripts = switch_partitions.py
board_build.partitions = partitions_two_ota.csv

with switch_partitions.py in the same folder as the platformio.ini

from os.path import join
from os import environ
Import("env")

platform = env.PioPlatform()
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
ESPTOOLPY_DIR = platform.get_package_dir("tool-esptoolpy")
OTATOOL_SCRIPT = join(FRAMEWORK_DIR, "components", "app_update", "otatool.py")
# so that "python -m esptool" works, otherwise not found
if "PYTHONPATH" in environ:
    environ["PYTHONPATH"] = environ["PYTHONPATH"]  + ":" + ESPTOOLPY_DIR
else:
    environ["PYTHONPATH"] = ESPTOOLPY_DIR
environ["IDF_PATH"] = FRAMEWORK_DIR # otatool.py needs this to find parttool

for slot in [0, 1]:
    env.AddCustomTarget(
        name="switch_ota_slot_%d" % slot,
        dependencies=None,
        actions=[
            "$PYTHONEXE \"%s\" switch_ota_partition --slot %d" % (OTATOOL_SCRIPT, slot)
        ],
        title="Switch to OTA Slot %d" % slot,
        description="Switches the active partition to OTA slot %d" % slot
    )

Cool , but not very simple, i mean when i choice platfromio and platform esparduino or idf , i have access to this base commands.

1 Like