mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Switch to 115200 baud upload if 460800 fails (#856)
* Switch to 115200 baud upload if 460800 fails * Update __main__.py
This commit is contained in:
		| @@ -165,16 +165,27 @@ def compile_program(args, config): | |||||||
|  |  | ||||||
| def upload_using_esptool(config, port): | def upload_using_esptool(config, port): | ||||||
|     path = CORE.firmware_bin |     path = CORE.firmware_bin | ||||||
|     cmd = ['esptool.py', '--before', 'default_reset', '--after', 'hard_reset', |     first_baudrate = config[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS].get('upload_speed', 460800) | ||||||
|            '--baud', str(config[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS].get('upload_speed', 460800)), |  | ||||||
|            '--chip', 'esp8266', '--port', port, 'write_flash', '0x0', path] |  | ||||||
|  |  | ||||||
|     if os.environ.get('ESPHOME_USE_SUBPROCESS') is None: |     def run_esptool(baud_rate): | ||||||
|         import esptool |         cmd = ['esptool.py', '--before', 'default_reset', '--after', 'hard_reset', | ||||||
|         # pylint: disable=protected-access |                '--baud', str(baud_rate), | ||||||
|         return run_external_command(esptool._main, *cmd) |                '--chip', 'esp8266', '--port', port, 'write_flash', '0x0', path] | ||||||
|  |  | ||||||
|     return run_external_process(*cmd) |         if os.environ.get('ESPHOME_USE_SUBPROCESS') is None: | ||||||
|  |             import esptool | ||||||
|  |             # pylint: disable=protected-access | ||||||
|  |             return run_external_command(esptool._main, *cmd) | ||||||
|  |  | ||||||
|  |         return run_external_process(*cmd) | ||||||
|  |  | ||||||
|  |     rc = run_esptool(first_baudrate) | ||||||
|  |     if rc == 0 or first_baudrate == 115200: | ||||||
|  |         return rc | ||||||
|  |     # Try with 115200 baud rate, with some serial chips the faster baud rates do not work well | ||||||
|  |     _LOGGER.info("Upload with baud rate %s failed. Trying again with baud rate 115200.", | ||||||
|  |                  first_baudrate) | ||||||
|  |     return run_esptool(115200) | ||||||
|  |  | ||||||
|  |  | ||||||
| def upload_program(config, args, host): | def upload_program(config, args, host): | ||||||
|   | |||||||
| @@ -184,6 +184,7 @@ def run_external_command(func, *cmd, **kwargs): | |||||||
|     except Exception as err:  # pylint: disable=broad-except |     except Exception as err:  # pylint: disable=broad-except | ||||||
|         _LOGGER.error(u"Running command failed: %s", err) |         _LOGGER.error(u"Running command failed: %s", err) | ||||||
|         _LOGGER.error(u"Please try running %s locally.", full_cmd) |         _LOGGER.error(u"Please try running %s locally.", full_cmd) | ||||||
|  |         return 1 | ||||||
|     finally: |     finally: | ||||||
|         sys.argv = orig_argv |         sys.argv = orig_argv | ||||||
|         sys.exit = orig_exit |         sys.exit = orig_exit | ||||||
| @@ -216,6 +217,7 @@ def run_external_process(*cmd, **kwargs): | |||||||
|     except Exception as err:  # pylint: disable=broad-except |     except Exception as err:  # pylint: disable=broad-except | ||||||
|         _LOGGER.error(u"Running command failed: %s", err) |         _LOGGER.error(u"Running command failed: %s", err) | ||||||
|         _LOGGER.error(u"Please try running %s locally.", full_cmd) |         _LOGGER.error(u"Please try running %s locally.", full_cmd) | ||||||
|  |         return 1 | ||||||
|     finally: |     finally: | ||||||
|         if capture_stdout: |         if capture_stdout: | ||||||
|             # pylint: disable=lost-exception |             # pylint: disable=lost-exception | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user