How to use the esptool.main function in esptool

To help you get started, we’ve selected a few esptool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github espressif / esptool / flasher_stub / esptool_test_stub.py View on Github external
# Foundation; either version 2 of the License, or (at your option) any later version.
#
import os.path
import sys

THIS_DIR=os.path.dirname(sys.argv[0])

sys.path.append("..")
import esptool
# Python hackiness: evaluate the snippet in the context of the esptool module, so it
# edits the esptool's global variables
exec(open("%s/build/stub_flasher_snippet.py" % THIS_DIR).read(), esptool.__dict__, esptool.__dict__)

if __name__ == "__main__":
    try:
        esptool.main()
    except esptool.FatalError as e:
        print('\nA fatal error occurred: %s' % e)
        sys.exit(2)
github project-alice-assistant / ProjectAlice / core / device / DeviceManager.py View on Github external
self._broadcastFlag.clear()
			return

		self.MqttManager.say(text=self.TalkManager.randomTalk('usbDeviceFound', skill='AliceCore'), client=siteId)
		try:
			mac = ESPLoader.detect_chip(port=port, baud=115200).read_mac()
			mac = ':'.join([f'{x:02x}' for x in mac])
			cmd = [
				'--port', port,
				'--baud','115200',
				'--after', 'no_reset', 'write_flash',
				'--flash_mode', 'dout', '0x00000', 'sonoff.bin',
				'--erase-all'
			]

			esptool.main(cmd)
		except Exception as e:
			self.logError(f'Something went wrong flashing esp device: {e}')
			self.MqttManager.say(text=self.TalkManager.randomTalk('espFailed', skill='AliceCore'), client=siteId)
			self._broadcastFlag.clear()
			return

		self.logInfo('Tasmota flash done')
		self.MqttManager.say(text=self.TalkManager.randomTalk('espFlashedUnplugReplug', skill='AliceCore'), client=siteId)
		found = self.findUSBPort(timeout = 60)
		if found:
			self.MqttManager.say(text=self.TalkManager.randomTalk('espFoundReadyForConf', skill='AliceCore'), client=siteId)
			time.sleep(10)
			uid = self._getFreeUID(mac)
			tasmotaConfigs = TasmotaConfigs(deviceType=espType, uid=uid)
			confs = tasmotaConfigs.getBacklogConfigs(room)
			if not confs:
github esp8266 / Arduino / tools / upload.py View on Github external
cmdline = cmdline + ['write_flash']
if len(write_option):
    cmdline = cmdline + [write_option]
cmdline = cmdline + [write_addr, binary]

erase_file = ''
if len(erase_addr):
    # Generate temporary empty (0xff) file
    eraser = tempfile.mkstemp()
    erase_file = eraser[1]
    os.write(eraser[0], bytearray([255] * int(erase_len, 0)))
    os.close(eraser[0])
    cmdline = cmdline + [ erase_addr, erase_file ]

esptool.main(cmdline)

if len(erase_file):
    os.remove(erase_file)
github marcelstoer / nodemcu-pyflasher / Main.py View on Github external
if not self._config.port.startswith(__auto_select__):
                command.append("--port")
                command.append(self._config.port)

            command.extend(["--baud", str(self._config.baud),
                            "--after", "no_reset",
                            "write_flash",
                            "--flash_mode", self._config.mode,
                            "0x00000", self._config.firmware_path])

            if self._config.erase_before_flash:
                command.append("--erase-all")

            print("Command: esptool.py %s\n" % " ".join(command))

            esptool.main(command)

            # The last line printed by esptool is "Staying in bootloader." -> some indication that the process is
            # done is needed
            print("\nFirmware successfully flashed. Unplug/replug or reset device \nto switch back to normal boot "
                  "mode.")
        except SerialException as e:
            self._parent.report_error(e.strerror)
            raise e
github cnlohr / swadge2019 / piflash / pyFlashGui / pyFlashGui.py View on Github external
# target function of the thread class
        import esptool
        import time
        # Spin forever
        while True:
            # Actually stop if we're told to stop
            if(self.stopped()):
                return

            # Draw the label
            self.label.config(text="Attempting flash on " +
                              self.name, bg="gray")

            # Try to flash the firmware
            try:
                esptool.main(["-b", "2000000", "--port", self.name, "write_flash", "-fm", "dio", "0x00000", "image.elf-0x00000.bin", "0x10000",
                              "image.elf-0x10000.bin", "0x1FB000", "blank.bin", "0x1FC000", "esp_init_data_default_v08.bin", "0x1FE000", "blank.bin"])
                # It worked! Display a nice green message
                self.label.config(
                    text="Flash succeeded on " + self.name, bg="green")
                time.sleep(4)
            except:
                # It failed, just wait a second a try again
                time.sleep(1)