No-Phone Sonoff stuff…

Sonoff with 3v3 USB programming adapter attachedI’m still quite enamoured of the Sonoff, from ITEAD Studios, despite the fact that I can’t get their eWelink to work with a tablet (the app refuses to register you unless you have a phone number — which my tablet doesn’t have, of course — and the excellent suggestion from Jon Chandler in the support forum, “use Oogleg Voice” may well work, but only for ‘merkins living in merika).  Sniffle.  I really shouldn’t be surprised, though; previous experience has shown that anything connected to female sheep usually leaves me with a cold, wet arm or a body to bury (occasionally both).

Anyway, playing around with the unmodified device showed it as coming up on an IP address of and happily assigning my laptop, but that’s as far as I got. All attempts to connect to it from the laptop failed miserably and I was also unable to get the Android “Smartconfig” app to do anything with it (if you’ve had success with any other method of getting the Sonoff to work with an Android tablet, please do leave a note in the comments section below).

So, I disconnected the wee beastie, ripped it apart and set about adding some pins to the existing programming header. A couple of warnings are in order here before I go any further, though:-

  • Your warranty is null and void if you start screwing around with your hardware (but you knew that already, right!?!)
  • You need to switch the unit off, unplug it from the mains and remove any cables connected to it before you start work (hopefully you knew that, too …if you didn’t, give yourself a sharp rap across the knuckles with wooden ruler and stop reading this right now!).
  • You should let the unit stand for half an hour or so to let the capacitors on the mains side of the PSU discharge before taking the top off.
  • DO NOT under any circumstances, touch any part of the PCB or component with a finger, soldering iron or USB-to-TTL adapter until all of the above instructions have been complied with.

ITEAD Studios have designed the board of the Sonoff with a socket for a programming header.

ITEAD Studios' Sonoff, with no clothes onAs it ships on the current version that header is unpopulated (this is ITEAD Studios telling you and me not to mess with their board …which is very sound advice).

The available schematic and the board itself don’t quite match up.  The schematic shows this as a five-pin header, but the PCB very obviously only has four holes.  What are we going to be connecting?  Well, we need pins for ground, receive data, transmit data and +3v3.  We need the latter simply because we do not want to attempt connecting another device (PC/Laptop/UFO-anti-gravity-generator, or whatever) to something which is already connected to the mains (do NOT do that!   I mean it!).  At any rate, four pins is all we need and four pins is what we’ve got.  We also need something that I’d been missing for a while …a 3v3 compatible USB<->TTL adapter (I finally gave in and ordered a couple a while back).

Adding the pins is fairly straightforward, but you should note that the ground pin is the one closest to the camera in the shot above, not the one with the squared-off hole.  The squared-off hole is the 3v3 connection.  Close-up shot of the unpopulated programming headerIf in doubt, get your meter out and test.  Before you put the pin header in place it’s also fairly easy to see the “star” connections from the ground connector to the ground plane around it.  The pin on the opposite end of the connector (next to the “J1” label and the big switch) is the 3v3 connector.

The long row of holes across the bottom of the picture is the connector for the 433MHz remote control board which is fitted to the Sonoff “RF” models, but missing on the base model.

With the pin headers in place, it’s not very easy to see either the silk-screen around pin 1 or the “J1” label, so it might be a good idea to label the ground pin using something like an indelible marker Programming socket populated with pinspen so that you’ll know which way round to connect the USB<->TTL converter leads the next time you take the top off.

Now that we have the header pins in place, we need some firmware to burn to the ESP8266 on the board.  I’d like to point you towards Theo Arends’ Sonoff-MQTT-OTA-Arduino package on GitHub.  It’s a drop in replacement which has a very versatile interface, allowing control of the relay, as well as status reporting and some configuration, from both MQTT and from the Arduino-IDE serial console window.  In addition, the button on the Sonoff will also provide manual control of the relay, start SmartConfig mode, start OTA update mode and force a reset to defaults, depending upon how many presses or how long you hold it down.  Changes to the relay state triggered by the button also automatically generate an MQTT state-change message, so your application should always be able to track state of external switch events.  Neat!  Theo also maintains a non-Arduino version if any of you masochists out there prefer fiddling with the SDK.

To update your Sonoff, make sure that no mains cables are attached, plug your 3v3 USB<->TTL converter cables onto the newly installed header pins (+3v3 to the pin next to the switch, ground to the pin next to the row of holes for the 433MHz module) and then hold down the switch button while plugging the USB connector into your computer.  Burn Theo’s firmware to the board using whichever method you are familiar with.

Note that the USB converters don’t usually supply enough current to run the ESP8266 when it fires up the radio (and it definitely won’t supply enough current to power the relay coil), so don’t be surprised if you see a couple of start-up messages followed by a crash or watchdog reset; just disconnect your USB cable and put the unit back together again (including all of the covers), before applying mains power.  Once it’s all back in one piece and powered on, you can check basic functionality by pressing the button.  A single press should produce an audible click from the Sonoff as the relay toggles state, followed by two brief flashes of the LED.  If you have “mosquitto_sub” available (or one of the Android MQTT monitor apps), you can fire it up and monitor the topic “stat/#” to see output from your newly updated Sonoff (assuming that you set up your own MQTT server details in the firmware defaults).  The mosquitto_sub command would be:-

mosquitto_sub -h Your.MQTT.Server -t sub/#

Use mosquitto_pub to publish an MQTT message to the cmnd/sonoff topic to have your Sonoff toggle the state of the relay:-

mosquitto_pub -h Your.MQTT.Server -t cmnd/sonoff/power -m "toggle"

Hopefully you’re now in business and your Sonoff is happily clicking away as you play with MQTT.

Update –  If you’re having trouble compiling Theo’s package (CFG_Default not defined, etc), I’ve put together a very slightly modified package with the function prototypes broken out into separate header files which should compile cleanly for most people.  It also has a minor pre-processor tweak which will reset the MQTT_MAX_PACKET_SIZE and MQTT_KEEPALIVE values to Theo’s recommended settings of 1024 and 120, without the need to modify the original PubSub library file.

Next …the next article in this series is a tutorial on using Theo’s new firmware.


11 thoughts on “No-Phone Sonoff stuff…

  1. Hi PB,
    I’ve just got into the whole ESP ecosystem due to the Sonoff after finding your blog while looking for MQTT stuff. I do however have a slight problem, using your software and also Theo’s. I’ve added the ESP build set up to my existing Aruduino IDE (and built it again from scratch on Ubuntu Linux and then again on Windows 10 just to check). The IDE seems to work OK as I compile/upload the ESP blink sketch and that works and also the SonoffWebserver sketch which connects to wifi ok and I can switch the relay on/off from the inbuilt webserver (all powered from the USB converter or mains).
    But when I compile/upload Theo’s TASMOTA or your version, the upload works OK, but it doesn’t connect to the wifi. Looking at the output from the serial connection, the ESP seems to crash then restart with this output over and over again –

    ets Jan 8 2013,rst cause:1, boot mode:(3,7)

    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d

    Exception (28):
    epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x001bd9b1 depc=0x00000000

    ctx: cont
    sp: 3fff03a0 end: 3fff06e0 offset: 01a0

    Followed by a load of hex.
    Any ideas what I’ve done wrong?


    • Mark,
      There are a couple of things you can check. The first is that your ESP isn’t picking up bad config from the previous application. Look for the line “#define CFG_HOLDER” either in sonoff.ino (Theo’s original) or in user_config.h (my hack). Add an odd number (lets say 3) onto the hex no. that’s defined there. Close down the IDE completely. Restart it, recompile and reload to the ESP8266 and see whether it works.

      If that cures it, great …but if not, you might find that there’s an SDK incompatibility issue. Have a look at the window header around the IDE and take a note of which version it shows (probably 1.6.9 if you’ve just done a clean install). Next go to an xterm and cat the SDK version number from the file:- ./.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc1/tools/sdk/version

      Go back to Theo’s and check that both of those match the versions which Theo recommends for his application.

      Pete Scargill ( is reporting a possible issue with SDK versions 1.5.4 and 1.5.4-1.



  2. Would love to see a diagram showing how one connects an FTDI device to the Sonoff board. The 3.3v & ground connection is made obvious, but the other two pins, not so much.

    I understand that this post is aimed at people more experienced, but you could open it up to those with less experience if you break out the crayolas!


    • Sorry, Elfeesho, I’m colour-blind, so the crayolas don’t help too much (and those damn 1/8-watt resistors don’t help at all! …at least SMD is a step in the right direction in that respect 🙂 ).

      On a positive note though, you can’t harm your Sonoff or your USB adapter by getting TX and RX mixed up. If it doesn’t work first time, just swap the pins.



  3. You may be able to install eWeLink on a tablet after all…

    I managed it a couple of hours ago after installing the app on a “borrowed” android phone. I used an email address to register the app, and once everything was running, I accepted the update to the newest version 2.2.5 (2016-11-16).

    On a hunch, I copied the downloaded file (Android/data/com.coolkit/files/Download/updates/com.coolkit20161116) to my desktop computer, renamed it eWeLink.2.2.5.apk and downloaded that file to my Android tablet’s Dowload directory. Using a third party file browser (ES File Browser & Total Commander both seem to work) on the tablet, I installed the app. It worked; I could log on to the account created on the server.

    Of course, you have to twiddle permissions to install non Google Play applications (on both the tablet and the phone for the update). You probably have to enable USB debugging and you need to choose the correct connexion mode when plugging in the USB cable to the phone and tablet to enable file transfer.

    Bonus side effect: my mate gets her phone back, updated cleaned, and capable of turning on/off the Christmas lights. I find the sonoff cute and very functionnal. Can’t wait to flash mqtt and incorporate them in future home automation project.

    Thank your for your site; it looks like it will be of great help as I learn about the ESP826.

    p.s. Hope this isn’t one of those recipes that will not work in a few days/week because the next version of the app will be modified.


    • Michel,

      Many thanks for the instructions. Unfortunately I don’t have anyone, willing or unwilling, that I can borrow an Android phone from, but this is certainly useful info that could help others out there. Arigato very much!



    • It is now very easy to install eWeLink on an Android tablet without a telephone number. Just get the latest version (, 2016-11-30) from Google’s Play Store. While it is described as a telephone application, it will download to a tablet and an activation code will be sent to an email address without ever providing a telephone number.

      Unfortunately, I could not install this new version on an older tablet with Android 4.0.4. But I still had eWeLink.2.2.5.apk, and once that was installed it did upgrade to and it does work for the most part. The appearance of the Loop Timer makes it difficult to use.

      If you don’t happen to have the 2.2.5 application package (and you won’t get the following my Nov 22 post since the Play Store has the latest version) you can install the somewhat different E-WeLink-2.1.13.apk (available here: An email address, without phone number, will get you an activation code. The gui is slightly different, the app looks like it can handle different types of devices, and I could not get it to “update” to Still, it if you are impatient to test your Sonoff, and you can’t borrow or beg an Android phone then it is worth a try.

      Incidentally, when I tested E-WeLink-2.1.13, I created a new account (different email, new password). I tried to attach a Sonoff that I had in my original account and the application refused, saying the device belonged to someone else. I found that comforting.

      That should be the end of that saga!




  4. Hello and congrats on this awesome article.
    I have installed the ewelink app on my tablet and on my android phone. The problem is that whenever I login through the smart phone I am disconnected from my tablet (so I need to re-login again) and vice versa. Any ideas on that?


    • Antonis,

      I’ve never bothered to try Ewelink again (there doesn’t seem to be much point when TASMOTA and ESPurna both seem to provide more features and support a wider variety of devices), however I would consider what you describe as being normal. You wouldn’t want multiple devices making concurrent updates. That holds true whether you’re connecting to your living-room Sonoff or over the internet to a banking application.



      • Dear John,
        Thank you for your quick reply. I guess I’ll have to flash new firmware to the boards. Frankly speaking, for the time being, I was quite satisfied with the features provided by the ewelink out of the box and I needed to enable this to my ipad, in the case that my phone is in another room or my girlfriend’s phone. Being two people in the house makes it necessary to be able to control the appliances.
        Thank you once again.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s