uni.horse / flashing esphome to an esp32 device with a glasgow interface explorer

You've probably found this page because you want to do this very specific thing, you tried it the obvious way, and it didn't work because esphome doesn't work with the pty created by glasgow uart.

Get a 3.3V power supply. In my experience the Glasgow can provide enough current to flash successfully, but it'll immediately get stuck in a brownout reset loop as soon as you try to boot it, so you may as well go do that now. It's easier if you can toggle power independently of the data lines.

Connect:

As a test, run:

$ glasgow run uart -V 3.3 -a tty
and turn the power on. You should see (probably a lot of line noise, but also) output like:
rst:0x1 (POWERON_RESET),boot:0x1 (DOWNLOAD_BOOT(UART0/UART1/SDIO_FEI_REO_V2))
waiting for download
Type ~. to exit.

Get your esphome config and build a binary:

$ esphome compile house-electricity-meter-left.esphome.yaml

Tell esphome to flash it to /dev/null. This will fail, obviously, but it'll produce useful output in the process.

$ esphome upload house-electricity-meter-left.esphome.yaml --device /dev/null
[...]
esptool v5.1.0
Serial port /dev/null:
ERROR Running command failed: Could not open /dev/null, the port is busy or doesn't exist.
(Could not configure port: (25, 'Inappropriate ioctl for device'))

ERROR Please try running esptool --before default-reset --after hard-reset --baud 115200 --port /dev/null --chip esp32 write-flash [...] locally.
WARNING Failed to upload to ['/dev/null']

Start the UART thing in TCP socket mode:

$ glasgow run uart -V 3.3 -b 115200 socket tcp:127.0.0.1:4000
I: g.hardware.device: device already has bitstream ID 48b537efd9ecb61575f69936f8ea5736
I: g.hardware.assembly: port A voltage set to 3.3 V
I: g.hardware.assembly: port B voltage set to 3.3 V
I: g.cli: running handler for applet 'uart'
I: g.applet.interface.uart: socket: listening at tcp:127.0.0.1:4000

With the power off, take the command esphome said to please try running earlier in its error message, and change /dev/null to socket://127.0.0.1:4000:

$ esptool --before default-reset --after hard-reset --baud 115200 --port socket://127.0.0.1:4000 --chip esp32 write-flash [...]

Turn the power on immediately after starting this, while esptool says it's trying to connect, so that it sees the bootloader starting. It should then carry on with flashing.

Kill the Glasgow client and restart it in TTY mode:

$ glasgow run uart -V 3.3 -a tty

Turn the power off, remove the IO0 wire, then turn it back on again. At this point you should see esphome log messages on the serial console.

Once you see it connecting successfully, you can remove the rest of the wires and flash future changes as OTA updates.