Category Archives: ESP8266

A good day

Today has been a good day. After a great Saturday down at Castril (waterfalls etc – fantastic weather) Aidan and I sat down with some wine to test his new movement sensor/smoke detector board. As is often the case the first iteration has some issues but I’m sure it won’t be long before I do a write-up  in here. We have a 3d printed box and it is now sitting on my wall. In the process we found some bugs in the home control 2016 code – to do with reading the state of inputs and sending relevant MQTT messages – all sorted now so that I have Node-Red waiting for input from the movement sensor and turning lights on, on timers. All the code and the OTA (which works wonderfully) is now updated. See the relevant blog items.

In the process I’ve realised (and you’ll note I’ve recently been upgrading even ESP-01s to 4Mbytes of FLASH) that OTA is a FAR better way than flashing boards – as you don’t even have to dismantle installations – or worry about turning off the serial terminal before programming boards  - just issue an OTA command and you’re off.  We’ve been making ourselves a little Python code to copy the OTA files across to the web server so that as soon as the code is updated in ECLIPSE – a single button-press makes the ROMS available to others.  Lots of updates tonight and the manual is being kept updated also.

CHIP[1]Meanwhile in the process of doing this I had a need to send information from one page to another in Node-Red and the new LINK modes work just superbly for that (you need to update Node-Red if it is more than a few weeks old). I’ve now updated several Node-Red installations without a hitch.

Meanwhile as Aidan was coming over from the UK he’s brought me some supplies here in Spain – a super new keyboard – a “Tecknet” which glows blue, red or purple as needed and which has sprung keys and laser engraving. It’s like a breath of fresh air.

I’m expecting BananaPi M2 as well as FriendlyArm new boards in the near future… right now I still have a problem with the FriendlyArm NanoPC T3 – it’s a wonderful board but for the life of me I can’t get the Android installation to work other than in the 8GB image – which leaves almost nothing to work with. I plan to put a 32GB USB drive in there and want a full 32GB installation.

ChipAidan has also brought me a CHIP board (seen above) – and I’ll be looking at that in a future article – it is really neat, quite small and the setup is ridiculously simple. Ok it isn’t the fastest processor in the world but  we’ve had Mosquitto running on it and in the process I even learned how to use the venerable VI editor! Like many boards it claims to show itself up by name on the network – and like most of them this just does NOT happen on Windows 10 at least – but again like most, the line I added to the install script:

sudo apt-get install samba samba-common samba-common-bin winbind

works every time and now I can just access it in VNC as chip:1

Chip has some smile-producing features one of which is a battery connector – so to test – just plug in a cheap battery using a standard connector. Now imagine you are communicating with it via VNC – and the power to the unit fails – makes no difference at all, just keeps on ticking with its wireless connection. Of course you can do this with loads of board but most of them need a complete battery backup system which we’ve discussed successfully in this blog recently – in the case of the Chip – nothing more than a battery is required.

No issues with the updated ESP8266s with the new ROMS discussed a couple of days ago – they work perfectly as you might hope. I’ve run out of the FLASH chips now now and sent off for some more to China (2-3 weeks). I’ve been thinking about how to use the extra 2MB RAM – I looked a SPIFFS but it is WAY too complicated and at least the original code would fail for me as I’m running short of IRAM so I’m thinking how I may create a simple system.  You have to write in 4K blocks as I understand – which could prove an issue as I’m not sure I have 4K of RAM left to form a write-buffer. More on that next week as I start experimenting.


Home Control Updates

For those following the home control project including the ROMS for ESP8266, I’ve made several changes in the last few days including a new uptime command {uptime?} returning a string of the time since last reset/power-cycle. Also added that to the debug output – also fixed a couple of minor RGB issues. Source code now works with very latest SDK from Espressif

If none of this means anything to you see:


ESP8266 and Nextion Updates

This one will be on-going.. so the plan was to write a blog about the latest version of our little ESP-12 board and it working with the new Nextion display board.

But as happens in life from time to time, it all went wrong at the Nextion end. However…

BoardOur board: We have updated our little ESP8266 board. Minor to be sure – we’ve added the ability to use an RGB serial LED as the indicator and some other minor items like fixing a missing track on the RGB LED. This board works – no cut tracks, no extra wires  - it is absolutely bang-on. In the image to the right you can see the RGB LED bottom left (LED2), extra grounds (bottom) compared to the last model but one – and of course the DHT22 connector introduced in the last revision.

The adc divider is now on the underside of the board and the “adc-div” is around 4k7 for 20v peak – I use it to measure battery voltage. for software see the home control 2016 project in this blog.

The files for this board are here including Eagle and images for viewing.

The Nextion: I received the latest board from iTead, the NX4024K032_11 which is supposed to be faster and better than the old model Nextions (which, for those reading this freshly – are touch-sensitive serial display boards suitable for a wide range of projects) and I updated the Nextion editor to the latest version.

I had a little difficulty at first because their downloadable editor now insists you tell it the exact model of board – I’d not seen that before. So off I went and made a display with a single button which would send back “Hello” when pressed.

Took me a couple of attempts as I had the serial wiring the wrong way around – anyway, eventually I did the update.  It did not seem to be returning quite what I’d imagined it would so I went in to make changes in the editor. This time around, I could not blow the update. The editor kept coming back saying “Forced interrupt!” no matter what I did. As it happens I have a virgin older design of board – the NX3224T024 – I did the same thing -  and lo – THAT is now dead. I’ve written to the designers and am awaiting an answer, nothing in the last couple of days and I’ve seen others with this problem. Right now the only way to get around it is to put the compiled file from the Nextion editor into an SD card, insert that into the Nextion board and apply power at which point it copies the image across. A LOT faster than using serial but then a lot more messy if you are making frequent changes. On the other hand it means I don’t have to keep disconnecting the board from our test board.

What can I say, everything works as it should do – our board can send commands to the Nextion display and accept input back. For test conditions I set our board to serial2 at 56k {set_serial:2} and created a blank template on the Nextion with 2 buttons – one of which has the pressed command get “nodered~up” and the other get “nodered~down”.  When our board sees incoming with a tilde – it splits the string into two – i.e.  topic and payload – and hence sends a message up or down to the topic nodered via MQTT - easily picked up in Node-Red by the MQTT node.

So no surprises – all works – I did spot a minor error in my manual for the “to_nextion” command – now fixed. So all tested – both old and new Nextion boards, able to both send and receive info to the little blue board.



After a slight hiccup with the new board (LED track missing) here’s the new board  – link for PCB here – as you can see, Aidan has made several improvements – smaller buttons, connector for DHT22 etc, markings for I2c (right now I only have support for the 8-output expander discussed elsewhere but more will follow as time permits) and general tidy up. Both the original LED and the new RGB LED are included – personally I find coloured lights for status a lot more useful than a flashing light – but of course they can use more power. As well as the LCD project this board has become a general purpose ESP-12 board and I now would not use any other.  We’ve not wasted cost putting USB on it because FTDIs are cheap and that reduces the end cost of the board.   The link above has all the files – please note we’ve NOT had delivery of these, the previous version was almost the same and works but for a track on the WS2812b.. so it is highly likely this board will be just fine – will be a couple of weeks or so before we know (delivery from China) and another week before I get my hands on one (Aidan is in the UK, I’m in Spain). The I2C markings are just to make it easier to remember which pins you use – we didn’t have enough room for yet another 4-way connector. If you are looking in for the first time – see the Nextion WIFI Display blog and the Home Control 2016 blog.

I’ll be trying this out on a brand new Nextion board I just received (faster processor I think – not tested yet – will blog when I do) along with some other stuff from Itead

Enjoy. For my next trick – a new board from SEEED…. review coming up later.




Remote checking Home Control Units

Those of you who are aware of the Home Control project (Home Control 2016) will know that the software/hardware combination of a Raspberry Pi (running Jessie, Node-Red, SQLite and Mosquitto) and ESP12 (running the software described in the Home Control project) is proving very reliable – but there are occasions when you may wish to be absolutely sure that units are actually doing something.  One way to do that is simply to put timeouts on every response you expect… but that makes for complicated coding. A simpler way is to regularly ask each unit for the status of one of the outputs. It doesn’t matter what the response is, as long as there is a response.

As it happens I’m having an issue right now – the heating controller part of my system back home in the UK is working perfectly except of an on-going issue with Plusnet broadband. They are denying it is their fault but the broadband fails perhaps once a day, maybe more, maybe once every two days but eventually it will fail. Most of the time the TP-Link TD-9980 router reconnects within a minute or so – but for reasons I don’t yet understand, occasionally it just will not reconnect. The solution to that was simple and two-fold, a standard timer which turns the router off for a minute in the early hours every day. That’s the “belt and braces” approach. In addition, the Raspberry Pi is polling Google every few minutes. If it fails totally over a 15 minute period to contact Google, an ESP8266 unit will reboot the router.

All of this worked perfectly for several days and then… the heating relay ESP8266 refused to log back in after one of these “cuts”. I can only put it down to being right on the edge of signal. The reason I say that is that late last year we had horrendous problems with WIFI here in Spain, some kind of attack. It went away but during that time over several days I was losing WIFI constantly so I made damned sure the ESP units would reliable log back in, in the event of temporary failure of MQTT or WIFI or both etc. And yet just occasionally this particular unit will not log back in – a power cycle fixes the problem but that means I need to know about it and ask someone to pull the plug for a moment.

So – I’ve implemented this for the two most important devices in the building – the main heating temperature sensor – and the ESP that controls the relay to turn the heating on and off.


Timeout NodeWhat you see above is as follows: 2 Node-Red “inject” nodes (standard) fire out requests every 5 minutes to MQTT to ask the relay and temperature units for the state of output 0. 

Which command is irrelevant as long as it is a query which returns a result and otherwise has no effect on anything.  So for example with a topic holly1/toesp and a payload of {out0?} the system is expecting a response of OFF or ON (irrelevant here) from topic holly1/fromesp/out0

The two incoming MQTT nodes (left, purple) pick up on the response and feed them into my “timeout” nodes  (node-red-contrib-timeout).

As you’ll see below, the operation is simple – the timeout node doesn’t care what is incoming as long as something is. if it gets nothing for 60 minutes it will time out and send a payload out – in this case thanks to the standard email node (green) an email to me. 

During that time, normally, the MQTT nodes would have responded every 5 minutes – ie 20 times, topping the timeout node up to 3600 seconds even if most of the messages were missing (and there is no reason why any should be missing).  In this case I’ve not put messages for “safe state” or “warning” – so nothing goes out unless the timeout actually runs down to zero.

Click on any of these images for larger versions.

So while this does not solve the problem, it does mean that I’m alerted to the issue and can ask someone to disconnect and reconnect the relay unit. With what has been 100% reliability of Raspberry Pi 2 boards (with a decent Samsung microSD or similar) I can be pretty sure I’ll get an email if something goes wrong.

I hope this proves useful to others.


Home Control and Nextion Updates

Just a brief update. Thanks to some feedback I was prompted to see if it is possible in the home control project to get feedback as to the state of an output on the same line as controlling it.

hapticSo for payloads you might use {out12:1} to turn on GPIO12 and {out12?} to get feedback – well you can simply join them together as such into one message:


Also on the subject of haptic feedback when using the software for a Nextion display, put a haptic feedback device onto GPIO12. I used these:

In the last couple of days I’ve updated the manual and the software to make the responses more consistent.

Nextion WIFI Touch Display project:  Reader John was trying to send a string to the Nextion display from my software and I said I’d check…

So having put the unit into Nextion mode by sending the relevant command {set_serial:2}  which then reboots the unit….  I sent this command… {to_nextion:"t0.txt=\"Hi there\""} and here is the result coming out of GPIO4 or GPIO5 depending on the labelling on your board….

You can click on the image for a larger version but if you refer to the bottom right – you’ll see the message has been picked up by the logic analyser and it is fully intact with the three FF bytes inserted on the end for the Nextion display.

Logic analyser

As a result of this I realised I was not parsing \r\n properly – not that they are needed for anything I’m doing – and these are now implemented in the latest update (1.3.4 at the time of writing)



Status update

GaleraIt may seem like I’ve been quite the past week – but having arrived safely in Spain we’ve had lots to do.  However I have done some updates to the “home control 2016” blog entry as I’ve implemented some fixes to the node-red-contrib-esplogin node.

For those of you unfamiliar with this – the idea is a node-red node that updates a bunch of ESP8266 modules with time and date info as well as dusk and dawn timings. It does this on power-up of Node-Red, on demand from individual units and every 12 hours – except it wasn’t doing it every 12 hours. It is now. Here’s the link for those interested. The node itself also now has much better status information and help.

cludgeMeanwhile I’ve been struggling with rubbish broadband back home in England as the router failed every now and then to reconnect. Aidan and I have implemented a solution using one of the ESP8266 modules which will check Google every minute and if it gets nothing for 10 minutes will reboot the router.

new layoutAidan is working on a new version of the home control board with a couple of minor improvements – the connection for a Dallas temperature chip is now a 4-pin job suitable for the Dallas chip or the DHT-22 and we’re also putting on-board an optional RGB serial LED as the status LED on the board uses all sorts of flashing convolutions to indicate state and we thought it might be nice to use colours instead. There  is still a question mark over simultaneously using PWM and sending serial data to LEDs and that is being tested right now.

There’s a significant update to the ESP8266 source(home control 2016 project etc.) as I fixed a minor silly in my watering system code. and added a load of improvements including a serial RGB indicator LED

Meanwhile I’m sitting here on the edge of my seat waiting for a new Nikon camera to arrive so I can make best use of the excellent weather out here in Andalusia.


North East Maker Faire 2016

peepsI could not be there at the Maker Faire UK in the Centre for Life in Newcastle – but thanks to my spies – it’s great to see so many people there.

Apparently this couple on the left are into ESP8266 and got some ideas from the blog.  Glad you like it guys and sorry I could not be there. Understand you had a chat with Aidan.

Hope everyone there is having a great time – let us know if you’re looking in.

Meanwhile I’m in and settled in Spain – spent the whole day updating software (and more to go as in many of my older boards there was no OTA software.  Just cracked the problems I was having with PWM on the ESP software and so the repository now along with the .BIN file I made available are all updated. 

And now, while the sun is shining (and it is 23c outside) I’m off to update the rest of my boards.


Simple Serial Terminal lost blog

For reasons beyond me the original article on my serial terminal, originally put together when I was messing with LUA, has disappeared from the blog entirely – and so here’s a quickly updated version with DropBox link.

Serial Terminal

So above right you should see the editor. The most important bits are the two big windows – on the left is the area you type in – multi line – and on the right is the output from the serial line – i.e. what comes back from the chip. In the simplest case you set up the serial port you want, ensure it’s set to the right baud rate, select “serial – open” and you’re all set (I’m assuming you have an FTDI or similar on your USB lead, talking to the serial on the ESP8266 device. You can send all of that out the serial line – or just a selected area or indeed whatever is in your clipboard. Also you can define up to 10 pages of info (Notepads) and send that – in addition you have up to 9 presets – handy for initialisation sequences. Oh and you can save the left panel into a file if you want.

Whatever you type in the left window is non-volatile, i.e. it’ll still be there after you blow up your serial port and have to reboot the computer.

Disclaimer: if any of the above or the use of the terminal breaks your computer, it’s not my fault. I’m providing this freely just because I’ve no reason not to but without support. You just need the exe file for this… PetesSerialTerminal.EXE and note that Windows XP is not supported.

So let’s take a look at the top first. I have deliberately kept this as clean and simple looking as possible as you really just want to get on with coding and not worry about some pesky program – but there are some basics if you want to make good use of this. The file system is easy enough – you might want to store what’s in your left window – your latest all-singing routine or just a bunch of nonsense – that’s up to you hence file – save. Find a suitable directory to store your stuff – the dialog is bog-standard. For retrieval – you have two options, load and append. The former will overwrite what’s in the window, the latter will append to what’s there – so you can store a load of routines and build up something new the easy way.

Serial is even simpler – open or close the port. When open you’ll find some controls don’t work – like changing the baud rate for example.

Notepad is interesting…yes, no less than 10 pretty coloured notepads (non-volatile) to store snippets in – nothing clever about these, you can just copy and paste to and from them in the normal way.

notepadsI normally have several projects going on and find it handy to have stuff lying around – this beats yellow sticky notes full of code any day. There’s a big CLOSE button at the bottom to hide these.

Clear- well you can clear the notepads or your left or right windows – and help – well it’s a picture of me – the idea of writing a complete help system for this just filled me with horror.

So down at the BOTTOM of the screen… assuming you have the serial all turned on you can “Send Window” – i.e. send the contents of your left window off to the serial port – it will send it one line at a time with a delay between each line specified at the top right in milliseconds, defaulting to 400ms – but whatever works for you.

I’ve coloured the individual panels just to try to help for when you’re in a hurry – I tried to colour the tabs but Microsoft isn’t having any of it up to now.

If you select some text in the normal way in that left panel you can press the “Send Selected” button and only send the stuff that is highlighted – OR you can “copy” from just about anywhere and send whatever is in your clipboard… that’s awfully handy.

Then there are those notes.. N1 to 10 let you send the entire contents of any of those notepads.  Finally there is a one-line window which you can send directly with the “Direct” button.

To the right there are some presets, 9 in all – and in SETTINGS you can define their names and what gets sent out.  And that takes us to settings.

settingsFirstly you’ll see the 9 preset buttons – their titles and contents – note you DO have to press OK to save these in SETTINGS – most things outside of this SETTINGS box just save automatically. Auto prefix and suffix I suggest you leave be unless you’re NOT messing with Lua and the “Auto prefix/Suffix” tickbox determines whether or not you use this – essentially if “” is see starting at the LEFTMOST character in your input window, these prefix/suffix characters will be added to your line as they are being sent out until the system sees a “File.close” again starting in the leftmost column of your input window.

“Arduino DTR” – well that’s for those of you who want to use this terminal with your Arduinos (you may be working with the Espressif AT firmware for example)  – that’s the bit that resets them when you open the port. It just flicks the DTR line temporarily on open – nothing more. Autoclear – tick that and you’ll see the right window cleared every time you press the send button – just preference really. Lua comment removal is turned on by default (—) – you can turned if off – and “Retain blank lines” is new, just something for the future. Normally, most blank lines never make it to the right window.

And that is that, really – nothing much else to tell you about the program – I hope you find it useful – I have – and no doubt I’ll add more in time.

Here’s the Dropbox link (Updated September 18, 2016)  –


Blowing the Home Control 2016 Code

Hackitt and BodgittThis is for the people who’ve been trying out my software (or thinking of trying it out) on the ridiculously cheap (£1.40) but very reliable, powerful and comprehensive ESP12 WIFI processor board and those who’ve gone ahead and gotten some boards we made – all referenced in earlier blogs. For the latest on how to FLASH the chips see this blog update.

Essentially the assumption here is that you have an ESP-12F-based )(or variation such as ESP-12E) board of some description and that GPIO0 is used as a programming button (held to ground to program etc) – and also as a web setup button.

Let me explain the difference between programming and setup. GPIO0 is set up permanently by Espressif as the pin to hold LOW before and during power-up to put the board into programming mode to replace the firmware (which may or may not exist on purchase… could be that AT-Command firmware, LUA or something else). Web setup is just something my software does – it’s not the only software to do so. It may use GPIO2 or GPIO0 AFTER power-up to put the unit into a mode where it acts as an access point, allowing setup for, for example SSID and password.

All other I/O pins are available for one use or another including GPIO16 – take note of other blogs describing wiring and power unless you’re using something like a node-mcu board which just plugs into USB. The software works with my Node-Red software – again described in the home control blog – what’s new here is that OTA now works and you don’t need a development environment to program up the code which  I developed with lots of help from others, using the unofficial Development Kit in Windows. The software will react to MQTT commands and also commands coming into the serial line at 115k baud (serial commands are the same as MQTT payloads - no topic required). - home controlI worked with Richard Burton to get RBOOT working on our code– it is his software which allows for OTA (remote updating) when developing, in my case, in C on the ESP8266.

With OTA working (including from an external location) I thought I might try taking the ROMS and blowing a chip from them rather than from the editing system – that way others can benefit.


Well, I went to get the NODEMCU flasher which was always good – so after a couple of blind alleys – I got to this link..

As you can see, with the flasher, the RBOOT rom loads at 0x00000 and our current code runs at 0x02000. Unlike me, make sure BOTH ROMs are ticked on the left.. as the first one is so short it shows little or no sign of activity. I found I could flash at 46800 baud, you may or may not wish to play safe at 115k baud.  You may also note there is an additional file needed above – in SDK 2.0 and above, on first installation this is needed. See THIS blog entry for up to date information.

So – you blow the software onto the ESP8266 board (here is the link to the NodeMCU – no guarantees as it isn’t mine), now what?

A reminder – what will my software do?

  • Turn outputs on and off with optional timeouts
  • Read inputs
  • Handle RGB Serial LEDs (up to 300 of them assuming you have enough 5v power)
  • Handle PWM 12v LEDs (assuming you have a 12v source and driver hardware such as Mosfets)
  • Act as a LED clock (and a nice one too) with 60 serial LEDs.
  • a TON of other things including handling DS18B20, DHT11, DHT22, talking to Nextion displays (see the Serial Nextion blog) and WAY more – all in the Home Control blog. Add to that the power of Node-Red and you have the basis for a very good and reliable complete home control system.

But first the unit needs to be setup. After programming and then resetting or power-cycling the ESP12 (suggest hooking a LED and resistor to GPIO13 and down to ground) – the light will start flashing – within a second or so – hold GPIO0 (or GPIO2 depending on defaults in the current ROMS – see power-up messages coming out of the serial at 115k baud)  to ground for say 10 seconds and let go (DON’T press for the first 100ms of turning on – JUST after turning on or resetting will do – if you come in early (and if the current pin in use is GPIO0)  it will go into programming mode – of course if you don’t program it, no harm done – just reset and try again).

NOW you can access the board with your mobile phone WIFI as “hack-Setup” and once connected use the phone browser to go to and you get that nice setup on the right above which needs at least one router SSID and password, two if you have them available (second is a backup) – the address of an MQTT broker and username and password and that’s really all that is essential to start off.

Once everything is up and running , the LED on GPIO13 should be flashing very briefly (i.e. off most of the time) – a variation you can setup by commands uses an RGB LED to give more meaningful use (yellow power up, green working, orange working on it, red dead – throw in the bin etc).

You can now talk to the board via MQTT… or the serial port at 11500 baud (you could use my serial terminal.

If using the serial, fire {debug} at it – if using MQTT – then assuming you’ve given it the name “fred” then the same command would be – topic:  fred/toesp and the payload would be {out4;1} or {out4:0} to flick GPIO4 on or off (or if your board is mis-labelled as some are – GPIO5).   The Home Control blog entry goes into the rest of this in detail.

Note that if you DON’T set up an MQTT broker, the unit will try to connect to MQTT and eventually reset and start again. This is deliberate. You MUST setup an SSID, an MQTT broker and once running you should use the ESPLOGIN mode or similar to send the time to the unit shortly after power up then every 12 hours or so. Again this is detailed in the home control blog… it’s quite simple.

The rest is up to you.  I use this with my Node-Red software and I have a node for setting up the time and date on the boards…  it is called node-red-contrib-esplogin

Node-Red controls - Peter Scargill

That log-in node incidentally is available here.

That’s it for now… I’m quite chuffed the OTA now works. This of course is directly relevant to the Nextion WIFI Display project.

You can get the three BIN files from:

IMPORTANT NOTE: If you choose to use ROMS rather than compiling code, you will need to keep up with the BITBUCKET repository changes as these ROMS will be updated when I make changes – which I’ve just done having realised I need to support some older boards we made with a relay on GPIO0 whereas I’m now considering GPIO0 should be an input. There is also a DOC file in the Home Control blog and that is the ONLY up to date guide to the ever increasing instruction set.

Update 14/05/2016:  No longer showing passwords in the web setup page so you must put those in every time you use the setup page – otherwise you end up with blank passwords – which you might want. Added several new commands like cpu_clock so you can double the clock speed  - documented… ROM updated. DEFAULT pin for web updating is generally GPIO2 but on power up you’ll see serial messages which TELL you which pin to use. You can change this to GPIO14.

Update 24/07/2016:  See the changes in blog above, rendering some of the comments below obsolete.