This instruction does not claim to be new. The above is quite googling (true in English), but I was looking for a long time where to start and decided to help those who take the path of communication with Sonoff.
There are a lot of reviews of Sonoff Basic on the Internet, including in Russian, there are also articles on how to connect it to local systems of “Smart Home” after reflashing.
So, if you do not have a USB-UART (have not yet come from China), and the Sonoff unit is already there and there is a Raspberry Pi, then this article is for you.
Here, if you have already tried to find information on how to flash this Chinese unit, then you realize that you can’t do without a soldering iron. First of all, you have to solder the comb to be able to connect our unit to the Raspberry Pi.

')
Next, we connect Sonoff Basic (having previously disconnected from 220V) to the Raspberry Pi, as shown in the picture (The picture, like the information, I took
here , and I quote here, respectively, a brief translation).

The first thing to do is to see if you have a ttyS0 port.
ls /dev/
If it is not there, but there is ttyAMA0 (as in the above article), then this does not mean that you are doing well (I remind you that this is Raspberry Pi 3 b +), since ttyAMA0 - responsible for bluetooth. This means that we need to enter the settings:
sudo raspi-config
and in “Interfacing Options” enable “Serial”, then reboot.
Next, perform the preparation of Raspberry:
sudo systemctl stop serial-getty@ttyS0.service sudo systemctl disable serial-getty@ttyS0.service
And edit cmdline.txt, namely delete “console = serial0,115200”:
sudo cp /boot/cmdline.txt /boot/cmdline.bak sudo nano /boot/cmdline.txt
In addition, it is advised to assign “enable_uart = 1” right below (without quotes, of course), to be honest, I don’t know what will happen if this is not done.
Next, install pip (if needed) and esptool.py:
sudo apt-get install python-pip sudo pip install esptool
Reboot Raspberry.
Downloading the firmware (I used ESPEasy build 120 as a stable release, but in general everything is also valid for other firmware):
wget http://www.letscontrolit.com/downloads/ESPEasy_R120.zip
Pre-making sure that you are in the folder in which you would like to download, and then unzip your firmware.
unzip ESPEasy_R120.zip
And should get a list of files:
ESPEasy_R120_1024.bin ESPEasy_R120_512.bin esptool.exe Source ESPEasy_R120_4096.bin ESPEasy_R120.zip flash.cmd
Next, turn off the Sonoff from 3.3V, pinch the button on the board (there is one button - do not mix it up), connect to 3.3V.
We make a backup of the firmware (and suddenly we want to come back later, and the firmware is unique for each unit).
sudo esptool.py --port /dev/ttyS0 read_flash 0x00000 0x100000 Sonoff_backup_01.bin
We disconnect Sonoff from 3.3V, we clamp the button on a payment, we connect to 3,3V. Erase memory:
sudo esptool.py --port /dev/ttyAMA0 erase_flash
We disconnect Sonoff from 3.3V, we clamp the button on a payment, we connect to 3,3V. We are stitching (we take the firmware for 1Mb, unless of course you soldered the memory of your block):
sudo esptool.py --port /dev/ttyS0 write_flash -fm dout 0x0 ESPEasy_R120_1024.bin
Well, in general, and everything, you had to flash your device.
At the initial launch of the module, the wifi network “ESP_0” will appear, the network password “configesp”. You need to connect to it, after which you will be automatically redirected to the settings page, where you need to enter information about your existing wifi network to which your sonoff should be connected as a client.
You can also configure wifi with the command:
sudo miniterm.py /dev/ttyS0 115200 -e
It is necessary to enter (not paying attention to the terminal who got mad after entering the SSID or after waiting for 3 seconds until Sonoff calms down):
ssid yourSSID password yourPassword