Backup, restore and deletion of a firmware Sonoff (and similar)

4 minutes of reading
PURPOSES OF THE GUIDE:
  • Perform a backup, restore and / or deletion of the firmware present on a Sonoff (or on equivalent devices however based on SOC ESP8266)
  • Difficulty level: bass
CONCEPTS FACED:
  • firmware interfacing
Software components used:
Physical devices used:
GUIDE MOST INDICATED FOR:

All environments

Notes and disclaimer
  • qualsiasi eventuale modifica agli impianti domestici dev'essere progettata ed realizzata SOLO da personale qualificato;
  • any changes implemented in probefore is a propersonal responsibility as well as a profirst risk and danger (the contents of the present page are purely educational);
  • any changes implemented in proprior to a device it voids the guarantee, quality approvals and certifications.
Driving review: 1.3

Abstract

- As it is known the actuators / sensors of the family ITEAD "Sonoff Smart Home” are among the most popular home automation components, thanks to the low cost, the big one versatility and, last but certainly not least (indeed), the high degree of integration home automation.

This last aspect is directly linked to the possibility to modify the sign in use from their processor, the SOC ESP8266, replacing the factory one with an alternative one, such as Sonoff-Tasmota, Espurna and others.

This guide it's satellite of those dedicated, in inDomus, to the riprogrammation of this firmware:

Since it may be necessary to carry out a firmware backup (specially the original one from the factory) For promaybe see it later, upon restoration, this guide illustrates the use of the free tool "esptool”(Usable on Windows, Mac, Linux) for this purpose.

It is assumed that:

It starts

Connection

To backup, restore or delete the flash memory of the component in question it is necessary to connect to it via the USB / TTL adapter (FTDI) to the board of the Sonoff (or of the module in question).

An adapter USB / TTL (FTDI) it is a simple device that allows us to put in communication our computer is the heart of the ESP8266 based module. To do this, it is first necessary to "undress" the Sonoff removing the white plastic shell that it protegge. The adapter, which can vary in shape and colors, has a USB port and four contacts as standard which go contacted with those present on the board of Sonoff using gods Dupont connection cables.

The contacts VCC and Ground dell 'USB / TTL (FTDI) they must be connected to the same contact points of the board, while TX and RX must be cross-connected (TX with RX and RX with TX).

CAUTION: if the adapter has a choice between the 5v and 3.3v voltages, choose always 3.3v. An adapter that only delivers 5v, is not suitable.

It is usually used to weld on the board of Sonoff of the pins so to make the connection to the FTDI easy, but it is enough place simple contact pins to get the same result - see image above.

WARNING! DO NOT CONNECT TO THE SIMULTANEOUSLY SONOFF TO THE USB / TTL ADAPTER AND TO THE NETWORK CURRENT 220V!
REMEMBER TO DISCONNECT THE MAINS CURRENT FROM THE DEVICE !!!

A further, last alternative without welding is that of "fresh laundry", available here.
Other connection techniques can be read here.

Flash mode

Once connected it is possible to connect the adapter to the computer, but in doing so it is necessary, at the same time, to connect the pin on the board named "GPIO0" to the "Ground" pin and, after making the USB connection, disconnect this "short" between the two pin. This causes the module to enter a mode called "flash mode“, Which gives free access to the module's firmware.

To do this, for example, on a Sonoff Basic as on other models (TH-16, POW ...), it is sufficient (upstream to make the USB connection) to press the button on the board (to then release it after the USB connection has been made); in other cases it is instead necessary to use a additional Dupont connection cable (male-male) to bring the two specific pins into contact. The thing varies from model to model, it is enough to refer to the specific guide of riprodevice firmware to understand how to do it.

Correct sequence:

  • I certify the four contacts VCC, Ground, TX and RX;
  • I press the button or put in contact GPIO0-Ground with a Dupont cable (chosen based on the type of module)
  • I connect the USB;
  • I wait a second, then release the button or remove the Dupont cable.

In this way the form will go into "flash mode".

COM port

After making the connection, go at the control panel of the proyour computer (according to prooperating system) and, at the USB list, to understand which port has been assigned to the USB / TTL.

Su Windows usually these ports are called "COM1", "COM2" etc., while on linu they are called "/ Dev / ttyUSB0","/ Dev / ttyUSB1" etc.

NOTE for users Apple: Atom, su macOS, could identify a different port from the classic COMx. To understand how to configure the door in this series, refer to to this thread. Beyond what is expressed in the link, always remember to install the correct driver for Mac of profirst USB / TLL adapter.

BACKUP

We are finally proNTI to backup the module, which is connected to the computer in "flash mode", I know the port and can therefore execute, from terminal /procommand mpt, the following command:

esptool.py --port COMx read_flash 0x00000 0x100000 sonoff.bin

where obviously COMx is the communication port e sonoff. Bin the name of the file that will contain the saved firmware.

If all goes well, the output will be similar to the following:

esptool - backup

At the end a file named as command will have been created (in the case of the image, “test.bin“).

RESTORE (Flash)

Having already a previous backup available (or anyway of a compiled made ad hoc), the "restore" command, that is restore, or flash (to be always performed after connecting the module in "flash mode"), it will be the following:

esptool.py --port COMx write_flash -fs 1MB -fm dout 0x0 sonoff.bin

where is it "sonoff. Bin”Will be the name of the backup file previously created.
The output will look like this:

esptool - restore

ERASE

Finally it might be useful to "clean" the module's flash memory. To carry out a total cancellation, execute the following command:

esptool.py --port COMx erase_flash

Who prowill produce an output of this type:

esptool - erase


ITEAD Sonoff BasicATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Sonoff (and more generally to devices ESP8266), for any doubt, question, information on the specific merit of these components.