Posted on 8 Comments

#35: Sonoff BasicZBR3: Zigbee, not WiFi!

Every single Sonoff model has used the Espressif ESP8266 / ESP8285 processor – until now.

But now ITEAD has gone in a different direction, and released the Sonoff BasicZBR3 which drops WiFi entirely in favour of Zigbee. It doesn’t even use an Espressif processor: instead it uses a Texas Instruments CC2530, which is based on the 40-year-old Intel 8051 processor architecture.

What is Zigbee, and how does it compare to WiFi? Is the Sonoff BasicZBR3 any good?

Let’s find out!

Resources

Zigbee basics

Zigbee is a wireless communications system that’s similar to WiFi in some ways, but they are optimised for very different purposes. They both use the 2.4GHz unlicensed ISM band, and they’re both based on standards managed by the IEEE: 802.11 for WiFi, 802.15.4 for Zigbee.

WiFi is optimised for devices with plenty of power available, and that also require very high throughput. It provides bandwidth in the region of hundreds of Mbps. Perfect for laptops, smartphones, tablets, and security cameras.

Zigbee is optimised for devices that need to run at extremely low power for a long time, and that don’t need to transfer much data. It provides bandwidth of 250kbps, so only about 1/1000th as much as WiFi. It’s suited to tiny devices that need to run on a coin cell for several years, and only pass small amounts of data. Great for temperature sensors and similar IoT devices that only need to send tiny amounts of data every few minutes.

Star topology vs mesh topology

WiFi uses a star topology, with each client device connecting directly to an access point. All communication is arbitrated through the access points, and end devices don’t talk to each other directly. The access points are linked together using some sort of backhaul, usually wired Ethernet. With this topology, you need enough access points to provide coverage of the entire area where you will be deploying devices:

Zigbee is much more flexible in its topology. It can be operated as a simple star just like WiFi, but it can also operate as a mesh because some Zigbee devices can act as relays to extend the coverage of the network:

There are three types of Zigbee device.

Zigbee End Devices (ZED) are nodes that only connect to one other device. They can enter a deep sleep mode to go offline when they aren’t sending data, so they can typically operate for 2 years or more from a tiny coin cell. Typical ZEDs include temperature sensors, light switches, and motion detectors. There can be many ZEDs in a typical Zigbee network.

Zigbee Routers (ZR) are nodes that don’t go into sleep mode. They stay awake continually, ready to pass on messages between other Zigbee devices. They are also functional devices in their own right: they include smart power plugs and light globes, because these typically have mains power available and can remain operating indefinitely. They don’t need to go into sleep mode to conserve a battery. With a few ZRs spread across your coverage area, your network can provide connections for many ZEDs.

Zigbee Coordinators (ZC) are the most important type of node. There can only ever be one ZC in each network. It always takes the first network address, and then it assigns addresses to all the other devices in the network as they join. You can think of it as being like the DHCP server in a typical LAN. Usually the ZC will also act as a gateway to other types of network, such as connecting your Zigbee network onto your WiFi network or wired LAN. Many home automation hubs can act as a ZC.

Pairing with Alexa

The Sonoff BasicZBR3 is wired up the same way as other Sonoff models, with active and neutral coming in on the input side on the left, and then going out to the load (such as a lamp) on the right. Follow the instructions provided by ITEAD and the guides in my previous videos to make the connections.

Once the BasicZBR3 is installed, turn on the power. It will begin in pairing mode, ready to join an existing Zigbee network. Startup is very fast, and it will be ready within a second or so.

You will need a home automation hub that can operate as a Zigbee Coordinator, such as an Amazon Echo Plus.

With the BasicZBR3 turned on and in pairing mode, and within range of your Echo, say “Alexa, discover devices.”

Your Echo will tell you that it is looking for new devices, and the BasicZBR3 will flash its output when it is discovered. The Echo will wait for some time in case there are devices that are slow to respond, so you will have to wait a minute before it will report back that it has found your new device.

That’s it, you’re done! You can now control the BasicZBR3 using commands such as “Alexa, turn on the first plug.”

Customisation of the node names can be done through the Alexa app.

CC2530 processor connections

Programming the CC2530 requires power to the device, plus DD (Debug Data), DC (Debug Clock), and Reset.

In the BasicZBR3, the output relay is controlled by I/O pin P0_7, and it reads the tactile switch using pin P1_3:

The BasicZBR3 provides the debug connections for the CC2530 in a handy 5-pin header, so if you want to mess around with the firmware and load your own code into it, these are the connections on the PCB:

If you write any custom firmware for the Sonoff BasicZBR3, please join the forum or Discord server and share your results.

Posted on 16 Comments

#34: Science or sorcery? Sonoff T4EU1C no-neutral wifi touch switch

The new Sonoff T4EU1C no-neutral touch switch seems to defy the laws of physics. It works with just a live wire, and doesn’t need a neutral wire.

How can that possibly work? And can we install Tasmota on it?

Let’s find out.

Resources

No-neutral power connections

Traditional house wiring has an active and a neutral that meander around the ceiling to each light location, with the neutral connected directly to the light. The active comes down through the wall to the light switch, and then the output from the switch goes back up the wall to the active side of the light fitting.

This works well with passive switches, but most smart light switches need a neutral connection to power their own electronics. With only the active wiring going to the light switch, it can be very difficult to replace existing switches with smart switches.

Building codes in many countries now require that all light switches must have a neutral connection, but this is a recent change so most existing houses don’t have a neutral wire at the switches.

Smart light switches that are designed to be installed in place of existing switches and don’t require a neutral connection are generally called “no-neutral” switches.

Sonoff T4EU1C

The Sonoff T4EU1C is a no-neutral smart light switch with WiFi, so it only needs the active-in and active-out connections that are already found at most light switch locations. It operates by drawing a small amount of power through the light even when the light is turned off, so that it can run its own electronics.

The T4EU1C consists of two PCBs joined together by an 8-way header. The top PCB is the low-voltage logic board, which includes the processor, WiFi antenna, 3.3V voltage regulator, touch sensor pad and driver IC, and the programming header:

The bottom PCB is the high-voltage mains board, which includes a 12V-output mains power supply, and a relay and Triac for controlling the active output to the load:

Re-flashing the firmware with Tasmota

WARNING: There are problems running Tasmota on this particular model. It worked for me, but many other people have problems with the touch switch even when Tasmota is installed correctly. The rest of the Sonoff operates properly and it can be controlled by WiFi, but the touch sensor doesn’t work. There are a few people collaborating right now to figure out why this happens. If you’re feeling lucky, you can give it a try. However, it’s possible that you won’t be able to use the touch sensor until this problem is solved. There is ongoing discussion about it on the SuperHouse Discord server so please join in.

Just like all other Sonoff models so far, the firmware on the T4EU1C can be replaced with alternative open-source firmware to add new features such as local-network operation, MQTT, etc.

However, out of all the Sonoff models that have been released this is perhaps the most difficult one to re-flash. It can be done if you have the equipment and ability to make soldered connections to very tiny parts on the PCB, and this particular board also seems to have some strange requirements to force it into bootloader mode.

The common process for putting a Sonoff into bootloader mode is to hold the GPIO0 pin low (ie: to GND) while powering-up the board. In my testing, I found that this would result in the Sonoff appearing to accept the upload of the new firmware, but a strange checksum error would occur in the flash memory and it wouldn’t boot properly afterwards.

The process that I’ve found to work requires making a connection to the RESET pin as well as GPIO0, so that it can be put into bootloader mode after it has already been powered-up and connected to the programming adapter.

Programming connections

Re-flashing the firmware on the T4EU1C requires the usual connections to the programming header found on the logic board as shown in the picture above, plus connections to GPIO0 and RESET to force it into bootloader mode. Connection to the programming header is easy, because it’s exposed on the logic board in the same format as almost all other Sonoff models.

The difficulty is gaining access to GPIO0 and RESET, because neither of these lines are brought out onto pads for easy connections.

The most convenient place to make a connection to GPIO0 is the very thin track that runs diagonally on the top side of the logic board. Use a scalpel to carefully scrape away some of the green solder mask along the track. Be very careful that you don’t cut the track, and don’t scrape away the solder mask from the surrounding copper areas. If you do, it will be much harder to connect a wire to the track without causing a short circuit to the surrounding copper.

RESET is even harder. The only place it is exposed is on the end of a tiny resistor labelled “R3”, with a very small gap to an adjacent resistor. The connection must be made very carefully and quickly. If the resistor is allowed to heat up for more than about one second, the solder on the other end will also melt, and the resistor will move.

To control the GPIO0 and RESET pins, I soldered a pair of momentary buttons together and connected 3 lengths of very thin wire-wrap wire to them:

  • The common (blue) wire is soldered to GND on the logic board.
  • One switched wire (yellow, in my example) is soldered to the GPIO0 track after scraping off the soldermask.
  • One switched wire (red, in my example) is soldered to the RESET line by attaching it to the bottom end of the resistor marked R3.

Be extremely careful when making these connections to the PCB. It’s very easy to damage the tracks or the parts, and if you don’t have the necessary equipment and skill to rework the board you may destroy your Sonoff.

Programming header connections

Use a USB-to-Serial adapter and jumper wires to connect the Sonoff to your computer. Make sure the USB-to-Serial adapter supports 3.3V mode, because the ESP8285 can be damaged if you connect 5V to it. The connections are the same as explained in previous videos:

In this case the power switch doesn’t matter, because we will use GPIO0 and the RESET line to force the Sonoff into bootloader mode.

The connections can be made with loose jumper wire, or you can use my Sonoff Programming Adapter which does the same thing.

Tasmota upload

The T4EU1C has the same pin assignments as a Sonoff Basic, so download the generic pre-compiled Tasmota binary.

Install the “Esptool” program, and open a terminal in the same directory as the Tasmota binary.

With the Sonoff connected to your computer as described above, and the buttons ready to assert GPIO0 and RESET, run Esptool as below:

esptool.py -p /dev/tty.SLAB_USBtoUART write_flash -fm dout 0x0 sonoff.bin

You may need to adjust the serial port address to match your computer.

Immediately after you press “enter”, follow this sequence:

  1. Press and hold both buttons that you have attached to the Sonoff.
  2. Wait about 2 seconds.
  3. Release the RESET button.
  4. Wait about 2 seconds.
  5. Release the GPIO0 button.

You should see Esptool immediately identify the processor on the Sonoff and begin uploading Tasmota. This entire process will take about 30 seconds. You should see output similar to this:

 esptool.py v2.6
 Serial port /dev/tty.SLAB_USBtoUART
 Connecting…….._
 Detecting chip type… ESP8266
 Chip is ESP8285
 Features: WiFi, Embedded Flash
 MAC: 2c:f4:32:a8:18:8b
 Uploading stub…
 Running stub…
 Stub running…
 Configuring flash size…
 Auto-detected Flash size: 1MB
 Compressed 515872 bytes to 355877…
 Wrote 515872 bytes (355877 compressed) at 0x00000000 in 31.3 seconds (effective 131.7 kbit/s)…
 Hash of data verified.
 Leaving…
 Hard resetting via RTS pin…

At the end of the upload, Esptool will report 100% completion and say that it is resetting the board. However, it can’t actually reset the board because it doesn’t have any connection to the RESET line. You can press the reset button yourself, or disconnect the Sonoff from the programmer and re-connect it to cycle the power.

The Sonoff will then begin the normal Tasmota setup process, creating a WiFi network and opening a serial connection through the programming header. Follow the usual steps as shown in the Tasmota documentation to set it up, selecting “Sonoff Basic” as the module type.

The T4EU1C should then behave as expected, with control using the touch sensor on the front panel and also via WiFi.

ESP8266 / ESP8285 boot messages

If the ESP8285 didn’t enter bootloader mode properly, the Tasmota upload may have appeared to work in the previous step but the Sonoff still won’t boot. Esptool can show its normal upload progress, ending with the message saying it is 100% complete and resetting the board. But then when you power cycle or reset the board, it never comes online and you can’t tell why.

While booting, the ESP8285 outputs debug information to the programming header at the unusual baud rate of 74880bps. Most serial terminal programs can’t operate at that speed, because it’s not a standard baud rate.

The “CoolTerm” serial console is available for Mac, Linux, and Windows, and can be configured to support 74880bps.

Download and install CoolTerm following the instructions on its site.

After it has been installed, find where the binary is located on your computer. On a Mac, it’s typically inside the “/Applications” directory.

In that same directory, make a text file called “baudrates.ini” and put in the number “74880” without quotes or any other characters. Save the file, then start up CoolTerm.

You should now find 74880bps listed as a supported baud rate in the “Options” menu.

Select 74880 as the baud rate, select the serial port for your programming adapter, and click “OK”:

Click the “Connect” button to open the connection to your Sonoff, and then press the reset button on the Sonoff to force it to reboot.

If the ESP8285 has failed to boot, it will display an error similar to this:

ets Jan 8 2013,rst cause:1, boot mode:(3,0)
load 0x40100000, len 27144, room 16
tail 8
chksum 0xef
load 0x00000000, len 0, room 0
tail 0
chksum 0xef
load 0x00000000, len 0, room 8
tail 0
chksum 0xef
csum 0xef
csum err
ets_main.c

It will then hang, and won’t proceed any further.

If you see this message, there is an error with the program stored in flash memory and you should try following the steps above to flash the Sonoff again.

Posted on 35 Comments

#33: Sonoff Mini and S55: ALMOST perfect

The new Sonoff Mini DIY and Sonoff S55 are (so far) the best Sonoff devices that ITEAD has made. Flash them with Tasmota, and they get even better.

Resources

Background

The original Sonoff Basic didn’t have any provision for an external button or switch. One of the most common hacks is to add a switch, so ITEAD decided to make it easy and put screw terminals right there on the Mini.

The Mini is also the smallest Sonoff model so far, which makes it ideal for retrofitting behind an existing switch. Combined with the screw terminals to connect the switch, the Mini is probably the best general-purpose Sonoff for anyone wanting to retrofit home automation to an existing home.

The S55 is an exterior-rated GPO (General Purpose Outlet) or power point. It allows you to have both local control of the power point using a button, and also control from your home automation system.

Both are nice devices, but they become even better when the amazing Open Source Tasmota firmware is installed on them.

Over the years there have been many methods developed to do OTA (Over The Air) replacement of the existing Sonoff firmware with an alternative such as Tasmota. However, I’ve found that these methods are either frustratingly complex or just stop working because ITEAD change things with new releases. I don’t even bother trying these methods anymore: I just go straight to connecting a USB-to-Serial adapter to the programming pins on the Sonoff’s processor. It can be tricky to get the connections sometimes, but it’s guaranteed to work every time single time.

Warning: Do not attempt to connect a programming adapter to any Sonoff model while mains power is connected. ALWAYS disconnect the Sonoff and power it ONLY through the 3.3V connection.

Install Tasmota on Sonoff Mini

The programming connections for the Sonoff Mini are provided on tiny flat pads on the bottom of the PCB:

The button on the top of the PCB is connected to GPIO0, so if you connect to GND, 3.3V, TX, and RX, you can put the Sonoff Mini into programming mode by holding down the button while connecting power from the programmer.

Unfortunately the pads on the PCB are very small, so soldering jumper wires onto them is tricky. If you have a small soldering iron and good eyesight (or magnification) you can solder wires directly onto the pads.

Just be careful you don’t apply too much heat, because the pads can come away from the PCB!

To get around that problem I used my 3D printer to make a programming jig using a design published on Thingiverse. This programming jig uses “pogo pins”, which are spring-loaded pins that can make temporary connections to a PCB. Pogo pins come in a variety of sizes and shapes. I used P75-B1 pins, which means they have a 0.75mm diameter pin with a simple conical point:

This design has 3 parts: a base that holds 4 pogo pins, a small spacer that slips over the pins to help keep them aligned, and a top that goes over the pins and then provides alignment guides for the Sonoff Mini.

I used super-glue to attach the top to the base, once I’d checked everything was aligned:

The Sonoff Mini can be attached using an elastic band:

The pogo pins push against the pads on the PCB:

Hold down the button on the PCB while plugging in the programming adapter to force the Sonoff to go into programming mode, then you can use Esptool or whatever other method you prefer to load the Tasmota binary. In my case I used Esptool, and the command looked like this:

esptool.py -p /dev/tty.usbmodem141101 write_flash -fm dout 0x0 sonoff-6_6_0.bin

However, this command is specific to the USB port that I used on my computer. You may need to adjust the command to suit your needs. This is all documented well on the Tasmota site.

Because the Sonoff Mini has different pin arrangements to a normal Sonoff Basic, and it’s designed to use a normal switch instead of a button, you need to load a special configuration for it.

After you’ve been through the normal Tasmota setup process and connected it to your WiFi as described in the Tasmota docs, go to the Tasmota templates site at blakadder.github.io/templates/ and search for “Mini”. You’ll find a template that looks like this:

{"NAME":"Sonoff Mini","GPIO":[17,0,0,0,9,0,0,0,21,56,0,0,255],"FLAG":0,"BASE":1}

In the Tasmota interface, go to Configuration -> Configure Other and paste the template into the “Template” field.

Make sure the “Activate” check-box is ON, then click “Save”.

Your Sonoff Mini will now operate as expected, with the external switch operating in the normal way.

Install Tasmota on Sonoff S55

The Sonoff S55 doesn’t have a “DIY mode” jumper, so that’s not an option. Luckily, the usual programming header is provided on the PCB ready for you to solder on wires, solder on a header, or just press connections against it. The button for external control is linked to GPIO0, so it’s very easy to put it into programming mode.

The header is in the normal 0.1″ pitch so it’s large enough to solder on a header directly. There’s no need to use a complex pogo pin programming jig.

Solder some hookup wires directly onto the pads, or solder on a header:

I soldered a 4-way 0.1″ header socket onto the pads, with the pins bent a little sideways to make the head sit almost horizontal with the PCB. This makes it easy to plug in a Sonoff Programming Adapter, or use jumper wires to your own USB-to-serial converter.

Hold down the GPIO0 button while you connect the programming header to put it into programming mode, then follow the normal instructions for installing Tasmota. This is very well documented on the Tasmota site.

There’s no specific device profile for the S55 in Tasmota, but it uses the same pinouts as the Sonoff S26 and other mains-plug adapters. Simply select “Sonoff S2x” as the module type in the configuration interface, and it will work as expected.

Posted on 5 Comments

Vlog #64: New version of the Sonoff Programming Adapter

My original design for the Sonoff Programming Adapter had a power switch on it, but the switches turned out to be rubbish quality so I put on pin headers instead.

Now I’ve updated the design based on feedback in the forum, so they’ll have a normally-closed button in the power line and will ship with both a socket and a pin header so that you can decide which one you want to install.

The Sonoff Programming Adapter page will be updated soon with the new model.

Posted on 32 Comments

#31: Sonoff Tasmota installation and configuration

Make the Sonoff smart power controller even more awesome by installing the Tasmota open source firmware.

Tasmota adds many new features, and allows you to integrate Sonoffs into an existing home automation system without relying on external cloud services. It includes MQTT support, Belkin WeMo emulation, easy configuration using a web browser, and you don’t even need a compiler or IDE to install it.

Note: Since this video was released, the Tasmota project has changed its build process so that the binaries are now called “tasmota” instead of “sonoff”. I have edited the text instructions below to match, but screenshots and the video still refer to the old name.

Step 1: Prepare hardware for flashing

To load new firmware onto a Sonoff, you need four pieces of hardware:

  1. A compatible Sonoff model or equivalent (more than 50 devices are supported by Tasmota)
  2. A USB-to-Serial converter that can run in 3.3V mode (don’t use a 5V converter!)
  3. Jumper wires or a programming adapter to connect the USB-to-Serial converter to the Sonoff
  4. A computer with WiFi. You can use a mobile phone for the WiFi steps if you prefer.

You can make the connections using jumper wires and the instructions in my previous video, or you can use my handy little programming adapter. Both methods do exactly the same thing: my programming adapter just makes it neat and easy.

Make sure the Sonoff is totally disconnected from any mains power.

Don’t proceed unless you have done that! Connecting your computer to a Sonoff while it is connected to mains is extremely dangerous.

Details of the electrical connection are shown in the previous episode, so check that out if you need more information.

Step 2: Download Tasmota

The Tasmota firmware and its documentation is available at github.com/arendst/Sonoff-Tasmota, including both firmware and pre-compiled binary releases. If you want to compile the code yourself that’s fine, but you don’t need to if you just want the latest version. The binary releases are at:

 github.com/arendst/Sonoff-Tasmota/releases

There is a big list of binaries for each release, which can be confusing if you don’t know which one you need. The binaries fall into several categories which are outlined on the releases page.

For most devices, you should choose the binary called “tasmota.bin” which includes all the features required for the majority of compatible hardware.

The binaries with 2-letter country codes appended, such as “tasmota-IT.bin”, have the exact same functionality as the standard “tasmota.bin” but with different languages for the user interface. If you want to run Tasmota in a language other than English, select the appropriate “tasmota-XX.bin” file.

Whichever version you select, download it to your computer.

I prefer to rename the binary file so that it includes the release version, such as “tasmota-8_4_0.bin”. That way if I come back to it later, I can see what version I downloaded.

Step 3: Download and install esptool

Esptool is a utility that can be used to read and write the flash memory on devices using the ESP8266 and ESP8285 microcontrollers, including all current Sonoff models. It’s written in Python so you will need a working Python environment on your computer.

You can download esptool from github.com/espressif/esptool.

Follow the instructions on that page to install it on your computer.

Step 4: Find serial device

Your USB-to-Serial converter connects to your computer by USB, and appears to the computer as a virtual serial port. The exact location of the virtual serial port will vary depending on the type of converter that you have, what operating system you use, and which physical USB port you plug the converter into.

If you have the Arduino IDE installed, a good way to find the location of the virtual serial port is to start the IDE, look at the ports list in Tools -> Port, then plug in the converter and check the ports list again to see if a new port has appeared.

On my Mac, the port appeared at /dev/tty.usbmodem14201, so I’ll use that in the following examples.

Step 5: Put Sonoff into bootloader mode

Disconnect power from the Sonoff, hold the GPIO0 pin low, and reconnect power. Then release GPIO0. This process is explained in detail in the previous video.

This will put the Sonoff into a mode where it waits for new firmware to be loaded.

OPTIONAL Step 5b: Back up original firmware

If you want to make a backup of the original firmware so you can restore it back to factory-original later, jump to the addendum near the bottom and then return here. Otherwise, carry on!

Step 6: Upload the Tasmota firmware

Open a terminal, and go into the directory where you have the Tasmota binary. Use esptool to push it to the Sonoff using the serial port location that you found earlier:

esptool.py -p /dev/tty.usbmodem14201 write_flash -fs 1MB -fm dout 0x0 tasmota-8_4_1.bin
  • The “-p” parameter sets the serial port
  • The “write_flash” command tells esptool to send new data to the flash memory
  • The “-fs” parameter is the flash size. Put this parameter in if you know it. If you don’t, you can omit this parameter and esptool will attempt to auto-detect the flash size for you
  • The “-fm” parameter is the flash mode to use
  • The “0x0” parameter tells esptool to start writing into flash from address 0
  • The final argument is the binary image to load

Uploading the binary takes about 30 seconds.

While esptool is doing the upload it will report useful information about the hardware in your Sonoff, including the MAC address. This can be extremely useful if you want to put a DHCP static lease into your router fix your Sonoff to a specific IP address. You can copy and paste the MAC address out of the terminal and save it in a document or spreadsheet for future reference if you want to.

Step 7: Connect to Sonoff via WiFi

Disconnect the Sonoff power power, then reconnect it. When the Tasmota firmware starts up and doesn’t find any existing configuration, it goes into a setup mode and creates its own WiFi network. The network will have a name similar to “Tasmota-6392”, with the 4 digits based on the last part of the unique MAC address of the Sonoff hardware.

On your computer or smartphone, go into WiFi settings and look for a network with a name similar to this. Make a note of the network name, because you will need it in a moment!

Connect to the Sonoff’s WiFi network without any username or password. Your computer should then automatically open a captive portal, with a WiFi configuration screen for the Sonoff.

Enter the WiFi settings for your normal network into the Sonoff. You can enter them directly, or you can click the “Show wifi networks” link to have the Sonoff scan for available networks so that you can select the right one and then enter the password manually.

Enter the details, and click “Save”.

The Sonoff will then reboot and attempt to connect to your normal WiFi network.

This will cause your computer to drop off the temporary WiFi network that was created by the Sonoff, and reconnect to your normal network.

Step 8: Connect to Tasmota configuration interface

Open a web browser, and enter the address of the Sonoff using the network name that you noted in Step 7 with “.local” added to the end. For example, the address could be something like

tasmota-6392.local

This will open a configuration interface where you can view information about the device, change its settings, backup and restore the configuration, install firmware updates, and control the output.

Many of the configuration options are explained in the video. Explore the menus and set up the Sonoff to suit your home automation system.

Addendum: Reconfiguring from scratch

If your home WiFi changes or you take the Sonoff to another location, it will keep trying to connect to the network that you originally configured and you won’t be able to control it.

If this happens, you don’t need to re-flash Tasmota. Instead, you can put it into WiFi recovery mode.

Tasmota can use the button on the Sonoff to put it into special modes. If you quick-press the button 4 times, it will restart the setup process and create its own WiFi network again just like in step 7. Then you can connect to its WiFi, and give it new details so it can connect to your main WiFi network again. Your other settings will be retained so you don’t need to set them again.

If you press and hold the button for more than 40 seconds, Tasmota will clear all its settings, reboot, create a WiFi network, and begin the setup process from scratch.

Other things you can do with the button are explained at github.com/arendst/Sonoff-Tasmota/wiki/Button-usage

Addendum: Backing up and restoring original EWeLink firmware

If you want to keep the option of returning the Sonoff to factory-original condition, you can download the original firmware out of its flash memory and save it for later use. Obviously this has to be done BEFORE you flash Tasmota onto it!

Do everything up to Step 5, but DON’T continue with Step 6. Instead, use esptool to determine the flash size of the Sonoff. Using your own serial port address, run a command like this:

esptool.py -p /dev/tty.usbmodem142101 flash_id

This will give a result that looks something like this:

jon@Jonathans-MacBook-Pro:~/Downloads$ esptool.py -p /dev/tty.usbmodem142101 flash_id
esptool.py v2.6-beta1
Serial port /dev/tty.usbmodem142101
Connecting….
Detecting chip type… ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: dc:4f:22:2b:c8:63
Uploading stub…
Running stub…
Stub running…
Manufacturer: e0
Device: 4014
Detected flash size: 1MB
Hard resetting via RTS pin…

You can see the result “Detected flash size: 1MB” near the end.

The Sonoff will have reset back into normal mode, so put it back into bootloader mode in the usual way, then use a command like this to download the existing flash memory and save it in a local file:

esptool.py -p /dev/tty.usbmodem142101 read_flash 0x0 0x100000 sonoff-ewelink.bin

Pay attention to the value “0x100000” above. That example will read the flash starting at address 0, and continuing on to the 1MB point. If you have a 2MB flash, you’d use “0x200000”, for example.

On my laptop, it looks like this:

jon@Jonathans-MacBook-Pro:~/Downloads$ esptool.py -p /dev/tty.usbmodem142101 read_flash 0x0 0x100000 sonoff-ewelink.bin
esptool.py v2.6-beta1
Serial port /dev/tty.usbmodem142101
Connecting….
Detecting chip type… ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: dc:4f:22:2b:c8:63
Uploading stub…
Running stub…
Stub running…
1048576 (100 %)
1048576 (100 %)
Read 1048576 bytes at 0x0 in 94.0 seconds (89.2 kbit/s)…
Hard resetting via RTS pin…

After it’s finished, you will have the original flash memory saved on your computer in a file called “sonoff-ewelink.bin”.

Then continue with installing Tasmota.

Later, if you change your mind and want to put the original firmware back in place, you can follow the normal steps for installing Tasmota but instead use the file you saved. The command will look similar to this, but with your serial port address substituted:

esptool.py -p /dev/tty.usbmodem142101 write_flash -fm dout 0x0 sonoff-ewelink.bin
Posted on 5 Comments

#30: Reflash ANY Sonoff, even if you don’t know the pinout

Sonoff is very popular for DIY home automation, but you can make it even better by loading new firmware onto it. Learn how to connect a USB-to-Serial converter to ANY model of Sonoff, even ones that haven’t been released yet!

This episode isn’t just a series of steps to follow: it’s a tutorial on how to reverse engineer the connections to the ESP8266 / ESP8285 microcontroller in an unknown circuit, and put it into bootloader mode ready to receive new software.

ESP8266 Strapping Pins

The strapping pins set the boot mode of the microcontroller. Typical ESP8266 circuits have an arrangement similar to this:

In the Sonoff, GPIO15 is pulled low to 0V, and GPIO2 and GPIO0 are pulled high to 3.3V.

If GPIO0 is held low (0V) during startup, the ESP8266 will go into bootloader mode and be ready to receive a new program uploaded via the serial connection on the TX and RX pins.

You can often find the appropriate connections on the PCB by tracing out the pins on the microcontroller. The relevant pins on the ESP8266 and ESP8285 can be found in these locations:

With only a couple of exceptions, most Sonoff models include a 4-pin header on the PCB that exposes GND, 3.3V, TX, and RX.

You can use a USB-to-Serial converter to connect this header to your computer by USB, so that you can upload a new program. You can make an adapter cable using these connections:

It’s a simple cable to hand-wire, but that can be annoying so to save time I designed a simple adapter that you can use between a USB-to-Serial adapter that uses the common “FTDI” pinout and the Sonoff:

The adapter makes it very easy to connect to most Sonoff models. Make sure you use a USB-to-Serial adapter that runs at 3.3V because it’s not safe to connect 5V. Doing so could damage the ESP8266 microcontroller.

Sonoff Basic Pinout

More detail to be added here soon.

Sonoff POW / TH10 / TH16 Connections

More detail to be added here soon.

Sonoff 4CH Pro Connections

More detail to be added here soon.

Sonoff Slampher Connections

More detail to be added here soon.

Sonoff B1 Connections

More detail to be added here soon.

Sonoff Touch Connections

More detail to be added here soon.

Posted on 13 Comments

New product: Sonoff Programming Adapter

If you want to load new software onto a Sonoff, you can use jumper wires to link a USB-to-Serial adapter to the programming header of the Sonoff. However, it’s easy to make a mistake, and loose jumper wires can be really annoying.

This cool little programming adapter simply plugs into a common FTDI-type header, and then plugs into your Sonoff.

No more jumper wires. No more looking up the pinout every time you have to connect them!

This little adapter is going to be featured in the next episode of SuperHouse, which will show how to put any Sonoff model (even new ones that haven’t been released yet) into programming mode.

Check it out in the online store.

Sonoff Programming Adapter

Use this adapter to install new firmware onto Sonoff devices from ITEAD.

The adapter provides a common 6-pin serial header on one side for connection of a USB-to-serial converter, and a 4-pin header on the other side in the correct format to match the programming header inside many Sonoff models.

Includes controller of the power line, so the Sonoff can be power-cycled without disconnecting.

Note: Does not convert voltage, so you must use a 3.3V USB-to-Serial converter.

The current version comes with both plug and socket header types, but they’re loose so you have to select which one you want and solder it on yourself. The current version also has a button to power-cycle the Sonoff, instead of a jumper. The button is more convenient to use than the jumper on older versions.

Details of the new version:

Features

  • 6-pin header matching FTDI cable pinout (with either a socket or a pin header)
  • 4-pin header matching many Sonoff models
  • Button to allow power-cycling without disconnecting

Compatible Sonoff models include:

  • Sonoff Basic
  • Sonoff TH10 / TH16
  • Sonoff POW
  • Sonoff 4Ch Pro
  • Sonoff 4Ch Pro R2

Resources

Posted on 7 Comments

#27: Visit to the Sonoff factory and ITEAD

UPDATE: I’ve been asked by several people how they can get in touch with factories so they can go on tours. Please DON’T DO THIS unless you are serious about doing business with that company. Factories are not amusement parks, and the staff who work in them are busy doing their jobs. If you want to manufacture a product and you seriously want to do business with a factory, then it’s easy to arrange a tour. But don’t do it just because you want to have a look! That wastes their time.

ITEAD, makers of the super-popular Sonoff home automation devices, very generously allowed me to visit their head office, their factory, and their warehouse so that I could see how the Sonoff is made.

Come with me on a quick trip to China to learn a little about the amazing city of Shenzhen, see its enormous electronics markets, and go inside the Sonoff factory to watch them progress from a bare PCB to a finished product.

ITEAD: www.itead.cc

Posted on 163 Comments

#21: Six Sonoff Secrets

Customise your Sonoff home automation controllers with a memory upgrade, weatherproof housing, control switches, sensors, and custom firmware.

ITEAD keep releasing new Sonoff models so this isn’t a complete list, but some of the models mentioned in the video include:

Storage

winbond-25q32fvThe flash memory chip in Sonoffs is 8Mbit, which is only 1MByte. Then if you want to do OTA (Over The Air) updates you need to limit your program size to less than half the available memory so that a new program can be uploaded alongside the old one. And if you use a SPIFFS (SPI Flash File System) to store non-volatile data outside your program, you lose even more memory.

You can replace the flash memory chip with a Winbond 25Q32FV in SOP-8 package, which is a 32Mbit (4MByte) chip. You can buy them on eBay for about US$3 for a pack of 10.

The original flash memory on the Sonoff is a Winbond 25Q08FV, which is the 8MBit (1MByte) version of the same chip.

Thanks to Pete Scargill for this idea! You can see more on his original blog post: “32Mb ESP01 and Sonoff

Safety

Sure, you can just cut a power lead and screw it into a Sonoff, but it’s probably a bad idea. You need to consider how your Sonoff will be used, including physical protection (stop little fingers reaching the terminals!) and liquid protection from spills. You also need to make sure there is strain relief on the cables to prevent them being pulled out, and possibly exposing live mains connections. You can do it cheaply using a plastic project box, and with some cable ties around the cables just inside the box so they can’t be pulled out. The result can be a very neat setup that won’t look like a dodgy DIY cable, and should be safe for general use.

sonoff-powerboard

You can go even further and use an IP-rated (Ingress Protection) case and cable glands, to make your Sonoff waterproof and physically very strong.

sonoff-ip56-case

In this video I gave a very simple explanation of the two-digit IP codes. There are also extensions to the code for other attributes. You can find more information and tables showing the specific meaning of the numbers at en.wikipedia.org/wiki/IP_Code.

Switches

Internet control is fun, but usually you also want some way to manually turn the output on or off without using your phone. You can modify a Sonoff to connect an external button across the pins of the built-in button, allowing you to toggle the output by pressing the button manually. The built-in button is connected to GPIO0, so when the button is pressed it pulls GPIO0 to GND. This is used during power-up to put the Sonoff into bootloader mode, and can also be used to toggle the output or do other actions.

sonoff-gpio0-terminals

Alternatively, you can connect an external button between GND and GPIO14 so that your software running on the Sonoff can detect when it has been pressed. Some firmware, including Theo Arends’s TASMOTA, supports this out of the box.

GPIO14 is exposed on the internal header used to upgrade the software on a standard Sonoff. There is already a pull-up resistor on GPIO14, so you don’t need any other parts. Just connect a button across the GPIO14 and GND pins, and you’re done!

sonoff-header

Even better, TASMOTA has an option to support an external switch instead of an external button. The difference is that with a button, you want the output to change state each time you press and release the button. This means the firmware needs to treat both the button press and release (cycling from HIGH to LOW to HIGH) as a single event. But a switch just changes state (goes from HIGH to LOW, or goes from LOW to HIGH) and stays there because it latches in place. So your software needs to treat each level change as a separate event, and toggle the output. Once again, TASMOTA supports this out of the box.

Sensors

As explained in the section about switches, the regular Sonoff exposes GPIO14 on the internal header that is used for flashing new firmware. The same header also provides GND and 3.3V connections, and the GPIO14 pin is provided with a pull-up resistor. This makes it super easy to connect anything that needs a single digital pin, such as an external switch / button or a one-wire sensor.

sonoff-th-sensor-pinoutTo make it even easier, the Sonoff TH10A and TH16A both feature a 2.5mm 4-way (TRRS) socket that is intended for connecting external sensors. The socket provides 3.3V, GND, and GPIO14: the same I/O pin exposed on the internal header of a normal Sonoff. That means you don’t even need to modify the board, you can simply plug in your sensor or switch externally.

sonoff-th-with-cable-800

The 2.5mm socket also has a 4th connection, but there are parts missing inside the Sonoff so it’s left unused. You can fix this easily by putting a solder blob across two pads on the Sonoff PCB, and optionally installing a pull-up resistor.

In the video I said that there is a 10k pull-up from GPIO14 to 3.3V. However, I didn’t notice that there are actually 2 pull-ups in parallel, so the effective pull-up on GPIO14 is 5k! You can still use a 10k pull-up on GPIO4 if you like, or you can use a 4.7k resistor if you want them to be about the same. 4.7k is common for I2C, but 10k is generally fine too.

sonoff-th-bottom-breakouts

Software

There are many alternative firmware projects for the Sonoff. Personally I love Theo Arends’s firmware, but there are many others that may suit you better.

To learn about how to install new firmware, see SuperHouseTV Episode #17: Home automation control with Sonoff, Arduino, MQTT, and OpenHAB.

If you have any other suggestions please let me know in the comments below, and I’ll update this list.

Sites

Because the Sonoff uses an ESP8266 microcontroller, there are a huge number of sites with information that’s relevant to the Sonoff. These include: