Riproset an ITEAD Sonoff using the DIY mode via OTA

7 minutes of reading
PURPOSES OF THE GUIDE:
  • Riproload a device ITEAD Sonoff new generation (explained in the abstract) via the DIY mode via OTA (then without physical connections and / or adapters)
  • DIFFICULTY LEVEL: variabile
CONCEPTS FACED:
  • riprofirmware grammation
Software components used:
Physical devices used:
  • the domotic component ITEAD Sonoff from riprocompatible grammar with the ITEAD DIY architecture (explained in the abstract)
  • a computer of appnow (Windows, Apple or Linux)
  • a smartphone or an access point Wi-Fi
  • jumper cap header (usually supplied with Sonoff)
GUIDE MOST INDICATED FOR:

All environments

Notes and disclaimer
  • qualsiasi modifica all'impianto elettrico dev'essere progettata ed effettuata 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.1

Abstract

Every electronic device contains broadly a small piece of softwareCalled firmware, which determines its functions and behavior. Our car is equipped with different firmware; it has one, the washing machine, our remote control, even a clock radio has a profirst firmware.

Devices based on SOC ESP8266 (a processor equipped with Wi-Fi rather in vogue for its low cost, limited size and great versatility) i'm not far behind: all mount a profirst firmware, usually written and compiled by proconductor. A classic example comes from the line devices ITEAD Sonoff "Smart Home” which, mainly, mount such processor.

Sonoff Mini
Sonoff Mini.

Using a similarity, riprogrammare (o flash) the firmware of a device it's like overwriting a whole VHS videotape. Well: the devices that mount the ESP8266 they easily lend themselves to this reproming, which, for the most part, is carried out in order to equip the components with additional (or in any case different) functionalities from the factory ones.

Is the case of alternative firmware like the Sonoff-Tasmota or l 'Espurna, free firmware written for devices based on ESP8266 (like i Sonoff, the Shells and many others): they are implemented to "free" the devices from the factory firmware and implement, apptogether, many additional features.

La procedura is usually the one you expect to connect physically to the component for prosee the riprofirmware weight; in the 2019, however, ITEAD has provided users with a defined mode DIY (do-it-yourself) which allows you to reproprogram some compatible components (for now only the latest models, i Sonoff Basic R3, Sonoff RF R3 e Sonoff Mini) without the need for physical connections.

La procedura is simple (and suitable for everyone) if you use a computer appobject based on Windows, while it is more complex e tricky for those who have a Mac or a macChina Linux. As an alternative to this procedura, remains good and old procedura by connection physics.

It starts

Description prosubsidence

Il proyielding is quite simple, but like everything else it requires a minimum of manual work; nevertheless, we will try to illustrate it in order to make it feasible for the most inexperienced user.

Phases are broadly the following:

  • download / customize and compile the target firmware;
  • connect the device toapp mobile eWeLink;
  • update the firmware;
  • turn off the device;
  • make a backup of the original firmware (optional);
  • open the device and short-circuit the OTA contacts;
  • activate an access point Wi-Fi (with very specific characteristics, which we will see later);
  • turn on the device (which will connect to the access point above);
  • connect the computer to appat the access point above;
  • throw the proreimbursement orderprofirmware grammation;
  • turn off the component, remove the connection between the two OTA contacts.

At this point the component will have of the new firmware.

firmware

Which firmware to use?
The question is broad and certainly not the subject of this guide. What is important to know is that in order to reprogrammare the Sonoff in question it is necessary to have the file available . Bin (hence the filled out) of the chosen firmware.

on choice, on how to pre-compiled firmware downloads e custom firmware compilation see the "Firmware" section of the MASTERGUIDE of riprogrammation of devices based on ESP8266 SOC.

ATTENZIONE: Using software pre-compiled Tasmota è strictly necessary use the file sonoff-basic.bin.

eWeLink

First step is to connect the component to theapp mobile eWeLink (For iOS e Android) for the unique purpose of updating the firmware. To get the paring between theapp and the component can be referenced driving the proconductor or the following video (the model in the images is the Sonoff Basic R2, But the procedura is however substantially the same even with the new models):

The purpose is that to update the component's factory firmware. To implement this guide, in fact, it is strictly necessary for the component to have a basic firmware version equal to or greater than 3.1.

Once connected to eWeLink, click in the component settings e check - and if anything update - the firmware.

After it has been updatednamento, our advice is that to backup the factory firmware, useful tomorrow we wanted to go back to the choice made of riprogrammarlo. To carry out this practice it is however necessary a USB / TTL adapter (which frustrates the meaning of this guide, but so does it). There proThe backup procedure is explained in detail in this other guide .

OTA contacts (DIY mode)

The devices Sonoff that support the DIY mode are equipped, on the board, of two contacts that, when short-circuited, they activate for theappgotten the DIY mode that allows the reproming OTA (Over-The-Air, ie without physical connection).

To do this, simply open the component, identify the contacts (they are identified by a labeled pitch "OTA“) And short-circuit them with the supplied jumper.

Sonoff Mini - OTA Contacts
An example: the "OTA" contacts in the Sonoff Mini.
ATTENTION: Carry out these operations by having always the foresight to eliminate any supply voltage from the component. Electricity is not a game: caution, ever!

Access Point Wi-Fi

At this point it is necessary that a network is present in the environment Wi-Fi with a name (SSID) and a password well specific. These coordinates, in fact, are already known to the component that when turned on in DIY mode, progoes to access it - if he is able to find that network. It is also necessary that the computer of appobject (through and thanks to which we will carry out the reproprogramming) enter the same network.

To ensure that such a network exists, more options are possibleprocci; We will list some of them:

  • use the computer of appobject (provided it has an antenna Wi-Fi) as an Access Point;
  • use the smartphone / tablet as an Access Point, provided that the computer can then connect to this network:
    • or directly through the profirst antenna Wi-Fi;
    • or through a device that acts as bridge, or that connects to the network exposed by the smartphone / tablet and, through its ethernet port, allows the computer to connect to the cable network.

The approccio easier and obviously the first: allows to create the network to which to connect the Sonoff and allows the computer to be there directly connected (as it is he who defines it).

To achieve the network we need refer to to this guide (for Window, Mac and Linux).

This network must necessarily possess the following characteristics:

  • SSID: sonoffDiy (pay attention to capital letters)
  • password: 20170618sn

Once the network is defined, turn on the component Sonoff and check (depending on the computer in use) that it is among the devices connected to the network.

Sonoff DIY - Windows 10 Mobile HotSpot
List of connected devices on Windows 10

Riproming

At this point (Sonoff powered and in DIY mode and computer connected to the network Wi-Fi specific) we are pronti for riprogramming the firmware.

Note for users Sonoff-Tasmota: beware of no use the minimal firmware, and above all to carefully choose the complete firmware to use based on the device, taking care to choose the correct one based on the device (basic for the basic, TH for the TH etc.)

Su Windows

La procedura su Windows it's the simplest. It is in fact sufficient to download the Sonoff DIY Tool from GitHub and run it.
Once running, the tool should detect the Sonoff connected to the same computer network; to select "Flash firmware"And select the file . Bin by the profirst firmware. Select the component then click on “OK". The riprogrammation will start until it is completed.

Finally jump to the conclusion was originally the proprocedure.

Su macOS and Linux

On these two operating systems the procedura, as anticipated in the abstract, is more complex.

First of all, the computer must have the tool curl and that the services of are active network discovery (Eg. mDNS for macOS o avahi-browse for Linux); secondly it is necessary that on the same network where the computer and the device are attested Sonoff is present a web server (do not SimpleHTTPServer and similar). This last element is necessary for "appobject "the firmware to use for the reproprogramming.

To start the procedura is necessary, first of all, find out the device ID from riprogramming. To do this you need to run a specific command for the profirst operating system: in the example below, we assume that the ID is 1000988699, just to understand where, in the log, go and watch:

SU MACOS
dns-sd -B _ewelink._tcp

example response log:

Browsing for _ewelink._tcp  
DATE: ---Mon 12 Aug 2019---  
20:19:31.956  ...STARTING...  
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name  
20:19:31.957  Add        2   5 local.               _ewelink._tcp.       eWeLink_1000988699
ON LINUX
avahi-browse -t _ewelink._tcp --resolve

example response log:

+ wlp3s0 IPv4 eWeLink_1000988699 _ewelink._tcp local
= wlp3s0 IPv4 eWeLink_1000988699 _ewelink._tcp local hostname = [eWeLink_1000988699.local] address = [192.168.1.109] port = [8081] txt = ["data1={"switch":"off","startup":"off","pulse":"off","pulseWidth":500,"rssi":-47}" "seq=1" "apivers=1" "type=diy_plug" "id=1000988699" "txtvers=1"]

Discovered the ID, copy the file . Bin of the firmware on the web server present on profirst network. Let's assume the file is called sonoff-basic. Bin and the web server is running on the computer ofappsame: the connection should be obtained via the following address:

http://127.0.0.1/sonoff-basic.bin

At this point we can make a first test that evokes from the component Sonoff service info (command is the same for both macOS that Linux):

curl http://deviceIP:8081/zeroconf/info -XPOST --data '{"deviceid":"deviceID","data":{} }'

where deviceIP is the IP of the component Sonoff e deviceID is the ID previously discovered.
Example response log:

{"seq":2,"error":0,"data":"{"switch":"off","startup":"off","pulse":"off","pulseWidth":500,"ssid":"sonoffDiy","otaUnlock":false}"}

If you get this answer (or similar), the communication works, so you can block the largernamento OTA using this command:

curl http://deviceIP:8081/zeroconf/ota_unlock -XPOST --data '{"deviceid":"deviceID","data":{} }'

which should answer as follows:

{"seq":2,"error":0}

Once this response is obtained, it can finally be prosee the reportprotrue grammar e proere:

curl http://deviceIP:8081/zeroconf/ota_flash -XPOST --data '{"deviceid":"deviceID","data":{"downloadUrl": "http://webServer/nomefirmware.bin", "sha256sum": "<SHAsum>"} }'

Where obviously webserver will be the address of our local web server e nomefirmware.bin the name of our firmware hosted by it.

If you get the following answer:

{"seq":2,"error":0}

the riprogrammation will be gone successful.

Conclusion

At this point it is necessary to switch off the Sonoff, remove the jumper on the OTA contacts, then reassemble it and turn it back on.
Obviously the behavior will be linked to the firmware that will be mounted: in case of a Sonoff-Tasmota precompiled you will need to press the button on the button five times Sonoff to reset it, let it expose the profirst AP Wi-Fi, connect and configure it; if instead you will be provveduto to preconfigure the profirst configuration file and compile it (then using the compiled for riprogrammare), certainly the Sonoff will enter alone in the profirst network Wi-Fi and it will be possible to start using it immediately.


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.


Please comment below