Thanks to Banggood I own two Sonoff basic devices. While the original and intended use is waiting for the local Hackspace to reopen, I thought I would take a look at hacking options. The Sonoff community is strong, and there seems to be plenty of support for Sonoff devices. Is it worth hacking Sonoff? The short answer is Yes, the long answer is below.
Hacking Sonoff basic
The reason for straight-up YES is the ability to reflash the original software back on the ESP8266. This means should anything happen, you can always go back to the intended use. Here is the breakdown of Pros and Cons:
|Enable HTTP, MQTT, and other protocols||Require programming knowledge|
|Utilise additional exposed pins||Android/iOS app support is not there|
|Reduce “talk home”||Poor coding practices can increase security risks|
|Can function better offline||Warranty|
|Better cooperation with other devices||Off the shelf support with Home Assistants|
For me, the pros outweigh the cons. And for a lot of you as well as the hacking community is strong and there are plenty of examples of Sonoff devices being used in an awesome way.
Hacking Sonoff – hardware
Before you open a device like this, remember to only program it using power from the FTDI programmer. DO NOT USE MAINS to power up the chip for programming.
Guys at Sonoff has been nice enough to expose all the pins needed to flash the software. To make the job easier, I have added 5 header pins to the board so I could use jumper wires when hacking Sonoff devices.
The pinout of the Sonoff basic is as follows:
Pay attention to the board orientation to connect the correct wires between your device and FTDI converter.
Once you have the hardware ready, we have to set up the hacking environment. I will cover the setup of Windows 10 as it’s the most troublesome.
Hacking Sonoff – software
Thanks to Tasmotizer, you can flash and configure your Sonoff devices in under a minute. Follow this guide about how to back up, erase and flash your ESP device with Tasmotizer.
I kept the old way of flashing ESPs as a reference, but I would strongly suggest you give the Tasmotizer a go since it doesn’t require the painstaking setup and it works like a charm.
3rd party firmware – Tasmota and AFE Firmware
If you don’t feel like coding yourself, you can use already developed firmware by the community. My favourite options are:
Custom Software – Arduino IDE
Now that we have the image backed up, we can use the Arduino to push the custom code to the ESP8266. Make sure to add the boards to the manager by opening Arduino IDE preferences and setting the path for the manager:
Select the ESP8266 and the following Arduino IDE options:
Board: "Generic ESP8266 Module" Flash Mode: "DOUT" Flash Size: "1M (no SPIFFS) IwIP Variant: "v1.4 Higher Bandwith" Erase Flash: "Only Sketch"
Now you can put your board again into a flash mode (hold the button for 2-3sec when powering up) and flash a custom code. I will be writing a better code especially made for the Sonoff basic, but for now, feel free to interact with a web-based interface. For now, I used the code I made for DIY Smart Socket as it suits my needs for testing. You can download the modified version at the bottom of the article.
An excellent firmware, developed by Adrian and available on www.smartnydom.pl (most of the content is available also in English). AFE Firmware is best for ESP8285 and ESP8266 devices which are not made by Sonoff’s ITEAD.
- HTTP support
- Custom Pin Mappings
- OTA updates
I talked about this in detail in my ESP8285 4-way relay tutorial. If you use ESP8266, don’t worry – the principle is the same, just download the correct version for your chip.
This firmware aims to use the exposed dev pins on Sonoff devices for the purpose of adding the sensors and modules. Tasmota firmware works best with Sonoff devices as the options are tailored for each product released by ITEAD.
- MQTT support
- HTTP support (although less fun to use than AFE Firmware)
- Easy config – just pick the model from the list
- Included libraries for sensors etc
- OTA updates
There is already a tutorial about the Tasmota and sonoff devices, and you can take a look at the implementation and flash it to your device.
It’s very rewarding to hack your own Sonoff device. You learned new skills, you can integrate it with your automation systems. The biggest advantage for me is the ability to link it to any device you wish almost directly. The consumer-based systems have a very limited scope and aim to work with the most popular solutions. On top of that, 5 years down the line there is no warranty that home automation systems owned by you will still be in use and supported. Having total control over a device you own is the best!
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.