HomeHome AutomationIs it worth hacking Sonoff basic?

Is it worth hacking Sonoff basic?

To hack Sonoff Basic or not to hack!?

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

Latest Sonoff R3 series

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:

PROSCONS
Enable HTTP, MQTT, and other protocolsRequire programming knowledge
Utilise additional exposed pinsAndroid/iOS app support is not there
Reduce “talk home”Poor coding practices can increase security risks
Can function better offlineWarranty
Better cooperation with other devicesOff 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

BE AWARE: Sonoff device backup will only work with the specific unit. Currently, there is no way of sharing the backup file between the devices. Make sure that you create the backup file for each Sonoff device you own.

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.

Sonoff BasicFTDI
3.3V3.3V
TXRX
RXTX
GNDGND

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.

Buy FT232RL Serial adapter

Buy it using these links to support NotEnoughTech.

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.

Flashing Tasmota - the old way

To be able to hack the relay, you will need several downloads:

  1. Python 2.7
  2. pip installer
  3. pyserial
  4. esptool

Start with the installation of the Python 2.7 (New installer has option to include PATH – use it). Once it’s installed, open Windows 10 system settings  (Win key then search for Advanced System Settings) then navigate to Environmental Variables, find Path and edit. Add a new line:

C:\Python27

This will save you a lot of trouble.

Download the pip installer and place it in a folder (not desktop). Hold right Shift and right-click within that folder to bring up the cmd/PowerShell window in the current directory. Then run:

python.exe get-pip.py

Now that we have the latest pip, it’s time for the pyserial. Download the tar.gz file and unpack it to a folder. Open the folder and a new cmd/PowerShell window inside it then run:

python setup.py install

Now you are ready to play with esptool software. Download the tool and unpack it to a folder. Bring up the cmd/PowerShell in that location.

Hacking Sonoff – backup

Connect the Sonoff device and power it up while holding the built-in button for 2-3 sec. You will be able to make changes to the bootloader now. Your first action should be a backup. Check the COM port connected via device manager.

BACKUP

python esptool.py --port COM5 read_flash 0x00000 0x100000 image1M.bin

Once the backup is done, you will notice a new file present in the folder. It’s the image1M.bin (or whatever you named it). This is your recovery file. Keep it safe. If you delete the file, you won’t be able to restore the original firmware.

ERASE

python esptool.py --port COM5 erase_flash

If you want to delete the firmware completely and prepare it for the custom software.

RESTORE

python esptool.py --port COM5 write_flash -fs 1MB -fm dout 0x0 image1M.bin

You can restore or flash a custom software. Just place the file in the same folder as the esptool.py file.

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:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

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.

AFE Firmware

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.

Features:

  • HTTP support
  • MQTT 
  • 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.

Tasmota

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.

Features

  • 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.

Shop with Sonoff

Take a look at the ZigBee and WiFi range of the devices compatible with eWeLink:

Conclusion

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!

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Smart Home

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?

Sonoff for households and gardens

0
ITEAD released two ZigBee devices to manage water in your household and gardens. Now you can monitor the flow and dispense water with Sonoff SWV and prevent water damage using the Sonoff Water Leak sensor with a twist.