Skip to content

Instantly share code, notes, and snippets.

@gmacario
Last active June 28, 2021 10:45
Show Gist options
  • Save gmacario/bb2467a94b73f3c3ae04af4b2f1e25b3 to your computer and use it in GitHub Desktop.
Save gmacario/bb2467a94b73f3c3ae04af4b2f1e25b3 to your computer and use it in GitHub Desktop.

Update firmware on Sonoff TH10

Reference: https://tasmota.github.io/docs/Esptool/#upload-tasmota

(2021-04-17 09:51 CEST)

Prerequisites

Make sure the Sonoff TH10 has no connections on its headers

Open the Sonofff TH10 WiFi Smart Switch and install 4x (5x) 2.54 mm pin headers on the PCB

Install esptool on laptop

pip install esptool

Install old PL2303 drivers for Windows 10 - see http://wp.brodzinski.net/2014/10/01/fake-pl2303-how-to-install/ (USB adapter contains a fake PL2303 chip)

Connect the GND/TX/RX/3.3V on the Sonoff to the corresponding pin on the USB-to-TTL dongle

⚠️ Remember to swap RX and TX pins!

Hold the button on Sonoff while inserting USB-to-TTL adapter into one empty USB port of laptop, then release it

Check on Device Manager the assigned port (in our case, COM5)

Print esptool help

Command: esptool.py -h

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py
esptool.py v3.0
usage: esptool [-h] [--chip {auto,esp8266,esp32,esp32s2,esp32s3beta2,esp32c3}] [--port PORT] [--baud BAUD]
               [--before {default_reset,no_reset,no_reset_no_sync}] [--after {hard_reset,soft_reset,no_reset}] [--no-stub] [--trace]
               [--override-vddsdio [{1.8V,1.9V,OFF}]] [--connect-attempts CONNECT_ATTEMPTS]
               {load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_id,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,version,get_security_info}
               ...

esptool.py v3.0 - ESP8266 ROM Bootloader Utility

positional arguments:
  {load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_id,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,version,get_security_info}
                        Run esptool {command} -h for additional help
    load_ram            Download an image to RAM and execute
    dump_mem            Dump arbitrary memory to disk
    read_mem            Read arbitrary memory location
    write_mem           Read-modify-write to arbitrary memory location
    write_flash         Write a binary blob to flash
    run                 Run application code in flash
    image_info          Dump headers from an application image
    make_image          Create an application image from binary files
    elf2image           Create an application image from ELF file
    read_mac            Read MAC address from OTP ROM
    chip_id             Read Chip ID from OTP ROM
    flash_id            Read SPI flash manufacturer and device ID
    read_flash_status   Read SPI flash status register
    write_flash_status  Write SPI flash status register
    read_flash          Read SPI flash content
    verify_flash        Verify a binary blob against flash
    erase_flash         Perform Chip Erase on SPI flash
    erase_region        Erase a region of the flash
    version             Print esptool version
    get_security_info   Get some security-related data

optional arguments:
  -h, --help            show this help message and exit
  --chip {auto,esp8266,esp32,esp32s2,esp32s3beta2,esp32c3}, -c {auto,esp8266,esp32,esp32s2,esp32s3beta2,esp32c3}
                        Target chip type
  --port PORT, -p PORT  Serial port device
  --baud BAUD, -b BAUD  Serial port baud rate used when flashing/reading
  --before {default_reset,no_reset,no_reset_no_sync}
                        What to do before connecting to the chip
  --after {hard_reset,soft_reset,no_reset}, -a {hard_reset,soft_reset,no_reset}
                        What to do after esptool.py is finished
  --no-stub             Disable launching the flasher stub, only talk to ROM bootloader. Some features will not be available.
  --trace, -t           Enable trace-level output of esptool.py interactions.
  --override-vddsdio [{1.8V,1.9V,OFF}]
                        Override ESP32 VDDSDIO internal voltage regulator (use with care)
  --connect-attempts CONNECT_ATTEMPTS
                        Number of attempts to connect, negative or 0 for infinite. Default: 7.

gmaca@alpha MINGW64 ~/Downloads
$

Read Chip ID from OTP ROM

Ensure the device is in firmware upload mode.

Command: esptool.py chip_id

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py --port COM5 chip_id
esptool.py v3.0
Serial port COM5
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:52:e5:70
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x0052e570
Hard resetting via RTS pin...

gmaca@alpha MINGW64 ~/Downloads
$

Read MAC address from OTP ROM

Ensure the device is in firmware upload mode.

Command: esptool.py [--port PORT] read_mac

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py read_mac
esptool.py v3.0
Found 3 serial ports
Serial port COM5    
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:52:e5:70
Uploading stub...
Running stub...
Stub running...
MAC: cc:50:e3:52:e5:70
Hard resetting via RTS pin...

gmaca@alpha MINGW64 ~/Downloads
$

Get security info (--> Fail)

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py get_security_info
esptool.py v3.0
Found 3 serial ports
Serial port COM5    
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:52:e5:70
Uploading stub...
Running stub...
Stub running...

A fatal error occurred: Failed to get security info (result was FF00)

gmaca@alpha MINGW64 ~/Downloads
$

Backup firmware in flash

Ensure the device is in firmware upload mode.

Backup the current firmware with the following command:

esptool.py --port COM5 read_flash 0x00000 0x100000 image1M.bin

Result --> FAIL

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py --port COM5 read_flash 0x00000 0x100000 image1M.bin
esptool.py v3.0
Serial port COM5
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:52:e5:70
Uploading stub...
Running stub...
Stub running...

A fatal error occurred: Corrupt data, expected 0x1000 bytes but received 0xfff bytes

gmaca@alpha MINGW64 ~/Downloads
$

NOTE: This was probably due to a faulty USB-to-TTL adapter

Erase firmware

Ensure the device is in firmware upload mode.

Erase the complete flash memory holding the firmware with the following command:

esptool.py --port COM5 erase_flash

Result --> OK

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py --port COM5 erase_flash
esptool.py v3.0
Serial port COM5
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:52:e5:70
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.2s
Hard resetting via RTS pin...

gmaca@alpha MINGW64 ~/Downloads
$

Upload firmware

Ensure the device is in firmware upload mode.

Download the latest tasmota firmware

Load the downloaded Tasmota firmware file tasmota.bin with the following command:

esptool.py --port COM5 write_flash -fs 1MB -fm dout 0x0 tasmota.bin

Result --> OK

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py --port COM5 write_flash -fs 1MB -fm dout 0x0 tasmota.bin
esptool.py v3.0
Serial port COM5
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:52:e5:70
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Compressed 607712 bytes to 434475...
Wrote 607712 bytes (434475 compressed) at 0x00000000 in 42.1 seconds (effective 115.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

gmaca@alpha MINGW64 ~/Downloads
$

Troubleshooting

If the esptool.py command fails when connecting

gmaca@alpha MINGW64 ~/Downloads
$ esptool.py --port COM5 read_mac
esptool.py v3.0
Serial port COM5
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

gmaca@alpha MINGW64 ~/Downloads
$

then put the Sonoff in firmware upload mode by powering it on while the button is pressed.

Connect

Once the firmware has been updated, disconnect and reconnect the USB-to-TTL dongle

Watch serial console 115200:8n1

If you can't see anything on the serial console, reboot the device pressing the button on Sonoff

Scan WiFi network and search for SSID tasmota_xxxxx

Connect and browse http://_ip-address/

Configure WiFi to connect to the home router

Wait until device restarts

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v3969889e
@cp:0
     ld

00:00:00.045 CFG: Loaded from flash at FB, Count 32
00:00:00.205 QPC: Reset
00:00:00.212 Project tasmota Tasmota Version 9.3.1(tasmota)-2_7_4_9(2021-03-09T16:12:28)
00:00:00.850 WIF: Connecting to AP1 gmhome2 Channel 9 BSSId 04:F0:21:23:2C:AF in mode 11n as tasmota_52E570-1392...
00:00:01.753 WIF: Connected
00:00:02.005 HTP: Web server active on tasmota_52E570-1392 with IP address 192.168.64.132
13:20:20.456 RSL: tele/tasmota_52E570/INFO1 = {"Module":"Sonoff TH","Version":"9.3.1(tasmota)","FallbackTopic":"cmnd/DVES_52E570_fb/","GroupTopic":"cmnd/tasmotas/"}
13:20:20.462 RSL: tele/tasmota_52E570/INFO2 = {"WebServerMode":"Admin","Hostname":"tasmota_52E570-1392","IPAddress":"192.168.64.132"}
13:20:20.473 RSL: tele/tasmota_52E570/INFO3 = {"RestartReason":"Software/System restart"}
13:20:20.481 RSL: stat/tasmota_52E570/RESULT = {"POWER":"ON"}
13:20:20.487 RSL: stat/tasmota_52E570/POWER = ON
13:20:25.405 RSL: tele/tasmota_52E570/STATE = {"Time":"2021-04-17T13:20:25","Uptime":"0T00:00:10","UptimeSec":10,"Heap":29,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"POWER":"ON","Wifi":{"AP":1,"SSId":"gmhome2","BSSId":"04:F0:21:23:2C:AF","Channel":9,"RSSI":74,"Signal":-63,"LinkCount":1,"Downtime":"0T00:00:03"}}

Sonoff TH Module

Tasmota

ON

  • Toggle
  • Configuration
  • Information
  • Firmware Upgrade
  • Console
  • Restart

Tap on "Console"

See Also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment