Sonoff smart IoT switch

Hackable smart switch

It’s been quite a while since I last wrote anything here, mostly because there have not been much of interest for this blog to write about – until now!

I recently discovered a small IoT device that is basically a connected high voltage smart switch; the Sonoff from Itead. Admittedly, I have been a bit slow to discover this product, which is now more than a year old, but my focus has been away from the electronics and IoT areas for some time now.

The Sonoff is a smart switch, which can be used to turn an appliance, such as a lamp, on and off. It basically sits between the wall plug and the appliance and functions as any other switch, except it can also be controlled over WiFi.

What really sets the Sonoff apart from other smart switches is that it is based on the popular ESP8266 WiFi SoC and has the FTDI pins exposed for programming, which is ideal for publishing your own firmware for the device.

It comes preloaded with a standard firmware from Itead, which connects to their own cloud based smart hub, eWeLink, and it has a lot of useful features, including timers for automatically turning on and off the Sonoff at specified times.

However, if you are not interested in exposing your smart devices to the Internet you can take advantage of the exposed FTDI interface and upload your own firmware as described over at Theo Arends’ Git WiKi, which is one of many possible replacement firmwares for the Sonoff.

The new firmware can be uploaded using the Arduino IDE. This requires soldering in some pins for the exposed FTDI interface and using a 3.3v FTDI programmer to connect to the Sonoff from a computer. The picture below shows how the FTDI pins are broken out on the Sonoff.

Sonoff FTDI connection
Sonoff FTDI connection

The firmware from Theo Arends converts the Sonoff into an MQTT wonder with all imaginable features anyone could ask for.

Besides supporting MQTT with secure connections, it exposes a web interface in which you can configure the settings for MQTT, WiFi and other features. It also contains a log of events in case something unexpected should happen and you want to investigate.

The Sonoff has a physical button, which can be used for various operations, depending on the firmware. Naturally, it can be used to toggle the switch (which goes with any firmware, I suppose), but it can be programmed to do much more than that.

Thanks to the support for the MQTT retain flag in Theo Arends’ firmware the Sonoff itself, along with any devices you may have set up to control the switch over MQTT will always be up to date with the current state of the Sonoff switch.

In practice, the retain flag tells the MQTT broker to store (retain) the message and, when other devices subscribe to the same MQTT topic, the broker will send a message to them with the current state (message) of the topic. This allows the subscribed devices to update their interfaces accordingly.

Other resources

There are a lot of resources out there regarding both the Itead smart home products and the ESP8266 SoC. I will not list all of them here, but mention a few that I find highly valuable.

Peter Scargill has a blog with a lot of interesting stuff about the Sonoff and other devices from Itead. For general interest in IoT devices and how to integrate them into something useful the blog is a must read.

One of the greatest resources for the ESP8266 SoC is the Everything esp8266 community forum.

Another great resource for the ESP8266 in general is ESP8266 Projects, which both contains presentations of projects created by community members and resources about using the ESP8266.

What else?

Itead has a lot of other ESP8266 based devices, including various versions of the Sonoff along with other more specialised devices and development boards. Theo Arends’ firmware supports most, if not all, of these devices, so the possibilities in easy and cheap home automation using IoT has become a lot easier and more attractive. Go check out the Smart Home section of the Itead web site for these wonders.

0 comments on “Hackable smart switchAdd yours →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: