Example #1
0
def upload_program(config, args, port):
    _LOGGER.info("Uploading binary...")
    if port != 'OTA':
        if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266 and args.use_esptoolpy:
            return upload_using_esptool(config, port)
        return run_platformio('platformio', 'run', '-d', get_base_path(config),
                              '-t', 'upload', '--upload-port', port)

    if 'ota' not in config:
        _LOGGER.error(
            "No serial port found and OTA not enabled. Can't upload!")
        return -1

    host = get_upload_host(config)

    from esphomeyaml.components import ota
    from esphomeyaml import espota

    bin_file = os.path.join(get_base_path(config), '.pioenvs',
                            get_name(config), 'firmware.bin')
    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOMEYAML_OTA_HOST_PORT',
                      random.randint(10000, 60000)))
    espota_args = [
        'espota.py', '--debug', '--progress', '-i', host, '-p',
        str(ota.get_port(config)), '-f', bin_file, '-a',
        ota.get_auth(config), '-P',
        str(host_port)
    ]
    return espota.main(espota_args)
Example #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':
        if CORE.is_esp8266:
            return upload_using_esptool(config, host)
        return platformio_api.run_upload(config, args.verbose, host)

    from esphomeyaml.components import ota
    from esphomeyaml import espota2

    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOMEYAML_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)
Example #3
0
def upload_program(config, args, port):
    _LOGGER.info("Uploading binary...")
    if port is not None:
        return run_platformio('platformio', 'run', '-d', get_base_path(config),
                              '-t', 'upload', '--upload-port', port)

    if CONF_MANUAL_IP in config[CONF_WIFI]:
        host = str(config[CONF_WIFI][CONF_MANUAL_IP][CONF_STATIC_IP])
    elif CONF_HOSTNAME in config[CONF_WIFI]:
        host = config[CONF_WIFI][CONF_HOSTNAME] + u'.local'
    else:
        host = config[CONF_ESPHOMEYAML][CONF_NAME] + u'.local'

    from esphomeyaml.components import ota
    from esphomeyaml import espota

    bin_file = os.path.join(get_base_path(config), '.pioenvs',
                            get_name(config), 'firmware.bin')
    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOMEYAML_OTA_HOST_PORT',
                      random.randint(10000, 60000)))
    espota_args = [
        'espota.py', '--debug', '--progress', '-i', host, '-p',
        str(ota.get_port(config)), '-f', bin_file, '-a',
        ota.get_auth(config), '-P',
        str(host_port)
    ]
    return espota.main(espota_args)
Example #4
0
def upload_program(config, args, port):
    build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])

    # if upload is to a serial port use platformio, otherwise assume ota
    serial_port = port.startswith('/') or port.startswith('COM')
    if port != 'OTA' and serial_port:
        if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266 and args.use_esptoolpy:
            return upload_using_esptool(config, port)
        command = [
            'platformio', 'run', '-d', build_path, '-t', 'upload',
            '--upload-port', port
        ]
        if args.verbose:
            command.append('-v')
        return run_platformio(*command)

    if 'ota' not in config:
        _LOGGER.error(
            "No serial port found and OTA not enabled. Can't upload!")
        return -1

    # If hostname/ip is explicitly provided as upload-port argument, use this instead of zeroconf
    # hostname. This is to support use cases where zeroconf (hostname.local) does not work.
    if port != 'OTA':
        host = port
    else:
        host = get_upload_host(config)

    from esphomeyaml.components import ota
    from esphomeyaml import espota2

    bin_file = os.path.join(build_path, '.pioenvs', core.NAME, 'firmware.bin')
    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOMEYAML_OTA_HOST_PORT',
                      random.randint(10000, 60000)))

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

    res = espota2.run_ota(host, remote_port, password, bin_file)
    if res == 0:
        return res
    _LOGGER.warn("OTA v2 method failed. Trying with legacy OTA...")
    return espota2.run_legacy_ota(verbose, host_port, host, remote_port,
                                  password, bin_file)
Example #5
0
def upload_program(config, args, port):
    _LOGGER.info("Uploading binary...")
    build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])

    # if upload is to a serial port use platformio, otherwise assume ota
    serial_port = port.startswith('/') or port.startswith('COM')
    if port != 'OTA' and serial_port:
        if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266 and args.use_esptoolpy:
            return upload_using_esptool(config, port)
        command = [
            'platformio', 'run', '-d', build_path, '-t', 'upload',
            '--upload-port', port
        ]
        if args.verbose:
            command.append('-v')
        return run_platformio(*command)

    if 'ota' not in config:
        _LOGGER.error(
            "No serial port found and OTA not enabled. Can't upload!")
        return -1

    # If hostname/ip is explicitly provided as upload-port argument, use this instead of zeroconf
    # hostname. This is to support use cases where zeroconf (hostname.local) does not work.
    if port != 'OTA':
        host = port
    else:
        host = get_upload_host(config)

    from esphomeyaml.components import ota
    from esphomeyaml import espota

    bin_file = os.path.join(build_path, '.pioenvs', core.NAME, 'firmware.bin')
    if args.host_port is not None:
        host_port = args.host_port
    else:
        host_port = int(
            os.getenv('ESPHOMEYAML_OTA_HOST_PORT',
                      random.randint(10000, 60000)))
    espota_args = [
        'espota.py', '--debug', '--progress', '-i', host, '-p',
        str(ota.get_port(config)), '-f', bin_file, '-a',
        ota.get_auth(config), '-P',
        str(host_port)
    ]
    if args.verbose:
        espota_args.append('-d')
    return espota.main(espota_args)