Get it while it’s hot!

If you happen to be resident in Japan and if you’re thinking about interfacing to an ESP8266 via Google Home, then you’re in luck …but only for the next two days.  Bic Camera is having a sale between the 22nd and 24th (of September, 2018) with some specific items heavily discounted.  One of them is the Google Home Mini at ¥3,240 (with free shipping inside Japan).  Not only is this a really good price (especially for the land of the rising yen), but you don’t even need to trust some intermediate, dodgy web site with your credit-card details; this is Japan, so you can just stroll down to your nearest “combini”, type your order number into their terminal and then use the printed invoice it produces to pay cash at the counter.  The next step is to sit back with a couple of beers and a good book while you wait for the Takkyubin to knock at your door.  Yappari, Nippon wa sugoi, desune (tokidoki!).


Weekend Reads [2016/06/25]


To begin with …a non-event.  This week we were treated to yet another “ESP8266 Killer!” shock-horror headline.  I suspect that the headline was very much tongue-in-cheek, because the publication in question, Hackaday, certainly knows better.  The article referred to the ESP8285, which was actually announced by Espressif way back in March and,  as the press release makes clear in the heading, the ESP8285 is nothing more than an ESP8266 with on-chip flash memory of 1MB.  For most of us, this was a big yawn item.  The currently available modules generally have more flash on board nowadays and generally, as hobby users, we rarely buy the chips themselves (mainly because it’s more expensive than buying the pre-built modules).  If you are itching to get your hands on an ESP8285 though, there are details below on where you can grab a brand-spanking-new breakout board.

1-btn ESP8266 ...button

On a lighter note …have you ever seen a crowdfunding campaign which reached 384,900% (yes, that’s three-hundred and eighty-four-thousand and nine-hundred percent!) of the funding target?  Well, here you go!  Of course, it’s an ESP8266 product.


For this weeks recommended reads, we touch on a few hardware items which look quite interesting:-

  • Here’s a slightly different take on the Sonoff.  Tinkerman bought some non-RF units and then discovered that he needed RF control after all …so he hacked in an RF board to suit his existing remote control unit.
  • Kris Winer at Pesky Products has a nice ESP8285 adapter board for sale on Tindie.  It’s a wee bit on the expensive side (compared to the el-cheapo 8266 modules we’re all used to), but has a lot on-board, with a LDO regulator, LiPo battery charger, USB-to-Serial, a USB micro-connector, reset and programming buttons, four LEDs and, of course, a breadboard friendly size and layout. ESP8285 dev board There are also pads available for an optional BME280 temp/humidity/pressure sensor and an optional VEML6040 light sensor (Kris can supply boards with these two sensor already populated for an extra $10).  Anyone who regularly browses OSH Park’s “Shared Projects” pages will know that Kris is constantly refining and updating his designs; he has a lot of design experience under his belt, so it’s a good bet that there aren’t going to be any nasty surprises with this module.
  • At the other end of the breakout board scale, Spence Konde (aka Dr Azzy) has a bare board for the ESP8266 which sells on Tindie for only $3.50.  It certainly isn’t as polished as the Pesky Products board, but it does have the advantage of having a good chunk of available prototyping space, along with a very basic power-supply area and break-outs for all of the ESP pins.  Top of DrAzzy ESP8266 breakout boardEither an ESP-07 or ESP-12 module can be used on the board and there are a couple of nice touches — there are different versions of the voltage regulator on the top and bottom of the board (so you use the pads on the bottom of the board for centre-ground versions and the pads on the top for centre-v-out versions), there are both SMD pads and through-hole pads available for some of the components, there are pads for FET drivers on the back of the board (SMD), as well as a couple of positions for WS2812 LED packages.
  • If you’re looking for a vertical,Vertical adapter with 4MB ESP  solderless-breadboard friendly adapter with the ESP8266 already attached at a competitive price, check this offering from (Greece), who also seem to have very reasonable postage rates.

No apologies (but an explanation) for the number of Tindie links this week.  A couple of weeks ago I had started writing a short piece on how disappointing the state of ESP8266 offerings were on Tindie (at that stage there were a fairly large number of vendors simply re-selling the bog-standard AI-Thinker modules and a large number of those were the el-crapo ESP-01 modules, at that).  That article was shelved (who want’s to read what’s not available?!), but I’ve been checking back in with Tindie since then to see if the situation is improving any and, as you can see, slowly but surely it is …but my take-away opinion on this is that you could still make a name for yourself in the ESP8266 world (and, perhaps, a killing) on Tindie if you have a useful, well-priced product aimed at the hobby market right now.

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.

ITEAD Studio delivery

Well, I can confirm that, for Japan anyway, delivery from ITEAD Studio is much faster than the normal Middle Kingdom standard (wait, wait, wait some more, then wait).  I ordered some bits and pieces from them on Monday (which was the first normal work day for them after their new year’s holiday) and the parcel arrived on my doorstep here in deepest, darkest Nagano at lunchtime on Saturday.  I had to sit down and have another cup of tea.

I was pleasantly surprised by the fast delivery and also fairly happy with the contents of the parcel.  I’d ordered a few of their AC to DC isolated switching supplies based on the iW1700 chip, along with a “Sonoff” ESP8266-based WiFi mains switch module (the non-RF version …it doesn’t have the optional 433Mhz card or a key-fob remote control).  I expected the PSUs to be small and I wasn’t disappointed, but what did surprise me was how tiny the Sonoff unit was.

Small hand, smaller Sonoff
Sonoff is tiny!

I’ve got very small hands, by the way (and probably none to clean either, come to think of it), so just image that it’s about one third smaller than the impression you’re getting from the photo.  The screws in the mains connectors are too small for a general-usage small bladed screwdriver and need a smaller “precision” type.  The box which the Sonoff came in was actually smaller than the boxes for the (tiny) switching PSUs, which had me thinking that they’d mixed up my order quantities, until I opened them.

I haven’t used either the Sonoff or any of the PSUs yet, so this is very much just first impressions.  So first, here are the PSU photos (click on them for larger images):-

From the top you can see the switching transistor nestled between the transformer and the 400v electrolytic capacitors.  The pins closest to the camera are the output side, with the middle connection labelled as 3v3.  However, there is actually no pin in that position and, although there are pads for a regulator on the bottom of the board, it isn’t populated either.  It looks as though it would be fairly easy to add a regulator in there, but as there are no pads for capacitors, it would be just as easy to put the regulator and caps on the target PCB instead.

On the photograph of the bottom side you can clearly see the slot underneath the transformer between the primary and secondary side which also runs across almost the full width of the board, providing galvanic isolation between the mains input and 5v output.  The iW1700 is the six-pin chip you can see underneath the transformer,  but on the primary side of the isolating slot.  It gets current feedback from a sense resistor connected to the emitter of the switching transistor and voltage feedback from a separate primary-side winding on the transformer; there is no feedback path from the secondary.  The two larger resistors at the extreme right of the photo are marked “155” (that’s 15 + five zeros, or 1.5 megohms) and they’re wired in series to give a very high impedance “bootstrap” supply to the iW1700 (this one of the area where the ITEAD design differs from the reference design – the reference uses a smaller limiting resistor and a “normally on” depletion mode MOSFET connected to the “active start-up” pin of the iW1700, so that once the power supply has bootstrapped itself the power flowing through the bootstrap resistor can be turned off).  The big, square, four-pin block next to the input pins is the bridge rectifier.

This isn’t a particularly efficient supply for a switcher (running, according to the design sheet, at roughly 75 to 80%, depending upon the combination of input and output voltages), but it does have a remarkably low quiescent current under no-load conditions, so is pretty good for something like a phone charger where the load will suddenly drop off (at full charge), but where the unit itself may remain connected to the mains supply for long periods.  Similar conditions might be found when providing the supply to  an ESP8266 which operates normally for a while and then drops into sleep mode, so it’s no huge surprise to find that ITEAD use virtually the same circuit in their “Sonoff”, ESP8266-based WiFi mains switch.  Looking at the photos of the (shockingly naked) Sonoff we see some very familiar components (again, click for larger sized images):-

Looking at the bottom side of the board, you can see the square block of the bridge rectifier at the top, left-hand corner and then slightly below and to the left our familiar “155” resistors (labelled R16 and R17) with the 6-pin  iW1700 chip sitting over to the left and slightly higher, labelled as U12.  The right hand side of the board is almost entirely given over to the ESP8266 (note the antenna at the extreme top right) and the tinned bus bars connecting the output screw-down connector to the relay and input side.  The empty row of holes slightly to the right of centre bottom are where the 433Mhz RF module sits (in the more expensive remote control “RF” version).  Over on the photo of the top side of the board the same row of empty holes can be seen slightly right of centre closer to the top edge of the board.  Just below them is an unpopulated pad for a QFP chip, labelled as U5.  That’s for the 8051-based “Busy-Bee-1” chip, which appears to handle the control of the 433Mhz module on the “RF” version.

Further down at the bottom of the photo and further to the left of centre is the (yellow) transformer for the power supply and you can clearly see the switching transistor sitting just to the left of it.  The big black box with the white paper label is the relay which switches the output load.

Backing up just a little bit, you’ll note that I said I was “fairly” (not “ecstatically”) happy about the contents of the parcel and the photo of the bottom of the Sonoff board shows why.  If you compare the photo of the PSU board and the PSU section of the Sonoff board you’ll notice a couple of things.  First, the PSU PCB has an isolating slot between the primary and secondary sides of the transformer, while the Sonoff doesn’t.  Second, the iW1700 chip is under the transformer, but on the primary side of the slot on the PSU PCB and, while it’s in the same approximate place on the Sonoff, it has been rotated 90° so that the tracks from the pins now come out towards the secondary pins.  Mmmm, not so good.

Don’t get me wrong.  This is still an isolated supply (the transformer and the winding on the relay both provide isolation to the ESP8266 circuitry), but I don’t believe that the “Sonoff” would pass regulatory inspection in the U.S. or in Europe (the fact that it has screw-down terminals instead of a molded-in power outlet probably makes the PSU issue a moot point, anyway).

Would I use the Sonoff myself?  Heck yes!  I’ll probably buy some more of them, too.  I’ve built much worse things myself (think full-wave rectified 240-volt mains with thyristors on stripboard and run away, screaming), although admittedly, I didn’t sell them as products.  The Sonoff will enable people with minimal knowledge or experience to put together an IoT set-up relatively safely (without having to resort to the horrible mix of stripboard and mains) and, whatever its faults, it is orders of magnitude better than any of the duct-tape-and-hot-glue IoT instructables out there.  Going back to my initial impression, it’s also small.  There are lots of places where a Sonoff would fit in unobtrusively (behind your TV, in an equipment cabinet) where it would save the trouble of needing to be physically there to simply power-cycle some errant piece of electronics.  It looks like a winner to me and that’s even before you factor in the ability of most ESP-aware folks (that’s you) of being able to reprogram the on-board chip to talk MQTT.

Update – See the newer post “No-Phone Sonoff stuff” for more information on loading an MQTT capable package onto the Sonoff.


Sonoff and Slampher – Crowdfunding for an existing product?

The last few articles that I’ve posted have been all about reworking the AI-Thinker T5 board to get it functioning with the on-board ESP-13 module.  You may also have noted that I chose to remove the relay and screw-down terminal, as I didn’t want anyone connecting AC mains voltage to something which obviously wasn’t designed for it, despite the promotional images showing a light-bulb.  Well, here’s another product out of the Middle Kingdom which is not only cheaper than the T5, but apparently a good deal more functional (not too difficult, I know) and safer, too.

Itead Studio is probably a familiar name to most of us, having made a name for themselves producing hobby boards and modules and providing a low-cost PCB service to boot.

Sonoff IoT Switch

They have a new pair of products, going by the not-very-snappy names of Sonoff and Slampher.  They are of interest to us because both contain an ESP8266 chip and provide WiFi control of mains powered devices.  I don’t have either of these units myself (yet), but from all that has appeared so far, they do seem to be quite special.  Sonoff is an in-line, relay based switch for small to medium sized appliances with a 10A rating.

Itead IoT Light Switch

Slampher is a screw-in base connector for light bulbs (it screws into the original socket and then the bulb screws into it) with an SSR which is rated at a more modest 2A.

They are cheap!  Basically a single unit is being sold for around $5 at the moment.  What’s more, they seem to be of quite decent quality, especially considering the price.  From the tear-downs and information I’ve seen elsewhere so far, there’s a switching power supply built in to provide the low voltage DC supply to the logic, there are routed cut-outs on the PCB (on the Sonoff, anyway) to provide physical isolation between the AC mains side and the low-voltage DC side and the single user-input button has a long plastic stem to provide further insulation between the user and the PCB.  The one area where the Sonoff may run afoul of regulatory requirements are the screw-down terminals for input and output connections, but otherwise both units look to be in a completely different league to most other offerings out there in the $10 range.

The units are basically switches, but in addition to the ESP8266 for WiFi, they also have a built in 433Mhz receiver and come with a tiny, key-fob sized 433Mhz remote control.  So you have that long-stemmed switch on each unit which can be used to manually toggle the (mains) device under control on and off, or to configure individual Sonoffs or Slamphers to respond to one (of the four) channels on the remote control (so one remote can control four S&S switches).  In addition to the manual and remote-control modes, the ESP8266 provides connectivity to enable remote switching from your network and Itead provide a free app and “cloud” service, so that your device could be switched on and off from a smart-phone anywhere in the world (no word on security yet, so it’s probably not a good idea to hook up anyone’s life-support system to one of these).  Importantly though, the app does provide feedback for the current state of the switched device (even if it has been manually toggled using the switch on the Sonoff or Slampher), so you can always see if someone else has turned your office coffee-maker on at 03:00 (if you happen to be awake and watching the status on you smart phone at that time of the morning).

Pete Scargill has already been at work with a screwdriver and a USB adapter and apparently has reflashed one of the units he has to use MQTT (which opens the door to local monitoring and control of devices, without the need to utilize Itead’s cloud system).

Peter Oakes has produced a couple of nice videos, the first showing the operation of both units and how to set up the cloud interface and the second is a teardown of both units.

Now the strange thing is, these units first came to my attention because of an on-going fund-raiser on Indiegogo.Sonoff Indiegogo  I liked what I saw (and the price) enough to subscribe for a couple of units (my first crowdfunding effort), but after signing up I discovered that similar units are already on sale in the Itead on-line shop.  Strange!  Why would Itead run a campaign for units which are already in production?  Well, it turns out that one reason is that the units available in their shop are earlier versions, which don’t have the 433Mhz remote control capability, so maybe they’re using Indiegogo not just to fund the production run of the newer models, but also to provide a little bit of extra “visibility” to their sales campaign?  I don’t really know the answer, but I still like the products and the price enough that I’m in for a couple of Sonoffs and am seriously considering whether to buy in for a couple of the Slamphers (despite the awful name), too.  As of the the time this article was penned, we both have twelve days left to decide.

Update – Not about the crowdfunding, but about the devices themselves …I’ve been trawling through the available documentation and it looks as though these devices “do the right thing”  when it comes to power and insulation/isolation.  The schematic shows that the Sonoff uses an iWatt iW1700 switcher chip to provide the low voltage supply to the ESP8266.  This is a really nice little chip which, according to the datasheet, changes modes between PWM (pulse-width-modulation)

iW1700 Typical Application
iW1700 circuit, courtesy of Dialog

and PFM (pulse-frequency-modulation) depending upon the load requirements.  It also has an exceptionally low stand-by current draw.  Regulation is based on current sensing through the drive transistor and voltage sensing through the auxiliary primary winding of the isolating transformer, so there are no opto-isolators required between the secondary and the chip.  At any rate, the supply and design provide “galvanic isolation” between the mains supply and the low-voltage electronics.  Definitely a good thing.

Update – Well, the campaign kinda’ fizzled, which is what I hope the products themselves won’t do, either figuratively or literally.  However, because I was so impressed with the iW1700 and because it matches the requirements of the ESP8266 so well (ultra-low power when the ESP is in sleep mode), I decided to order a bunch of the stand-alone AC supplies (which are available for just $2.50 each directly from ITEAD) as well as a single Sonoff (the version without the 433MHz remote control) just to play around with.  ITEAD obviously ships more promptly than some Middle Kingdom suppliers and everything arrived on my doorstep just six days after ordering.  I still haven’t had time to actually play with anything, but some photos and descriptions are in a newer post.