Using oddball ESP boards with TASMOTA – Part II (Console)

I’m not going to go too deeply into the specific hardware I used for my own project, but instead just give a couple of tips on using the Yellow board as a base for your own creations.  First of all there’s that row of red LEDs.  While they make for a neat “running light” display, there aren’t that many projects (ESP-based VU meter, anyone?) where they’d be truly useful.  In addition to sucking the life out of your battery, they can also interfere with some peripheral connections by providing a pull-up path on the GPIO pins (the single RGB LED is a common-cathode device, by the way, so those GPIOs are pulled down).  Sometimes the red LEDs are beneficial; for instance, I2C requires pull-ups and the LEDs also handily show activity on the bus, which can be an aid to troubleshooting.  However, in general, we don’t want them there, especially on a battery-powered projects.  I usually disable the red LEDs by removing the 470Ω current limiting resistors with a hot iron (why the resistors? …because I don’t have to try and figure out the correct polarity when replacing them, if I want to re-enable any of the LEDs).

If you’re mounting the Yellow board in an enclosure of some sort, you may want to desolder the RGB LED and mount in the lid,so it can be seen externally.  Be warned, because of the four leads (with the one which is the common cathode soldered to ground), this is a bit of a beast to remove, but it can be done with a big enough iron and some patience.  If you are mounting the LED to the lid, it makes sense to add a momentary switch across the boot/program select jumper (GPIO0) and mount it in the lid, too.  That will give you access to all of the Sonoff switch functionality built into TASMOTA.

Whichever way you’re powering the Yellow board, from batteries or a mains adapter of some sort, it never hurts to add a nice chunky electrolytic capacitor on the 3v3 supply line (I generally use a 470µF).  The existing SMD capacitor close to the edge of the board by the boot/program select jumper has the pads oriented just right to allow the leads of the electrolytic to be soldered on, with the body of the capacitor hanging over the edge of the PCB.  A 5v supply from something like a phone charger works well with the Holtek regulator on the Yellow board (which has rather a low maximum input voltage rating, compared with some of the more commonly available 3v3 regulators).

Using the configuration information from the previous article as a guide, you can now connect up the Yellow board GPIOs to the devices you need for your project.  The important ones for TASMOTA compatibility are:-

  • GPIO0   – Button1
  • GPIO12 – Relay1
  • GPIO13 – LED1 (the Sonoff basic uses “LED1i”)

In my particular application, GPIO13 (LED1) is connected to the green anode of the RGB LED and I also have three additional connections:-

  • GPIO5   – DS18x20 (two DS18B20 temperature sensors)
  • GPIO14 – PWM1 (the blue anode of the RGB LED)
  • GPIO15 – PWM2 (the red anode of the RGB LED)

With the current version of TASMOTA (5.11.1), the one-wire bus for DS18x20 sensors is limited to a single GPIO.  You can have multiple sensors on that GPIO, but you can’t have (for instance) one DS18B20 on GPIO4 and another on GPIO5; only one of them will show up.  If you want to have more than one sensor on your one-wire bus, you should use Theo’s specially crafted sonoff-ds18x20 binary (or define USE_DS18x20 in the user_config.h file when building your own).

The “PWM” designations for GPIO14 and GPIO15 allow us to control the brightness of the LEDs attached to those pins.  We could just as easily have assigned them as “LED2” and “LED3” to use simple on/off switching, instead.

Now, to test the operation of our newly updated ESP8266, we have basically three options:-

  • The serial port on the ESP itself.
  • The web server provided by TASMOTA
  • MQTT

DO NOT use the serial port method with a mains-powered project unless you remove external power and use the serial adapter to provide DC to the ESP.  I’d recommend that you program the ESP with the serial adapter before fitting it to any mains-powered project and from that point onwards limit yourself to OTA upgrades and using the Web and MQTT methods for configuration and testing.  Note that using a serial adapter generally doesn’t supply enough current to reliably drive multiple LEDs and a relay, so I wouldn’t recommend this method, anyway.

For either of the remaining methods, the essential reference guide is the “Commands” page of the Sonoff-TASMOTA wiki.  You should keep that guide open in your browser while you experiment.

The “console” option of the web interface provides a very versatile method of monitoring output, as well as enabling input and, together with the previously discussed configuration menus, is pretty much all you need to get your ESP project up and running.  You can input commands by selecting “Console” from the main TASMOTA menu and typing them into the input box displayed at the bottom of the screen.  The results will be displayed in the main console window.

Console command window detail

In the above example (click image for full-size version), you can see that the console was displaying occasional status messages until (at 23:56) I entered the commands:-

  • ledpower
  • ledpower on
  • ledpower off
  • ledpower

…to check the current status of the green LED (LED1), then turn the green LED on, turn it off again and finally check the status to verify that it was off (note that the final “ledpower” command was entirely spurious, as the device had already echoed an “MQT” status message in the main console window to indicate that the LED was “OFF”).

The commands to control the relay are similar.  We simply replace the “ledpower” with just “power”.  Typing in “power” on its own will return the current status, while “power on” and “power off” do exactly what you’d expect and also return a confirmation message, just as the “ledpower” command did.

Controlling the PWM drive to the red and blue LEDs is only very slightly more complicated.   Entering “pwm” gives us the status (of both PWM1 and PWM2), while entering “pwm1” or “pwm2” followed by a numeric value between 0 and 1023 will produce an output brightness in proportion to the value entered (and, as before, the console will show a message confirming that the action has been completed).

00:24:15 CMD: pwm
00:24:15 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":0,"PWM2":0}}
00:24:21 CMD: pwm1 350
00:24:21 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":350,"PWM2":0}}
00:24:35 CMD: pwm2 799
00:24:35 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":350,"PWM2":799}}
00:24:38 CMD: pwm
00:24:38 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":350,"PWM2":799}

Reading the one-wire sensors is even easier still.  As long as there are no hardware or Main menu, showing temperature readouts.configuration issues, the temperature(s) will always be displayed at the very top of the TASMOTA main menu.

Using the console command line is slightly more obtuse, though.  The temperature readouts are a part of the TASMOTA status group, so you could type in the command “status 0” to get a full display of all possible status items.  However, if you do that, you will see an extremely verbose listing of 10 separate lines of status, with the temperature data being displayed as status line “STATUS10…StatusSNS…”.  Luckily that line hints at the command we need to use to get just the temperatures and nothing else.  The magic incantation is “status 10” and typing that into the console input box will return just that single “StatusSNS” line with our sensor data, including the sensor’s unique serial number and an indication of whether it is reporting in Fahrenheit or Celsius, as well as the temperature value itself.

00:55:11 CMD: status 10
00:55:11 MQT: stat/Plug1/STATUS10 = {"StatusSNS":{"Time":"2018-02-01T00:55:11","DS18B20-1":{"Id":"011590E534FF","Temperature":2.87},"DS18B20-2":{"Id":"031590A618FF","Temperature":1.87},"TempUnit":"C"}}

There are a number of “setoption” commands in the TASMOTA toolbox and, for those who might need it, the command “setoption8” will change the temperature display units.

setoption8 0 – sets the units to Celsius

setoption8 1 – sets the units to Fahrenheit

That’s it for the console commands for now.  Next time we’ll look at doing the same thing again, but utilizing MQTT from a remote machine, instead.


A wee bit late for Xmas, but…

Here’s a very seasonal item, courtesy of Hackaday  …Sean Hodgins’ ESP8266-enabled Xmas ornaments.  They’re worth checking out for the really neat, multi-coloured PCBs (although I’d probably decide to do without the piezo speaker if I were to build any).

Sean Hodgins' Xmas Ornaments

No word yet on where Sean sourced the PCBs, or on what the battery life is like (even with deepSleep(), not long, I’d guess).

Sean’s GitHub repository has all of the code, if you fancy knocking a couple of these together on Xmas morning.

Never underestimate the power of the gravy.

This is yet another aside and absolutely nothing to do with the ESP8266, so you’re allowed to change channels now if you feel cheated…

We have an IH cooker which came as part of a complete kitchen assembly some ten odd years ago (HID∇  “Nice red.  We’ll take it!”) and has worked well (if a little noisily) since then.  Many of the controls (including the main on/off switch) are cleverly camouflaged or secreted away behind hidden panels, which can make cooking for visitors quite an adventure, but the controls for the two, main top 3KW rings are nicely set out along the front edge of the cook top and easy to see and use.  Right and left rings have separate controls; a strip of fairly heavy duty plastic film with domed buttons which pretty obviously, from the feel, cover “tact” switches underneath.  Unfortunately, over the past few months, the on/off control for the left-hand ring has gone from “iffy”, to “troublesome”, to “Lunch will be served in dribs and drabs over the course of the next hour and a half”.

It’s just a tact switch …I can do that.  Maybe.

Disclaimer & Safety Warning – Although officially an old fart now, I have spent the best part of my professional career troubleshooting and repairing isolated and non-isolated, low and high voltage supplies of various sorts (and have the scars to prove it).  I’ve designed, built and blown-up my own switching power supplies, studied (and mostly forgotten) the theory and practised the practical.  I’m not a newby at this, in fact, by definition and history, this is what I do and what I am.  This article is for your entertainment and amusement.  I am not suggesting in any way that you should start fooling around with equipment which has the potential (yes, bad pun intended …again) to maim or kill you or to burn not just your dwelling, but the entire neighbourhood to the ground.  Please enjoy this article, but …Don’t Do This At Home!

As well as the half-dozen or so salvaged tact switches in my junk box, I’d recently bought a bag of 100 tact switches to feed my habit of building ESP8266 devices (most of those switches are now probably going to go to waste, as I move over from manually reprogramming devices to OTA updates), so I was fairly confident I would have something available to replace the part which I suspected had failed (and there, we did manage to squeeze in a little bit of ESP8266 after all).  So, off with the breaker, disconnect the unit from the mains supply and get to work.

Ah!  How do you get this dang thing out of the work-top?  After removing lots of dangly bits of plastic trim, most of the surrounding drawers and all of the obvious screws, I was still no closer to actually getting the beast out to where I could work on it.  After a bit of crawling around with a flashlight in the spiders webs and mummified, zombie carrot slices which inhabit the nether regions of our kitchen unit I came to the conclusion that it was gravity …and lots of glue, which was holding me up and the cooker down.  I’d already loosened a retaining lug at the back of the unit, so I confidently applied the ISO certified BSAI method (Brute Strength and Ignorance) until the glue sealing the unit to the worktop finally and noisily gave way.  With the seal broken the unit was actually relatively light and I was able to angle it out on my own fairly easily, thus skilfully avoiding one of these “What are you DOING!?!” moments (she’ll never notice the gaping hole in the counter top for a couple of hours …unless she drops the coffee pot into the chasm at eleven o’clock).

Getting into the unit proved almost as difficult as getting it out of the counter, with a pair of sneakily hidden tongues latching the front of the glass and metal top to the body (easy to see …once the top was actually removed).  From that point, access to the PCB holding the control switches was relatively straightforward, with just a single, flat ribbon cable connecting the left-hand panel to the rest of the electronics.  Evidence of gravy ingress. Yuk!Removing the PCB from the plastic housing revealed an unwanted surprise; a nasty mess of coagulated goo (looking suspiciously like gravy from a long-forgotten Sunday roast) coating the board and components in the general area of the faulty switch.  Yuk!  A quick check revealed that the glue holding down the plastic button cover wasn’t quite up to the standard of the stuff which they’d used for the counter top and the liquid had leaked in through some tiny gaps in that seal.  Messy!

First order of business, pry off a bit of the goo and taste it to see whether it was turkey or beef.  If it’s turkey, it’s definitely my fault. [Okay, I admit it, I didn’t actually perform this act of forensic(k) investigation  …I’ll cop for the blame without indulging, thank you!].  Out with the alcohol and swabs to clean up  the patient before the real operation begins.  Bugritt!  The tiny, SMD LED next to the on/off switch decides it likes gravy better than working for a living and skitters off across the workbench to hide somewhere.  At this point I notice that, as the gravy comes off, it’s bringing quite a bit of corroded metal (of various sorts) off with it.  Well who’d have thought it, you can apparently use gravy to etch PCBs!  And LED anode/cathode connections.  And metal switch bodies.  And solder.  Voracious gravy  (what on earth is it doing to our stomachs?)!

After a couple of dozen swabs I could actually see what I was working on.  The board was long and thin, but the layout was a classic switch/diode matrix with a couple of LEDs thrown in.   I already knew that I was probably out of luck with my bargain-basement bag of switches.  I could see from the clean end of the board that the tact switches used by the manufacturer were five-pin, low-profile, surface mount types, with a nice metal shield enclosing the plastic body.  That shield was very much the worse for wear gravy on the on/off switch, as were the PCB tracks in the immediate vicinity.  A check with the meter on the (newly de-gravied) pins confirmed that the on/off was an ex-switch and now functioned solely as an air-gap (or possibly a gravy-gap).  Fall back to plan “B”.  I’m going to have to sacrifice one of the other switches to replace the broken one.  The “timer select” switch would have been the obvious one (never once used in ten years …it must be pristine inside), but it’s so close to the plastic ribbon connector that it’s impossible to get the soldering iron in there, so the fickle finger of fate falls upon the “down” switch (there are “up” and “down” switches to fine-tune the power level, but there are also several pre-sets, “low”, “medium” and “high” which are what we generally use anyway).  In retrospect the “up” switch would probably have been a better choice (to prevent nasty surprises to the unwary), but the “off” switch should work after this, anyway.

The swapping of the switches was fiddly, but not impossible and I repaired the PCB traces as best I could with tinned wire and checked for continuity with the meter again afterwards.  Everything looked good (apart from our AWOL LED), so I threw it all back together just to test and …bugrall!  The newly replaced switch made a nice healthy clicking sound and felt good and I knew from my previous check with the meter that it was working and that we had continuity on the damaged tracks, but it still didn’t want to play nice.  Back to the workbench with it.

Which is where I discovered that the continuity ended at the solder joints either side of the diode which isolated the on/off switch.  The leads (short though they were for the SMD diode) had been eaten completely away, so although it looked fine to the naked eye, it was just sitting there, stuck to the board by a tiny puddle of the gravy-goo underneath it.  This was a bit of a problem.  As I mentioned, I’m a certified old fart, so virtually all of the components I have in-hand are through-the-hole.  I have hundreds of diodes in stock, but none of them are SMD and, unfortunately, the diode sits right underneath a plastic frame in the assembly, which in turn sits right underneath the membrane of the switch plastic, so a non-SMD part would prevent the switch from closing.  Time for some more ferreting around in the junk box.  Ah-hah!  A logic board for an old CD player, which I’d held onto mainly to salvage the chunky FET drivers from and, yes, there were a couple of mostly anonymous SMDs on there which were silk-screened as being D134/D135.  Unfortunately, they were both common cathode, dual-diode packages, but hey, life isn’t perfect and it is only a switch array after all.  So, after a wee bit of soldering we had an SMD diode package mounted diagonally across the pads and looking, according to the junction test function on the meter, remarkably like the other diodes on the board (which I now took the time to check, one by one).  The same CD controller also yielded up an SMD LED as a replacement for the one which is (still!) hiding somewhere on the workbench and we’re now racing against the clock and a looming coffee break time (with the emphasis on the “break” part if I don’t get the cooker back into place before someone tries to boil water).  I slap it together again roughly, just long enough to make sure that it does actually work this time and then take the time to squirt some fresh heat-transfer compound back onto the mating surfaces between the temperature sensors and the glass work surface, before assembling everything once more into a plastic, glass and metal lump which resembles a cooker, rather than the vaguely electronic pile of scrap we had a few minutes earlier.  One more check and then it’s time to lever the whole thing back into place in the worktop.  A quick wipe down and we’re almost good to go.  I pop the coffee pot on the left-hand ring and bring it to the boil while I’m replacing the drawers and tidying up the other odds and ends (I don’t need to hide the screwdrivers …they’re a normal part of our kitchen furniture if I happen to be there).  As the magic hour approaches, I switch the coffee pot back onto the right-hand ring and am mildly, but pleasantly, surprised when Mr Murphy fails to make one of his usual, ill-timed appearances and the water is boiled and ready when HID∇ makes her appearance for coffee.

∇ – “Her Indoors”

Postscript – A couple of weeks later, “Hey, have you noticed?  That left hand ring has fixed itself, thank goodness.  If we had to wait for you to get around to it we’d be drawing our pensions already!”.  As we are drawing our pensions already, I take this as a subtle complement (she probably did notice the boot mark on the counter, after all).