Update: November 22, 2017
Updating to Sonoff-Tasmota by Theo Arends has come around a lot faster than projected for three reasons. First, a package from ITEAD containing some Sonoff Basic and POW switches arrived and, of course, the firmware on these has to be replaced if they are to be used with Domoticz. Second, I was eager to try out the "experimental" method of uploading the new firmware that does not involve soldering a header. Third, Andreas Spiess posted a YouTube video informing us that a new revision of the ESP8266 SDK preventing a key reinstallation attack (KRACK) is available.
I did manage to use SonOTA by Mirko Vogt to update the firmware of an unmodified Sonoff Basic switch using the original OTA upgrade mechanism provided by the ITEAD firmware. Very nice: there was no need to solder a header on the board and no need for a serial programmer. However, I failed when I tried to do the same with a Sonoff POW switch. This was probably because of a false move on my part. I tried to do cut and paste from the terminal window using CtrlC (old habits!) and thus interrupted the process. I could not recover from that situation and had to solder a header and upload the firmware in the usual method. I plan on using this OTA approach again and may report on it in the future.
Table of Contents
- Updating the ESP8266 Arduino Core
- Prerequisites for Sonoff-Tasmota
- I copied two files,
/home/michel/.arduino15/packages/esp8266/hardware/esp8266/2.4.0-rc2/. Of course, your home directory will probably not be
/home/michelbut something like
/home/your_name_or_something. And the hidden directory
/home/michel/.arduino15is where the binary Arduino files are stored. They could be somewhere else, especially if you installed the IDE for use by everyone on the computer. Note that I took care to save the original files under different names; you never know.
- I did not copy
/home/michel/.arduino15/packages/esp8266/hardware/esp8266/2.4.0-rc2/tools/sdk/ld/. The original
eagle.flash.1m0.ldended with the line
INCLUDE "../ld/eagle.app.v6.common.ld"which existed (I suppose it could have been written as INCLUDE "eagle.app.v6.common.ld") whereas the link in the Tasmota directory,
INCLUDE "esp8266.flash.common.ld"pointed to a non-existing file.
- The library
pubsubclientwas already installed and the define MQTT_MAX_PACKET_SIZE was already set to 512 (bytes) so there was nothing more that needed doing.
- I did install version 5.8.3 of the
ArduinoJsonlibrary via the library manager in the Arduino IDE (
Sketch/Include Library/Manage Libraries...).
- As I do not use them, I did not install the
- Updating Sonoff Switches
- I started the Arduino IDE.
- Then I opened the project:
/home/michel/Arduino/Sonoff-Tasmota/sonoff/sonoff.inoIn the IDE click on the
Filemenu and then choose
- Next, I selected the
user_config.htab. There are many files in the project, it may be easier to click on the down arrow at the right edge of the tabs. Then select the file in the drop-down list.
- I made sure that USE_WS2812 USE_DS18x20 USE_IR_REMOTE are commented out.
For example, I changed
//MD #define USE_IR_REMOTE.
- Then, in the
Toolsmenu of the IDE, I selected the correct board (generic), flash mode (
DOUT), flash size (
1M (no SPIFFS))upload speed (
115200) and port. Other options were acceptable.
- I compiled the sketch by pressing the keyboard combination
CtrlR. Or the menu can be
- Without closing the Arduino IDE, I checked that there was a newly
sonoff.bin.inofile in a directory called
xxxxxxwill be different for each distinct build. That is the file that needs to be flashed or uploaded OTA to each device.
- I used FileZilla to copy the file to the appropriate directory on the Raspberry Pi hosting my home automation system and I logged onto each device running Theo Arends firmware and updated its firmware. All this is explained in the previous post Over the Air Sonoff Flashing.
- Updating Sonoff Switches with Local Controls
- Click on the in the main menu (left panel above).
- Click on in the configuration menu (centre panel above).
- Set the GMIO14 Sensor to
09 Switch 1.
- Click on the button. Once the device restarts, the lamp will follow the state of the push button, which is not what is wanted. The push button should toggle the lamp on or off just as does the tactile button on the Sonoff does.
- Concluding Remarks
On October 16, 2017 Espressif released patches to counter the Key Reinstallation Attack (KRACK) vulnerability of the WPA2 WiFi security protocol. And it appears that on October 30, 2017, Ivan Grokhotkov (Igrr) incorporated these changes in the latest release candidate for version 2.4.0 of the ESP8266 Arduino Core Release. On the 31st, it seemed like a good time to update the ESP8266 Arduino Core in the Arduino IDE.
Since I was using the latest stable version of the Core, I had to
add an additional URL to the list of
Board Manager URLS.
Read the docssite for release candidate 2. I decided to keep the older URL also. Note that the instructions still give the URL for the stable 2.3 version; the URL for the release candidate is
https://github.com/esp8266/Arduino/releases/download/2.4.0-rc2/package_esp8266com_index.jsonAs the instructions say, add the new URL and then put a comma to separate it from the old one.
If you press on the button to the right of the text box, it will be easier to add URLs, one per line (no separating comma) as seen on the following screen shot.
The next step is to go to the boards manager:
esp in the filter box to quickly find
by the ESP8266 Community. As can be seen, version 2.3.0 was installed. The
the Update and Remove buttons
are made visible by clicking on the entry. I elected to remove this older
and, after, to install the newest version
Presumably, one could have chosen to update to the newer version; I am not sure what would be the difference.
To use the patched version of the Espressif SDK in a deployed device, its sketch would need to be recompiled with the new version of the ESP8266 Arduino Core and the binary file would have to be uploaded to the device. I only have one device running my own code and I will soon do that. In the meantime, I decided to switch to Theo Arends latest version of his replacement Sonoff firmware for the Sonoff Basic switches I have around the house.
It is important to note that the WiFi router as well as all devices connected to it must also be updated to remove the KRACK vulnerability. If you are in a similar situation to mine that will not be easy. We have older Android tablets and telephones with older versions of the OS that are not being updated. Some of the manufacturers have gone out of business some time ago.
Friends and acquaintances sometimes come with their own devices and we have in the past given them the password to our WiFi network. It will be impossible to control if they have updated their devices in the future. As a precaution, I changed the SSID and password of our wireless network and activated a guest network using the old SSID. That way, our guests will still be able to log on, in a way that is similar to logging on to public WiFi networks. As a result it will be simple matter to change the password on a regular basis and guests will no longer have access to our main network.
As for the router, it is rented from an ISP and I will have to hope that it will go about updating the firmware in a timely fashion.
The first step is to get the project from GitHub.
This time around, I used
git to create a clone in the
Arduino directory where I store sketches.
Instead, you can download a zip file and extract it to a separate directory in your Arduino sketch directory.
Sonoff-Tasmota requires more "tweaking" of the Arduino IDE and some libraries than the older Sonoff-MQTT-OTA-Arduino. I more or less followed the instructions contained in the Prerequisites page of the Wiki.
user_config.h in the Sonoff-Tasmota
sketch needs to be edited and then the sketch can be compiled and uploaded
to the Sonoff devices.
For most of the Sonoff Basic switches around home, that was all that was needed. The new version picked up the old configuration and everything worked as before. There were two exceptions.
Espressif suggests to choose the fastest option for flash_mode that works with your device. This is certainly possible when updating a device with a serial link. However, it is probably not a good idea when flashing over the air. It may very well force retrieval of the device to connect it with a serial cable to a desktop computer to revive a DOUT mode device that was flashed in DIO, QIO or other access mode.
It looks like I will now have some switches that can handle DOUT flash access mode only and older devices that use both DIO and DOUT modes. Since I do not want to keep records about which switch is in which mode, I decided to use DOUT mode for all the switches. Memory access is slower, but it has not resulted in noticeable difference in performance, probably because slow flash memory is paged into fast RAM memory.
Two bedside lamps are plugged into Sonoff switches and are also locally controlled with four push buttons set up as parallel pairs connected to GPIO 14 on the fifth header pin of the Sonoff. This was all explained in Local Control of Sonoff Switches. Sonoff-Tasmota did not pick up the correct settings for these switches.
The mode of the button connected to GPIO 14 needs to be changed. I could not find a way of doing this in the module configuration page, but it can be done in the console.
Return to the main menu and select
Enter command box enter
switchmode 3 and press the Enter
button. The result will be as shown above on the right. That is all that is
required. Of course I had to repeat the steps described in this section for the
other bedside lamp.
As I mentioned in the introduction, updating to Sonoff-Tasmota is really very simple if Sonoff-MQTT-OTA-Arduino is already functioning properly. This can be done over the air, without disturbing the devices in a short time. For most basic Sonoff switches, that is all that will be needed. Some relatively simple adjustments may have to be done for more complicated situation as explained in the last section.
Sonoff-Tasmota represents a nice evolution in Theo Arends project to create a one size fits all firmware for Sonoff devices. I was able to load exactly the same sketch on a POW switch and again the final settings of the parameters was done with the Web interface on the switch.