Keeping your local ESP8266 source trees up to date

I have a burgeoning directory on my laptop which holds all of the source code for any ESP8266 project I’ve ever come across and thought “This looks interesting…”.  Through the magic of Git, it usually only takes a few seconds to clone a complete project to local disk and have a permanent local copy which you can play with.  The only problem being that the code usually gets stale fairly quickly and you never know when the original author has pushed out an update.  To this end, I knocked together a very simple script which simply lists all of the subdirectories in my ESP8266 master directory and then goes off and does a “git pull” for everything it finds …assuming that the subdirectory is actually a git structured repository and is not flagged with “Do Not Update”.

Git being git, it doesn’t actually care whether the remote, original repository is on GitHub, PasteBin or Bob’s_basement_box, it’ll happily update from the stored URL, whatever and where-ever it is.

The “Do Not Update” feature is there in case you’re lazy (like me) and tend to make working directories with local modifications (which would fail to update and cause errors), or just because you want to maintain a pristine, original snapshot of a repository at some particular point in time.  You can tell the script not to update a repository in two ways.  The first is to add the name of the subdirectory to the file Do_Not_Update.txt in the top-level ESP8266 directory.  The second is to create a file named “Do_Not_Copy” in the actual repository subdirectory itself (the file can be empty, or you can use it to store a note on why you wanted to prevent updates).

The script will keep a (fairly verbose) log of the update process (by default, it is written to /var/tmp/ESP8266_auto_update.log).

The only thing you must change for your particular installation is the path to the top-level ESP8266 directory on your machine (which can be called anything you wish, BTW), “WK_DIR”, which is right at the top of the script.  There’s a sample cron entry in the file which will run the script once per week.

I’ve been running this early every morning for my ESP8266, ESP32 and a couple of other directories for well over a year now and my morning routine now includes a quick “ls -alrt” of those directories to see what’s been updated in the last 24 hours  …a good way of staying abreast of Theo’s amazing update rate on TASMOTA.


T-bao R8 15.6″ $185 Laptop – First Impressions

My old Inspiron 1525 laptop (bought second-hand) has served me well over the past few years, but now has a host of symptoms which, collectively, mean imminent retirement (the hinges are loose, the fan is terminally noisy, the “h” key and space-bar are both intermittent, the battery is dying again and, worst of all, it occasionally crashes with memory-related errors).  I’ve been on the lookout for a replacement for a while and, rather than paying inflated prices for a low-end machine, I thought I’d take a chance and pay next to nothing for a very low-end machine.  The T-bao R8 15.6″ laptop is available through GearBest (and a few other on-line retailers) for less than $200 and sometimes for as little as $182~$185 (usually with a special discount code).

I should note here that I bought this machine for my own use and I am in no way affiliated with GearBest, other than being a customer.

The T-bao was on a “special offer” sale when I bought it and there was also a valid coupon code available for a one-time purchase which bought the price down even further (note that you have to enter the coupon code at the check-out stage and only the final price changes, not the displayed price for the actual item).  If you’re interested in getting a bargain deal like this, it’s worthwhile doing a web search for “GearBest coupon codes” -and- regularly checking back with the main GearBest site, as the price for an item in your cart will vary by quite a bit over time, depending upon what special offers are available (along with the coupon codes); the difference can easily be $20~$30.

As far as I can tell, there is no difference between the T-bao R8 and the Chuwi 15.6″ LapBook.  Looking at the photographs on the web page, it appeared as though the T-bao had a symmetrical screen bezel (whereas the Chuwi has a very obvious asymmetric design, with the right hand bezel being slightly thicker than the left).  However, having received the machine, I can confirm that the T-bao is also asymmetric, with a 5mm left-hand bezel and an 8.5mm one on the right.  The T-bao is also available in both blue and white versions (although the “Sapphire Blue” version is the one most frequently discounted).  Both machines seem to have pretty much identical hardware specs (as advertised on the sites where they’re sold), but it’s worth noting that the stated specs aren’t always correct (see the note on USB 2.0/3.0 below).

-Update 7th Sept 2017-   It looks as though this same model is now being sold as a “Deeq Z156 Notebook” on some sites.  The specs (and pictures) look pretty much the same, but the price is somewhat higher (note that, on GearBest at least, the Deeq includes a USB to ethernet adapter as part of the deal).

One of the reasons I decided on this type of laptop (either the T-bao or the Chuwi) was that at the end of last year I purchased a Z83-II mini PC system as a replacement for an older, standalone home server and I’ve been really impressed with its performance, despite being a lowly “Atom” Z8350 processor (it’s actually quad core and holds up remarkably well under load).  Both of the laptops seem to be adaptations of the same basic design and, like the Z83-II, they’re both fan-less, which is another major plus for me.

Anyway, the T-bao was a slightly more attractive colour than the Chuwi (and the prices were within pennies of each other), so a couple of weeks back I took the plunge and ordered it, resigning myself to a two or three week wait (the norm for things coming to Japan from the Middle Kingdom).  A week to the day after I’d ordered, a courier delivered the package to my doorstep (so top marks to GearBest for prompt shipping).  The laptop was well packed in a type of strong, light, corrugated plastic former which I hadn’t seen before, but which is obviously ideal for this type of shipment.  My heart sank when I saw that the package had been opened (visions of a faulty returned unit being re-shipped), but it’s just as likely that customs had opened it.

The laptop was neatly boxed and the white cardboard, minimal “UltraBook” logo and profile, black and white photos of the laptop on the exterior reminded me strongly of Apple packaging.  Inside the box, the laptop had plastic protective sheets both top and bottom, with an extra (super-reflective) sheet across the screen.  The power-supply and a (fairly superfluous) leaflet were included in a separate, boxed-off area to the rear of the laptop itself.  I don’t have any sapphires to hand and I’m colour-blind enough to be fairly useless at adjusting a colour CRT (if anyone other than Jenny List and me still remembers doing that), but the R8 is definitely blue.  The uniform swath of blueness is unbroken, except for the “T-bao” logo in the centre of the top panel.  It doesn’t look too bad for the price and the build quality is surprisingly good.  It has a nice heft to it and it doesn’t feel as flimsy as some, all-plastic laptops that I’ve used.  It’s light enough to be easily transportable, although I don’t suppose the majority of people who buy a 15.6″ screen are going for the portable option.


The good, the bad and the not-so ugly

Even before plugging the laptop in, there are a few obvious things which scream built-to-cost.  The cable on the power supply is short and will barely reach from floor to table-top.  In addition to that, the connector is a minuscule “barrel” type, of a size (3.5mm) which is normally associated with USB hubs (which generally remain permanently connected and get very little stress).  It’s a fair bet that this flimsy plug (or rather, the socket on the laptop motherboard) is going to be the major point of failure for anyone (like me) who unplugs their laptop once or twice every day for untethered use.  The PSU plug does get noticeably warm (not hot) in use.

One oddball thing which I noticed after plugging in that tiny plug is that there’s an even tinier red LED between the power socket and the back of the laptop which appears to come on when the battery is discharging and (maybe) when it is connected to power but not fully charged.  The LED is in a position which is difficult to see when you’re using the laptop, so I’m still not entirely sure what its purpose actually is (other than to further deplete your battery).

While we’re on the subject of LEDs, I have to mention that I’m surprised just how much I miss a “disk activity” indicator.  Without the noise of a spinning disk, there’s nothing on this machine to indicate that it’s doing anything at all.  I wonder how difficult it would be to convert the numeric-lock indicator to display disk accesses instead?

The keyboard and touch-pad also show their (lack of) pedigree, with somewhat jerky key movement and a noisy, “clacky” spacebar which doesn’t always register presses, unless they’re near to the centre of the key.  The one-piece touch-pad has physical key-switches underneath it at the bottom left and bottom right (there are no separate buttons), so you can use either tap selection, or press selection (or a mixture of both).  Using a physical press to imitate left and right mouse buttons is surprisingly noisy as the flexing of the touch-pad and the noise made by the key-switches seems to reverberate through the internal cavity of the laptop.  The noise is loud enough to wake a dozing person on the other side of the table (“Watchoodoowin?!?!?”), which is much too loud for me.  Having said that, the keyboard is definitely usable (although not as comfortable to type on as the older Inspiron) and the touch-pad can be used in tap mode and with some basic  gestures, such as two-fingered scrolling, zoom and pinch.

The key-tops on the keyboard are black, with white lettering, so very legible.  The additional functions (such as numerics, volume control, etc) are marked in blue, which is also very legible under normal lighting conditions (and far superior to the terrible red-on-black which is so common — and so totally illegible — on most laptop keyboards).  One obvious missing function though, is brightness control for the display; you need to use on-screen control to control screen brightness (am I the only one to see a problem with that?).

The display itself is actually very nice.  Removing the super-glossy protective sheet reveals a matte screen with excellent contrast and brightness and minimal reflection.  I found the colours to be bright and (bearing in mind my comments earlier about colour-blindness) accurate.  The wide aspect ratio makes it pleasant to use and the high definition means that there’s tons of space available for multiple windows.  One of my only reservations with it is that the hinges on the laptop lid limit the vertical viewing angle a little too much for comfortable use on your lap; it really needs about another twenty degrees of (backwards) travel.

Sound — So far I’ve been unable to get sound working, so this one will have to wait.  I will note here though that the positioning of the speakers under the bottom of the laptop body means that the sound is undoubtedly going to be muffled when the machine is sat on your lap.

WiFi — You don’t have the option of an hard-wired Ethernet port on this laptop, so you will be using WiFi (unless you buy an additional dongle for one of the USB ports).  My experience so far is that the WiFi seems to be less sensitive than the other machines in the household and I have seen very occasional drop outs where I lose signal completely.  This is actually a little worrying, as I live in a log house, with no brick walls anywhere and I don’t normally have any problems picking up a signal anywhere indoors, or even outdoors within a few metres of the house.  If you happen to have a brick or concrete built house with solid walls, I’d guess this may be a fairly major issue for you.

There seems to be some confusion between different web sites advertising this product about the capabilities of the USB ports.  I can confirm that one port is indeed a USB 3.0 port and plugging in a 3.0 device shows a speed of “5000M” (as opposed to the “480M” for the USB 2.0 port and camera), so the GearBest is correct in this respect and the sites which show USB 2.0 only are incorrect).

The Bottom Line

Okay, reading back over this, it all  looks a bit negative, but I’m trying to give an honest impression of what you’ll be getting if you order one of these systems.

At the end of the day, the main question is, is it worth $185?  If you’d have asked me this two weeks ago, you would probably have gotten a simple “No”, mainly because of the keyboard and touch-pad.  After loading, booting and configuring Linux on this beast many, many, many times over the past few days, I’ve naturally started to get used to the keyboard quirks and have consciously modified my own behaviour to work with the touch-pad, instead of against it (helpful hint:  use your two middle fingers for scrolling, instead of index and middle – it works much better.  Oh, and keep your palms off the touch-pad when typing, too).

So at this point in time I’d actually give it a qualified thumbs-up and say yes, it is worth $185.  If you’re a Windows user and can work with the version which comes pre-loaded, then it’s probably a huge bargain (be prepared to give yourself a couple of weeks to get used to the keyboard and touch-pad, though).  If you’re a parent looking for a cheap laptop for one of your children for school, this one looks good, runs Windows and it won’t give you a heart attack if they drop it on the first day.

If you’re not a Windows user, then you need to be prepared to go through some extra steps (over and above the normal Linux install) to get this laptop working.  The UEFI boot and Atom processor mean that this isn’t a particularly easy machine to get running (see the next article for details), but the good news is that bootable (and mostly usable) images for the latest Ubuntu-based Linuxes are available on the ‘net (but you might have to live without sound and Bluetooth until some issues with those are solved).

Update as of Nov 3rd 2017 —  Okay, after struggling with this beast for many tedious weeks, I’m going to change my opinion for non-Windows users to a definite thumbs down for this machine (again, see the follow-up article for more details on all of the shortcomings I’ve encountered so far).  I’m hopeful that Linux/BSD support for Bluetooth, the SD card and sound will improve in the near future, but the current problems with those drivers, combined with all of the other issues (especially the trackpad), currently make this a very frustrating laptop to try and use as your main machine.  Save your money, pay a little more and get something usable from one of the mainstream makers, instead.

And for anyone interested, the output from “dmesg” on the T-bao R8 while running ElementaryOS 4.1 is available here.

Next, we’ll look at getting Linux (Elementary OS) onto the T-bao R8…


An interesting new Sonoff (ITEAD) product on the way

Browsing through the wiki pages on the ITEAD site is always a good way to pass a few idle minutes and usually rewards the curious reader with interesting stuff (like schematics, for instance) which ITEAD are kind enough to publish for our edification.  Sonoff 433MHz to WiFi bridge, block diagramToday’s snippet was some information on what looks like an as-yet unannounced product, a WiFi to 433MHz gateway module.  The schematic shows this as an ESP8266-based unit, but there’s no separate flash memory chip that I can see and the block diagram refers to an ESP8285 (shame!).  There are both transmitter and receiver sections on the 433MHz side and it appears to use an EFM8BB1 “Busy Bee” 8-bit microcontroller to interface between the 433MHz RX/TX section and the ESP UART, with what looks like a slide switch (S2 on the diagram) to disconnect the Busy Bee to allow for programming of the ESP.  The device itself receives external power via a micro-USB socket.

Depending upon the price (and ITEAD prices are usually pretty reasonable) and the range of the 433MHz components, this could be a neat little device to have around. Front and back views (photo courtesy of ITEAD) It’s not just all of those older 433MHz switch modules that have been available for years, but also the slew of devices which just transmit (doorbells, weather stations, window interlocks, etc).  There does seem to be a four device limit on the number of remote 433MHz modules supported by the stock firmware though, according to the User’s Guide.

Update – ITEAD have just sent out a “Mid-Year Carnival Sale” promotion which features this unit (with the photo above) but, bizarrely for a sale, without a price.

Update 8th Aug 2017 – The main sales page is available on ITEAD’s site now and, for a time anyway, the unit is available at an introductory price of $9.90 (down from $12.90).  There are some clarifications of the details too, with the supported device limits being shown as “up to sixteen 433MHz RF devices” or “up to four 1-4 button 433MHz RF Remotes” (so basically 16 addressable channels).

As expected, Theo isn’t far behind and Sonoff-TASMOTA has had support for the 433MHz RF Bridge incorporated since the 5.5.0 version (released on July 30th), with further updates to the code added in v5.5.1.

Save power by (reliably) switching the ESP WiFi on and off

-Update Oct 2017-  Doug Elliot very kindly submitted a comment (see below) to let me know that the redoubtable Erik Bakke has done a much better job at both troubleshooting and writing up this issue in a series of articles on his blog.  Rather than wasting your time with my half-hearted fumbling around, I’ll point you directly to the first article in Erik’s series.  Stay with it and read the whole bunch right through to the end; he keeps on coming up with new tweaks as he goes along.  There are a couple of extra articles (one on eliminating network scan at start-up and another on solar power for the ESP8266) which are part of the series, so don’t miss them, either.

I have an ongoing project to add an ESP8266 to a solar trickle charger for a lead-acid battery.  Really, the only set-in-concrete requirement is that the controller must switch off the feed from the solar panel before the battery voltage gets to dangerous (“gassing”) levels, but it would be nice to have remote data logging of voltages (battery and solar) and temperature, as well as some control over the load (a small impeller pump in an external sump well, used for orchard irrigation during the summer and autumn).

Because the target battery is a standard (wet plate) car battery, I have quite a bit of capacity to play with, but even so, my back-of-the-envelope calculations show that the ESP8266 is quite capable of completely discharging the battery in under a week (assuming no sunshine and an ESP8266 module with WiFi enabled and transmitting on a more or less continuous basis), so I’d been looking for a reliable way to save power, but still have the ESP8266 do real time monitoring of the battery and solar voltages and interrupt the charge process when the battery was already fully charged (I should probably note that we get a lot of sunshine here during the summer and autumn months and our usage of the pump is only very intermittent, so despite having a mere 300mA output from the solar panel, it is possible to overcharge the battery over time).

I didn’t want to use deep-sleep mode (although it’s the least power hungry), because I want the ESP to be the actual charge controller and it can’t do that if it’s off in la-la land for the best part of its day.  I still want to use the WiFi capability (otherwise there’d be little point in using the ESP over a PIC), but I don’t need to have 24/7 connectivity.  Turning the WiFi on and off has always been a bit of a hit and miss business for me, though (and with quite a few other people too, judging by the number of hits a web search on the subject generates).  So I was pleasantly surprised to find some answers in a GitHub “issue” raised against the ESP8266/Arduino project.  The thread contained some excellent answers and testing experiences from some of the well known members of the ESP8266 community (thanks guys!), so I felt fairly sure I was onto a winner, but there were one or two twists along the way.  So here is a brief rundown on how I’m doing it with those kinks ironed out and here is a program which will demonstrate the practicality and reliability of using the “Issue 644” method.

First, let me assure the nervous reader that, despite what follows, we are not putting the ESP to sleep at all, we do not need to use an interrupt or a reset to restart the WiFi and we also do not need to make any hardware changes to the ESP module for this method to work.

The crux of this method is to use WiFi.forceSleepBegin() to put the ESP into “modem sleep” mode.  It’s important to realize that this does not put the core into any form of sleep; it simply turns the modem (radio) off.  There are some other incantations in there to ensure that WiFi is shut down in  an orderly fashion:-

bool WiFi_Off() {

One of the issues at this point though, is that the WiFi can take a finite, but variable time to shut down after the final forceSleepBegin() call, so at this point I’ve just added a timeout loop, checking the status of the connection until it goes down (returning without an error) or times out (returning with an error):-

while ((WiFi.status() == WL_CONNECTED)
&& (conn_tries++ < WIFI_RETRIES)) {
#ifdef DEBUG
if (WiFi.status() != WL_CONNECTED)
return (true);
return (false);

The default timeout of 3 seconds is more than enough for the WiFi_Off() function.

The WiFi_On() function is pretty much a reversal of the “off” code:-

bool WiFi_On() {
conn_tries = 0;


while ((WiFi.status() != WL_CONNECTED)
&& (conn_tries++ < WIFI_RETRIES)) {
#ifdef DEBUG
if (WiFi.status() == WL_CONNECTED)
return (true);
return (false);

The call to “wifi_station_connect()” seems to be the equivalent of a sacrificial chicken for most people, though. Without it, the restart of the WiFi doesn’t always work; with it, everything is hunky-dory (whatever that means).

Unfortunately, actually getting the call to wifi_station_connect() to compile turned out to be a bit problematic for me (from within the PlatformIO build environment). Just where the heck is it? Well, some searching found a define for it in the user_interface.h file in Espressif’s SDK. Adding a simple:-

#include "user_interface.h"

…in the header of my ESP_Power_Save.ino file got me past the initial “not found” messages, but then, at the last stage, the linker failed with “undefined reference” errors. Grrrr! The magic sauce for that though, is simply to let the C++ compiler know that it’s looking for a plain C function (buried deep in the nether regions of the Espressif SDK, in this case) by modifying that include to be:-

extern "C" {
#include "user_interface.h"

Finally, it compiled …and worked, too.

Before you flash ESP_Power_Save.ino to your ESP8266, you’ll need to configure the IP addresses, access-point SSID and password in the user_config.h file.

After flashing, connect to the ESP8266 console as normal and you’ll find yourself in a mini test environment where you can use a few simple, single character commands:-

  • “w” — to toggle the state of the WiFi between on and off.
  • “s” — to display the current state of the WiFi connection.
  • “c” — to display a simple count on the console, just to prove that the ESP core is still operational.

I’d recommend opening a second window and using it to ping the ESP’s IP address, to verify whether it is up or not as you toggle the WiFi.

Finally, a word of caution …If you try to connect to a non-existent access-point, or one which is out of range, or you use an incorrect password, then the WiFi will not turn off. That seems pretty counter-intuitive to me and I haven’t yet worked out why it happens. At any rate, it’s obviously worth doing some testing (I use a hand-held ESP8266 rig running on three AA batteries) to make sure that you have connectivity before deploying this power-save code to your remote units.

Update — The latest version of the code now includes a cut-down version of the “FSWebServer” example (from the ESP8266WebServer library) which will server up a 750kB JPEG file from SPIFFS on the ESP.  It takes a non-trivial amount of time for the little ESP to retrieve such a substantial file from SPIFFS, chunk it up and push it out across the network, which hopefully will give you adequate time to measure the current consumption of your module while busy transmitting, for comparison with when the WiFi is toggled to the “off” state.

Update #2 –  Real world testing has brought some interesting “features” to light.  Most problematical is that the WiFi doesn’t seem to always switch off completely, which is peculiar.

First, you need to know that the ESP8266 returns its current status when interrogated with the WiFi.printDiag() request.  When running normally, the results look something like this:-

Mode: STA
PHY mode: N
Channel: 11
AP id: 0
Status: 5
Auto connect: 1
SSID (9): Mainwaring
Passphrase (10): D0ntPan1c!
BSSID set: 0

The two most important indicators are the Mode and Status lines (although the SSID and Passphrase entries will also change when the WiFi is disabled).

The current draw on  my test module is generally in the area of 75ma when WiFi is enabled, with very brief peaks when actually transmitting (so brief that they’re impossible to measure with an ordinary digital multimeter).  That value drops off to 20ma when the WiFi is disabled and at the same time, WiFi.printDiag() changes to show “Mode: NULL” and “Status: 255” (and the module stops servicing web requests or even  a simple “ping”).

Frequently, toggling the WiFi (with the “w” command) will give the same result in terms of connectivity (ie:- the unit stops responding to web requests or pings) and the result of a WiFi.printDiag() is still “Mode: NULL” and “Status: 255”, but the current draw remains in the 75ma region.  I suspected that the auto-connect or auto-reconnect settings may have been responsible, but after further testing that doesn’t seem to be the case.

So, after using the word “reliably” in the title of this post (which, admittedly, referred specifically to being able to turn WiFi back on after a modem sleep), I now find that the current reduction isn’t reliable at all.  Does anyone have any ideas?

Killer (ESP8266) Apps for the Weekend

Sometimes, while browsing GitHub for ESP8266-related projects, I come across a user’s page which just happens to “push all the right (ESP8266) buttons” for me.  One which I came across recently was from martin-ger and he has several projects which tickle my fancy.

Those three should keep you amused over the weekend and give you a sample of what Martin is capable of.  Definitely a page worth bookmarking!



Adding an Ethernet Port to your ESP32

Frank Sautter has an interesting post on his blog on adding a physical ethernet connector to an ESP32 development board.  The board he chose was the Waveshare LAN8720 and, apart from Frank Sautter's LAN8720 Adapter Boardone gotcha with GPIO0 during resets, it appears to be a fairly simple build.  The LAN8720 already has (some!) support from Espressif, so this seems like a nice, easy and relatively cheap way to build yourself a WiFi-to-Ethernet gateway.

Frank has detailed the connections for his adapter board and included a nice bottom view (left), so that it should be fairly easy to duplicate his build.  The LAN8720 boards themselves are currently available on eBay for about $3 each.


Olimex Updates

Back in February I wrote about the Olimex ESP32-EVB board, which looked like an exciting development in the ESP32 world.  Well, Olimex have posted a remarkably frank update on the progress of the EVB on their own blog, saying of the initial revision that “[it had] too many errors” and that they had “decided to trash it and just move forward to revision B”.  Olimex ESP32 Dev BoardThe problems apparently included non-functional ethernet and missing pull-ups (Olimex assumed they were already included on the ESP32 module, when in fact they weren’t).

The updated, rev-B version is well underway and the aforementioned blog has some interesting back-and-forth in the comments section regarding the choice of ethernet controller and other design issues.

The latest news on rev-B is that it has automatic programming mode via the USB connector (ala NodeMCU), a new IR transmitter/receiver and an additional CAN bus.  One of the “user” buttons has been removed, as there’s now no free GPIO to handle it due to the new features just mentioned.

All in all, an interesting insight into the evolution of a new product.