Please note that this post applies to other Sonoff devices. I just checked it with Sonoff TH16. I didn’t want to change the title of this post to not mess the permalink.
This is a quick guide to installing the alternative firmware on the Sonoff Touch using only the WiFi. No soldering is required, just a laptop with a wireless adapter. I wanted to reflash this device for two reasons - to connect it to the OpenHAB via MQTT and to get rid of Itead closed source cloud enabled software. All steps below were carried out on a Ubuntu 17.10 although I am pretty sure they should also be working fine on a Ubuntu 16.04.
Preparing the tools
Start by installing the PIP and the development libraries for Python 3
$ sudo apt install python3-pip python3-dev
After that you need to get the latest PIP which is not bundled with Ubuntu. You could do it either via the virtualenv or just on your account. I went with the second option
$ python3 -m pip install --upgrade pip
After that you can clone the SonOTA repository
$ git clone https://github.com/mirko/SonOTA.git
Before you start flashing you need to make sure that you don’t have any firewall rules on INPUT that could cause trouble. If using ufw you need to check if it is off
$ sudo ufw status Status: inactive
… or iptables policy needs to be ACCEPT and no reject/drop rules should be in place
$ sudo iptables -L INPUT Chain INPUT (policy ACCEPT) target prot opt source destination
When the environment is set up you can go into SonOTA directory and start the process:
$ cd SonOTA ; ./sonota.py
It will ask you about the IP address you wanted to use. Make sure it is the one on the interface connected to the same WiFi that Sonoff will be using. Also type in SSID name and the password. It would look like this (please bear in mind your IP will be different)
Current IPs: ['192.168.77.19'] Select IP address of the WiFi interface: 0: 192.168.77.19 Select IP address : WiFi SSID: YourWifiSSID WiFi Password: YourWifiPassword Using the following configuration: Server IP Address: 192.168.77.19 WiFi SSID: YourWifiSSID WiFi Password: ************ Platform: linux ** Now connect via WiFi to your Sonoff device. ** Please change into the ITEAD WiFi network (ITEAD-100001XXXX). The default password is 12345678. To reset the Sonoff to defaults, press the button for 7 seconds and the light will start flashing rapidly. ** This application should be kept running and will wait until connected to the Sonoff...
At this point you need to look for a WiFi network name staring with ITEAD- and followed by some numbers. Unfortunately this wasn’t the case for me. That network wasn’t showing up at all. So I had to reset the whole device by touching the button on the Sonoff and waiting for about 7 seconds (until it started to flash its LED rapidly). After that the network showed up and I was able to connect to it with a password 12345678.
Being connected to that network you will see some more diagnostic messages until it shows the notice about “FinalStage” network, looking like this
*** IMPORTANT! *** ** AFTER the first download is COMPLETE, with in a minute or so you should connect to the new SSID "FinalStage" to finish the process. ** ONLY disconnect when the new "FinalStage" SSID is visible as an available WiFi network.
At this point you need to look for a network with a SSID “FinalStage” and connect to it. After a while it will continue with diagnostic messages (I edited them for brevitiy)
This server should automatically be allocated the IP address: 192.168.4.2. If you have successfully connected to "FinalStage" and this is not the IP Address you were allocated, please ensure no other device has connected, and reboot your Sonoff. .........................Current IPs:  .Sending file: /ota/image_arduino.bin .Current IPs: ['192.168.4.2'] The "FinalStage" SSID will disappear when the device has been fully flashed and image_arduino.bin has been installed. If there is no "Sending file: /ota/image_arduino.bin" log entry, ensure all firewalls have been COMPLETELY disabled on your system. ........200 GET /ota/image_arduino.bin (192.168.4.1) 17943.19ms
After a while the “FinalStage” network will disconnect you and dissappear. It means it has flashed completly and you need to look for a WiFi name starting with sonoff- followed by 4 digits. After connecting to it you need to point your browser at http://192.168.4.1/ and finish the setup. This step is required because the Sonoff won’t remember the settings you provided at the beggining of the whole process.