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)
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)