示例#1
0
def upload_program(config, args, host):
    # if upload is to a serial port use platformio, otherwise assume ota
    if get_port_type(host) == 'SERIAL':
        if CORE.is_esp8266:
            return upload_using_esptool(config, host)
        return platformio_api.run_upload(config, args.verbose, host)

    from esphome.components import ota
    from esphome import espota2

    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOME_OTA_HOST_PORT', random.randint(10000, 60000)))

    verbose = args.verbose
    remote_port = ota.get_port(config)
    password = ota.get_auth(config)

    storage = StorageJSON.load(storage_path())
    res = espota2.run_ota(host, remote_port, password, CORE.firmware_bin)
    if res == 0:
        if storage is not None and storage.use_legacy_ota:
            storage.use_legacy_ota = False
            storage.save(storage_path())
        return res
    if storage is not None and not storage.use_legacy_ota:
        return res

    _LOGGER.warning("OTA v2 method failed. Trying with legacy OTA...")
    return espota2.run_legacy_ota(verbose, host_port, host, remote_port,
                                  password, CORE.firmware_bin)
示例#2
0
def upload_program(config, args, host):
    # if upload is to a serial port use platformio, otherwise assume ota
    if get_port_type(host) == 'SERIAL':
        from esphome import platformio_api

        if CORE.is_esp8266:
            return upload_using_esptool(config, host)
        return platformio_api.run_upload(config, CORE.verbose, host)

    from esphome import espota2

    ota_conf = config[CONF_OTA]
    remote_port = ota_conf[CONF_PORT]
    password = ota_conf[CONF_PASSWORD]
    return espota2.run_ota(host, remote_port, password, CORE.firmware_bin)
示例#3
0
def upload_program(config, args, host):
    # if upload is to a serial port use platformio, otherwise assume ota
    if get_port_type(host) == 'SERIAL':
        from esphome import platformio_api

        if CORE.is_esp8266:
            return upload_using_esptool(config, host)
        return platformio_api.run_upload(config, CORE.verbose, host)

    from esphome import espota2

    if CONF_OTA not in config:
        raise EsphomeError("Cannot upload Over the Air as the config does not include the ota: "
                           "component")

    ota_conf = config[CONF_OTA]
    remote_port = ota_conf[CONF_PORT]
    password = ota_conf[CONF_PASSWORD]
    return espota2.run_ota(host, remote_port, password, CORE.firmware_bin)