ESP8266 MQTT Publications

The PlanIn my last blog I referred to publishing temperature etc and there is one issue with the existing MQTT library that makes that an issue: The MQTT publications are not queued.

For the benefit of anyone still not into the MQTT thing – by publications I mean “sending a message” comprising a topic and a message. The topic might be “BathroomTemperatureReading” and the message might be “20.6”.

What happens right now – and Tuan has said he’ll fix this… if you send 2 messages out in a row IMMEDIATELY after each other – only the last one will go. Well, that’s fine unless you have to send one message off to a thermometer display and another message off to a humidity display.

So… this evening I wrote a queue. This is possible because of a “callback routine”. When you fire a message off it is handled in the background and when it’s done it calls an empty routine. I’ve trapped that.. the basic idea is this.  

Clear a “done” flag at the start and from there on..

If the done flag is clear, set it and send out a publication. If it is NOT clear, put the message in a queue.

In the callback routine, clear the flag – check a queue, if there is anything to go – send out the publication.

Simple really.

So here’s the code I’ve added to the start of the MQTT package..

#define QUEMAX 10  // 10 messages -  need more? – increase
#define QUESIZE 50 // my topics and messages are never more than 50 chars
struct Queues{
    MQTT_Client* cli;
    char top[QUESIZE];
    char mes[QUESIZE];

struct Queues myQueue[QUEMAX];

int queuein=0;
int queueout=0;
int isPublished=0; // my flag to see if I can publish or need to put in a queue

All simple enough – the queue can be maximum 10 deep (it’s rotary – when I get to the end I roll around to the start). I save the client pointer, the topic text and the message text in an array of simple structs.

At the beginning both the in pointer and out pointers for the queue are cleared and isPublished is clear.

Instead of the main publish routine – I have my own – which checks the flag before sending off a message.

void petesPub(MQTT_Client* cli, char *top, char *mes)
if (isPublished==0)    { isPublished=1; MQTT_Publish(cli, top,mes,strlen(mes), 0, 0); }
    if (++queuein>=QUEMAX) queuein=0;

You can see the message going in the queue unless the flag is clear… and in the callback routine, called when a message has gone…

void mqttPublishedCb(uint32_t *args)
    MQTT_Client* client = (MQTT_Client*)args;
    INFO("MQTT: Published\r\n");
    if (queuein!=queueout)
        if (++queueout>=QUEMAX) queueout=0;

The first two lines were there already – I don’t think I actually need to store the client info – I think it gets passed – however – what I have works for now.

So you can see I clear the published flag, look to see if there is anything in the queue and if there is – publish it. I’m sure there’s a bit of recursion going on there – but it all works.

And that’s me done for the day. Meetings again this week so I’ll not get much more done now until the weekend but DHT22, RTC and message queue – not a bad start for the week.

I’m still begging anyone with assembly skills to look at the WS2812B code to see if they can make an accurate job of it Smile

ESP8266 Memory Usage

debugGlen Cook has just made a neat little utility for checking the amount of RAM in Eclipse projects…  here’s the output – and there’s a link below – contact Glen, not me for more info.

Part of the problem of working with new processors – is understanding what is being used and where.  I look forward to seeing a visual version of this with used RAM, FLASH etc. and showing what’s used and what’s left. It would not be the first time I’ve run out of RAM.

Also linked to on my ESP8266 Facebook page.

Does anyone know the significance of the IRAM (initialised RAM) as in one project I’m down to 800 bytes – while having 38K of general RAM left.

ESP8266 and RB Serial LEDS

rgb ledsWell, it looks like everyone and their auntie have figured out how to get Arduinos to listen to ESP8266s sending out messages and control RGB serial LED strips – not surprising as there are several Arduino (and for other boards) serial libraries out there. I’m not talking about old fashioned 12v RGB strip but the more modern 5v variety with serial control, which, when (if) they get the price down, HAS to be the future of lighting.

I was at a hotel in Blackpool a few weeks ago and they’d just modernised and had the serial LED strip EVERYWHERE. If you’re not familiar with this stuff, each LED has a serial controller and can accept RGB settings – and once set can simply pass the info to the next LED. All of this is done with blindingly fast serial, so fast they build huge TV displays at airports using the stuff. Why is this stuff so much better than the old PWM red then green then blue LEDS? Because all 3 chips are in one housing you can create REALLY subtle lighting – you want daylight? No problem Tungsten? No problem? Nice warm candle-light? No problem.

Grab a strip, fasten it to an Arduino, provide plenty of 5v and a library and you’re up and running. You tell the library how many LEDS you have and it builds an array of 3 bytes for each LED. You populate the RGB info for the LEDS, call a function and BANG – they all get updated in an instant. with that array at hand it is trivial to write code to drive a colour wheel through it and by updating at regular intervals, create a moving colour change along the strip that is nothing short of stunning.

Right – that’s the easy way and also the larger and more expensive way. Now when is some clever person going to provide us with the same library (in C, not Lua please) for the ESP8266. Should not be a problem as the chip is way faster than an Arduino. I am not familiar enough with the chip to do this yet but I’m hoping someone else is – or has already done this – any takers?

Add this to the current MQTT code and you have an instant WIFI lighting controller. If antone has this or can make this I’m quite happy to put an article together – once I have my hands on a library (preferably working with GPIO0 or GPIO2 on the ESP-01 as that’s the cheapest and smallest solution out there but is pin-challenged).. it’ll take me no time to get that under message control.

Feeling MQTT Thick

Oh firstly, after filling in the form with Espressif to keep commercial confidentiality about their SDK info which I’m still waiting for – I discover it’s freely available here –  granted that IS for the 0.9.2 version which is a tad old now..

Tonight as I get ready for a round of meetings in London which will severely hamper my research until later this week, I’m struggling with MQTT-SPY. I should say I’ve had some communication with the designer and he’s been MORE than helpful  – he’s added a demo time script, he’s changed the XML format slightly so it’s readable for the likes of Notepad++ all of which is great, but I want some pre-programmed scripts to send out publications – and can I HELL figure out how to use them.  I’m hoping for an update to the WIKI on that otherwise excellent free program. If nothing else I hope to set off a script every minute to transmit the time on “/time” and I can keep an eye on it while I’m away on business to check for reliability.

I didn’t get a chance today to update the ESP-12, now that the MQTT code works so well in the Windows environment, to add port operations to that as I thought I might use a couple of pins of the board as indicators instead of all that serial info. All I want coming out of the serial is MQTT messages.

My unashamedly Windows-only ESP8266 Facebook page  is doing well and how has over 170 followers which is nice.

Not much else is new. Quite interesting that people made so much noise about the Lua interpreter code going open source – the guys did that and what’s happening? Not  a lot right now.. the Frankenstein code? Nothing for a month….   the beta of the SDK? Nothing new.  Maybe everyone’s having the week off after Christmas.

Here’s hoping for lots of new developments over the weekend. Something I don’t really understand about the Lua code – it’s constantly short of RAM – and yet, those who are trying to understand the chip say that it has a LOT more DRAM than it has RAM… so I wonder if any of that is being used.. perhaps that will remain one of life’s mysteries.

And on a completely unrelated subject – if you’ve been struggling with your old Nexus 7 (2012) – the 5.01 Android update is out -  installed it today (with a lot of wheel-re-inventing) – and.. yes, I think it speeds it up again.

ESP8266–a Way Forward

Right, it’s becoming pretty clear how this is going to develop for some of us… I’m not interested in joining someone else’s circus when it comes to home control – I want to do my own thing… but I want inexpensive mechanisms to help me do that and it’s becoming clear that MQTT as a communications mechanism is going to be part of that. It’s also clear that the ESP8266-type boards are also part of that.

So here’s where I think we are right now – but firstly I need to explain MQTT for absolute beginners before they run away:

I’ve been messing with home control over 2 years now, I wasted a year of my life on those AWFUL NRF24L01 boards which can’t even manage a single stone cottage wall and won’t send and receive at the same time. Then I moved onto better radios and even did some work with a friend on the Atmel radio processor boards – and then all of that seemed to change – the ESP8266 WIFI boards came about. Why were they better? Well first off they could use your existing WIFI infrastructure, they had excellent range, they were CHEAP – and by that let me make my position clear – I think spending £30 to turn a 50p lamp on and off is STUPID… it needs to be a LOT cheaper – like “a few quid”. When it comes to complexity – a little WIFI board on it’s own is sometimes all we should need (temperature sensor), or for a more complex item that feeding, say, an Arduino. In the past the problem has been that by the time you add Ethernet libraries and radio libraries to the Arduino you end up with almost no memory left.. and hence my use of the more powerful 1284 chips on custom boards – but that’s not REALLY the answer.. Micro-Arduino boards from China at £2 is REALLY the answer.  So a WIFI board+micro-Arduino for £4 or so – that’ll do.

The ESP-01 board is a perfectly usable board which sadly has a couple of things missing – the link for SLEEPING being one of them – the chip pins are way too small for most of us to solder and so it looks like the slightly more expensive ESP-12 might be an answer – it also has lots of FCC and other stickers to keep those people who care about such things happy.

But how do they all talk together? It seemed at first that the ESP8266 would do it all then reality set in – you can’t be a client, talking TCP/IP to a phone – AND be a web client, getting the time etc. at the SAME TIME – OH DEAR, the dream was starting to come apart. And then along came MQTT.  It’s REALLY simple… you have a machine or service somewhere called an MQTT broker and all it does is this.. everyone logs onto it with a unique name, lets say we call our devices peter and paul. Peter and paul can receive messages from the “broker” and send message – to anyone. So Peter can sent a direct message to paul. Problem solved. But it gets better.

The TOPIC system lets peter only subscribe to messages he’s interested in.  So, if Peter was an external temperature sensor he might only be interested in messages requesting the temperature.  If Paul however is a thermostat control, he might be interested in knowing what Peter’s temperature is – and what the time is . He might also want to know if he’s on PEAK time or not, or what the current requested temperature is. If this is not exciting I’m doing a piss poor job of explanation as it’s got me excited.  So whatever this protocol is it needs to be available on PCs and Linux etc., it also needs to be available on ESP8266 for those projects that use it – and on Arduino for those projects with a hardwired Ethernet connection. Well, as of around now – IT IS!

MQTT is now available on the ESP8266 but BEWARE – the author himself says this is for messing with and not yet for production – so don’t get TOO carried away – a new release came out yesterday with SSL. – my own experience is – it WORKS. I’ve had a little light sitting there dangling from a shelf, listening to the broker and responding – and it just keeps on ticking – loss of power no problem – it picks up where it left of.

But what if the little device is not on all the time – won’t it miss messages? Well no because there are 3 types of message (it’s important this is implemented in whatever you use. Type 0 message means send it and take pot luck if anyone gets it-  type 1 means they are guaranteed to get the message – but they might get it more than once. Type 2 means they will get the message for sure – once only.  This is nothing more for you to worry about than putting a number at the end of a function – 0,1 or 2.

So, let’s backtrack – that time thing. Right now I have an Arduino which calls a web page I wrote to get hte time because I don’t find NTP time servers that reliable (they get a lot of use) and they don’t send me lighting up times etc. I wrote my own PHP page sitting on a public server so I could get what I want, when I want.  And that was fine, it’s in the blog and some of you have used it… but there’s a BETTER way. Given an MQTT server and the common ability of web servers using CPANEL to allow “cron jobs” – WAY more complicated sounding than it is… imagine if I could have the ISP call that page every 15 minutes. Imagine now that the page instead of returning the time and light up times, sends that info to the BROKER!!! (As it will from sometime this afternoon until eternity). NOW the lonely thermostat ESP8266 in the kitchen doesn’t need a whole new protocol to learn – it just subscribes to that message and every 15 minutes it gets the time – SIMPLES!! But by now your ears are probably pricking.. hang on.. if I can do that then… yes, the humble web page now not only can send off the time, but a load of stuff like “lamp 4 in the living room – it’s time to turn on”. Instead of having to write a whole load of shite in a little processor you can have a password protected page on a website with TONS of terms and conditions to setup and you can update them on any old tablet and… well, I’m sure you’re writing code already.

What’s wrong with the above..

The little ESP8266 powers up for the first time, has no idea what your router is called.  So what we need is the MQTT software on the board, COMPLETE with the simplest page…. what is the router called – what is the password and what’s the address, name and password of the MQTT broker. As the ESP8266 can be it’s own access point this could all be done by a mobile phone which talks to the unit which ONLY is an access point if you pull a lead down to ground – or better – only when it actually has no information stored or the info stored does not work. Anyone up for that.

Lua allows people with no engineering degree to interact with the ESP8266 boards – and it’s very nice and there’s one fellow suggesting a way to merge MQTT and LUA – that would be great – but again BEWARE – the Lua installation WILL let you down if you get too ambitious – the implementation is unforgiving when you make mistakes and it EATS RAM.

If we could combine ALL of the above – a Lua interpreter that has it’s own web setup page – and the MQTT client software and maybe a range of temperature sensor libraries (the DHT22 is good – reliable, accurate and gives both temperature and humidity)….

BUT we won’t always be working with the ESP8266 alone – we might want it to be part of a package with an Arduino.. SO –  the unit when it receives messages should always put them out onto the serial line – maybe wrapped in some unique combination of characters – like << and >>or similar so it’s a doddle for the Arduino to pull out the message from any other crap (like the ESPs start-up 78kbaud crap we can’t seem to stop) with the absolute minimum or parsing… so for example if we have a topic peter/stuff and a message “turn something on” – maybe <<peter/stuff:turn something on>>   – see what I mean – look for “<<” – store until the colon in one buffer then till >> in another – and you have 2 buffers – topic and message – SIMPLES!!  But then there’s the slightly more complicated bit – they Arduino would need to send into the serial port two things…. 1. a topic/message in the same format – but ALSO commands to subscribe or unsubscribe to topics…   I honestly think at this point that this is ALL we need from the ESP8266… that of course and the whole thing being in a Windows- Eclipse compatible GITHUB package we can drop in – open up ONE web page in which we put our own special bits – using the Espressif SDK manual which they seem to be rather reticent to part with.

MOSQUITTO is a free MQTT broker (or server if you like) and it’s fine – but it’s all command line and pretty gruesome for beginners to understand. It can run on a PC under Windows… it’s ACTUALLY not that difficult once you’ve used it but messing with that config file is like a trip back into the 20th century – someone needs to make a nice sparkly Windows screen with lots of tick boxes.  When it comes to clients on the PC I’m in love with the free MQTT-SPY – it’s just lovely.  As for Android – really – MyMQTT is awful – if anyone wants to re-write MQTT Spy for Android they would be on my Christmas card list for years.

So there you are – I’m playing with Mosquitto and Rabbit-MQ which looks really nice but I have to say it did collapse when I tried to send a level 2 message out… might just be me not understanding things yet.

From here I’m ready to start coding – there’s enough above to form the basis of a very large and complicated control system –  I’m THAT far off having an internet controlled SAD light for the wife… it’s sitting here waiting for commands but I need something on the phone with nice round, shiny buttons and flashing lights that looks the part – not sure Basic 4 Android is going to do that for me but we’ll give it a whirl.

Let me know if this didn’t make sense – because if it didn’t you’re missing out on lots of potential fun.



Peter Scargill

p.s. The easiest way to get to grips with this MQTT thing – get MOSQUITTO – install it  – ignore usernames and passwords for now.  Get MQTT Spy – tell it about the IP address of the machine with MOSQUITTO (can be same machine) and PLAY… subscribe to arbitrarily named topics – send messages to those topics – within minutes it will all become clear. 

p.p.s. If you’re a Facebook fan and want to read about this stuff ONLY for Windows users who like pretty interfaces like me – head over to

My New Board

tmp1060Ok, I’ll grant you it LOOKS hand soldered.. and the LEDS are slightly too small for my eyesight – but the INTERFACE board worked first time.

This is an interface I put together to handle coming from a normal 5v FTDI – to the 3v3 ESP-01 board, complete with a pair of level-shifting resistors (for serial in), caps for the 3v3 regulator and a couple of series tmpBB9Bresistors for the LEDs. Worked first time. This is going to make life a little easier than having bits of wire all over the place.  Not sure what happened to that GROUND indicator on the 6 way connector though…

Budding PCB designers – note the holes for the regulator to get the heat away to the other side which has a nice copper area.  Over on the right – my ESP-12 turned up – it’s very pretty, it’s nice and shielded, it has the same wiggly aerial as the ESP-01 – but I CAN confirm that it is NOT 0.1” spacing – which is something of a pain in the bum. I’ll be testing it over the Christmas sometime.

To Lua or Not to Lua

Serial TerminalLua is one of the two main contenders for firmware for the little ESP8266 WIFI boards which have peaked so much interest recently because of their low price of under £3 (for some reason some people pay more). Alternatively you can brew your own firmware but contrary to popular belief, most of us don’t have time for that and if we did we’d have to take a month to learn Linux commands – so for the majority, the success or failure of these boards will be down to available firmware.

AT Commands – the original AT command set from Espressif is coming along nicely – I would not say it’s perfect but armed with an external processor such as an Arduino, it is possible to interrogate little WIFI boards and for example go and get information from a web server or act as a TCP/IP listener and respond to commands. Right now for anything serious that is my preferred option.

Lua Interpreter. A month ago I’d never heard of Lua and sometimes I still wish I had not, however it is a small, high level interpreted language that can be embedded into the ESP8266 boards and as of last week it will even read the likes of Dallas temperature chips and the A/D on the board. It can read inputs, control outputs and give you many of the facilities that the AT commands can. As you can see in the image above I even developed my own serial terminal specifically to deal with this board and with Lua in particular as I found myself using the same commands over and over again so I developed a non-volatile notepad and filing system to quickly save and retrieve snippets of code as well as easing the process of saving “files” to the board.

Here however is my current list of issues with this otherwise fine piece of work by a gentleman who goes by the name of Zeroday.

1. RAM – the board is chronically short of RAM for variables and the stack – it does not take too much for it to reboot thanks to running out of memory

2. It has only one timer – and that would not be a problem except for the nature of the language – multitasking is arranged cooperatively and unlike the venerable VB6 it does not have the equivalent of doEvents() to let other processes have a go when you are busy. So everything has to be event driven, not ideal for this application. For example one could run the timer at say once per second and increment a load of variables – giving almost unlimited timers but creating a loop in which to poll those timers blocks access to background processes! Ok you could do all of that in the timer callback routine but that limits how much time you can spend on each process severely. Right now for example reading the temperature sensor takes over a second (working on that)

3. Storing variables permanently – lets say the interpreter is running code constantly to listen to an Android of IOS App to control outputs… if the power goes off – how do you restore the outputs to their previous state? There seems to be no equivalent of the Arduino EEPROM facility.  I may be wrong on this one but I spend an hour last night staring at the ceiling trying to figure this one out.

Of course all of this is resolved with the AT command set and a separate processor – but for the fact

that you’ve now gone from a sub £3 device to at least twice that….

Time will tell.

ESP8266 Options

Firstly let me say this is not intended to be authoritative, so please don’t come back to say I have it all wrong… these are just my views for now – they may change as things develop.

tmp962BYou may have noticed I’ve been taking an active interest (there’s an understatement) in the development of firmware for the ESP8266-type WIFI boards. Why? Well I see this little board as a saviour on two fronts:

1. As a low-cost stand-alone unit – using either C or a higher level language to make the ultimate in low cost controllers.

2. As a means to accessing the Internet for Arduino and other microcontroller systems at low cost.

Up until now, the lowest-cost means of scattering devices around an area included the likes of the NRF24L01 radio modules, at around £1 each you don’t get much cheaper, but they have very limited range. This can be mitigated somewhat by networking software and in my own homes and elsewhere I am using a network of Arduino-type devices to control and monitor heating and lighting. It works – but the hoops you have to go through to get range make it not a lot of fun. Low cost alternatives include RS485. Again at around £1 from China you can get RS485 interface boards and these are fine – but you have to wire everything together.

In my case the whole thing is held together by a master board using hardwired Ethernet to talk to the outside world. All well and good but for all the wires and intermediate wireless points to boost the range.

And then along comes the possibility to use WIFI. I have simply dismissed the alternatives available at £10+ as the cost per point starts to become excessive – especially for anyone doing this as a hobby.

A few weeks ago, the ESP-01 and similar boards appeared out of the woodwork, a dirt cheap Chinese WIFI board around the size of the NRF24L01. At first I started to think of them as a  simple cost-saving replacement for my own main Ethernet card and so I was very interested in the AT version released by Espressif. To explain: The little board uses serial control to talk to a host microcontroller such as an Arduino. I have spent every spare minute on this as we’ve gone from a board being released with almost useless firmware, to the point where today we have maybe 3 viable options for taking this forward and I’ll go into that in a moment.

tmp2ED3The hardware: The ESP-01 is probably the most popular design and sadly it is not ideal. The tiny board has an 89-pin header and it’s sole saving grace is that it is CHEAP – just over £2 at best. It has a PCB antenna which works but doesn’t give the best range but it’s save to say that if you have routers offering a strong signal throughout the building, this board will work for you.  As a unit designed to work with, say an Arduino, it is perfect.  As a stand-alone board it is useless as you only have simple access to one pin! The problem there is that with 2 pins you can implement, say, I2c which opens a whole world of peripherals. With 1 pin –  well, you can flash a light or read a temperature sensor.

There are others, the ESP-03 design brings out the pins to the edge of the board. In both cases these boards use 3v3 – which is fine unless you consider that many controllers and many peripherals run on 5v and those microcontroller boards which offer 3v3 do so with insufficient current to safely power these boards which can use up to 250ma (tiny 3v3 regulators often supply only 100ma).

In my experience, while powering the boards with 3v3 you can feed the output directly to, say a 5v Arduino but you need at a minimum a resistive divider to the inputs – that is the serial input – and the reset (and you really do need to be able to access the reset).  There is even a board out there which I won’t discuss which has access to power and serial only – that is dead in the water for me.

What I would LIKE to see is a 5v compatible board with internal aerial, the pins available on 0.1” centres and an optional aerial socket for external aerial. Do I want this? YES, do I want to pay over £3 for it? NO. Therein lies the issue. Only the Chinese can make that happen at the price.

What absolutely is needed is a minor change to ESP-01 to bring out at least one more port wire. The magic phrase… “I2C”.

The software: This has been an absolute minefield and I would say it is only in the last 2 days that I’ve come to the conclusion that we have a real winner of a board here. There are to my mind 4 routes to potential success available to us, depending on our requirements…

1. The original Espressif software. To call this awful up to now would be generous.. Using the existing software is a nightmare as it has bugs – several trivial and one major. The “busy…s” problem is firmly embedded in my brain as a timeout which won’t go away and as for some of the error messages, “no is fun” comes to mind.  However as of yesterday, an as-yet unavailable version seems to have tamed but not eliminated the first problem.

I have an Android App for my mobile phone which controls 4 outputs on an Arduino which is using the ESP-01 board. Until yesterday I could not keep it running for more than a few minutes without the dreaded lockup. The busy issue still appears but is now an inconvenience. My App has not fallen over in 20 hours (to keep this in perspective, my Ethernet-based home controllers have stayed up for well over 1100 hours without a hitch). I am relatively confident that if Espressif continue to develop this we will have source code access to working software within days or weeks.

2. Frankenstein. There is one complete re-write of the software, no longer using AT commands which, until the designer got the flu last week was starting to look promising. Badly documented to date this is a potential alternative to the Espressif software.

3. There is, floating around, an implementation of a standalone web server designed to initially turn a LED (or whatever) on and off from the ESP-01 etc. using the board itself with no external support. This can act as a router for setup and via a web page can be set to use your router. Another fellow has developed this to read temperature and you can see the possibilities here… but right now, it is NOT a practical solution as there is a bug in the setup software which means the part where it runs stand alone and gives you a list of available routers… doesn’t actually work. You end up having to FLASH the original Espressif software to setup the router – then re-flash this software …. erm, no thanks.

I do have promises this will be fixed and if and when that happens, I think this has a niche all of it’s own – not in it’s original form but with custom software to make better use of I/O.

4. Finally, one great hope is a development that puts a LUA-based interpreter inside the ESP-01 etc. and allows for a stand-alone unit needing no other hardware. See my notes however about I2C and the need for another pin. So – WHAT ON EARTH is LUA? I’d never heard of it until last week when the first implementation came out – which didn’t work properly. I am about to test the update completed only hours ago and a colleague of mine is already onto it and getting excited. Essentially LUA is a high level language interpreter. You can send commands, functions and even complete  programs and data to the ESP-01 serially and have them run on the board with nothing else but power attached.

There is even a start up function you can send which will ensure the board acts sensibly on power up. If you are familiar with C and Java etc you’ll find LUA reasonably straight forward but you might want to get something printed out. The ZIP file for this software contains a lot of info and if you look up LUA on Google you’ll find a complete reference website – concentrate on the features of version 5.1, not 5.0 or 5.2 (as far as I can tell). 

Today I intend to give this last option a good hammering – one of the features CLAIMED to work with e LUA version is I2C. Now, how you do that with 1 wire I don’t know, I suspect on the ESP-01 it’s going to involve micro-surgery but we’re still trying to work this out. But think about it – even if it’s slow (as interpreters tend to be) if it will act as a web client and web server that’s half the battle (reading time servers etc., remote access) and the ability to handle I2C means the little board on it’s own, with no compiling from your perspective, can talk to a myriad of devices including port extenders, clocks, LED drivers – there are thousands of devices out there that talk I2C ( for the uninitiated, a 2-wire bus where devices have addresses and can talk both directions). Remember that this is not an Arduino – it’s a powerful little Microprocessor with a reasonable amount of room – the possibilities are huge.

We have cheap WIFI devices, we have at least one company working on a prototyping board for them, we have many suppliers ensuring we should have reliable access to the devices…what we need is for at least one of the above options to mature to the point where we can rely on them to do whatever it is we want them to do. I could see, best case, these things being a fantastic, low-cost alternative to radio networks for so many applications around the home and office. Sadly the current devices use a lot of power which makes solar operation “challenging” – but that’s just for now – you never know what might happen tomorrow. What would really be nice would be a cheap supply of the actual chips so those of us with PCB abilities could make our own versions.

Everything I describe above, has links in my previous blog items in here. I am so lucky as a man who spends his life going from meeting to meeting around Britain and Europe that at this very time I’ve a short lull in said meetings which means I can spend a little time indulging in this challenging but exciting development. I don’t normally get the time to do this so please, take advantage, do look in over the next couple of days to see what’s new – it’s changing by the hour.

All in One Ethernet Arduino

Just as I was getting all upset about my ESP866 woes, the postman arrived. The nice people at Freetronics sent me a couple of samples to play with – and here’s the first one.


I’ll confess I’m not a great one for using the Atmega328 as found in Arduinos – it has too little memory for my liking – but there’s no doubt it’s very popular and so an all in one board containing the processor AND the Ethernet card has to be a good idea. The on-board Ethernet is NOT the cheaper ethernet card which I wasted months on but is the full official Wiznet version – so this board,, which has a micro-usb interface, power socket, Ethernet socket and comes complete with lead and instructions, looks ideal for the more ambitious projects. There’s an SD card interface as well as a pair of half-decent looking 3v3 regulators – actually the 3v3 regulator looks man enough to handle the likes of various radio boards which need 3v3 so that’s a plus.   I’ll write some more on this when I can fit it into my testing schedule but right now this looks like a nice, solid winner. You have the link above for Freetronics.


This is turning into a diary – my life with the ESP8266 – sounds like a serious disease.

Last night I tried increasing the speed at which my Arduino-like board talks to the ESP8266. I’ve been using 115,200 baud and it was suggested that the problem might not exist at HIGHER speeds. Sadly the Arduino-type boards just will not talk at much higher speeds – either because of inaccuracies or because of the resistive divider I use to talk to the ESP-01.  As the results were SO bad at high speed, I thought I’d try a LOWER speed just in case, in fact it was my serial that was causing the “busy…s” problem – turns out it wasn’t.

So this morning I received a reply from one chap who has tried the LUA version of the ESP8266 software only to find it crashes for him when stressed. His example code is as follows:

i = 0 repeat print (i) i=i+1 until (i == 800)

Well there’s a surprise and another hope dashed for now. Meanwhile the latest Frankenstein code (all of this is referred to in previous blogs) failed last night – latest BINARY files go into a loop on powerup. Hopefully we’ll see another release of that tonight as the author is now aware of the issue.

For my own part, I received an email from ESPRESSIF to ask me to test an archive file they sent me – an experimental version of the software to see if the “busy…s” problem would go away.  That was nice of them and it’s good to know that someone at least understands there is an issue.  I’m including the contents of my reply and their email so you can see the problem and how it occurs.

Here it is in total….my response to Espressif followed by their original email trail – you’ll see they acknowledge the issue, were originally too busy but it’s nice to see them now trying to help.  This is running at 115,200 on an Arduino-type board with 2 UARTS – one for the ESP-01, one for the Serial debug.


Thank you for the test code… but the problem still exists with the new code.  Here is an example.

> 1
> 0
> 0
busy s…
busy s…

So.. here is what I do..

I use an Android program called NETIO (

My Arduino (Mega) uses TWO Serial ports at 115200 – one to talk to the debug serial you see above – and one to talk to the ESP-01 board… hence there are responses above from the ESP-01 AND messages from the board. You can see at the end I am doing a reset to make the board recover but this is not the solution.

Here is what happens…

On power-up my program looks for a valid IP address and if it does not find one it sets up the board. It sends one instruction at a time, waiting for the relevant response – or a timeout.

It sets up the connection to my router then sets up a TCP/IP listener on port 4000. From there, when the APP is running on my phone that sends requests for button status to the ESP-01 – and my board picks that up and sends responses… to say a LED is on or off…


The board then receives messages from the Android APP


The instruction is requesting the state of LED1

Arduino sends back a reply…


i.e. It is sending 3 characters = “0” followed by CR/LF.

So typically we see checks for 4 LEDS as such.


The above shows 4 requests for status – for lamps 1-4 and the Arduino sends back “0” in each case for lamp OFF (or “1” for lamp ON).

This happens continuously.

This works perfectly.. BUT… at any time I might turn the phone off [or swap apps] – or go out of range. Much of the time the data simply stops – and recovers when I start again – but SOMETIMES as in the example above – the BUSY_S occurs and that is the end of it, a reset is required…

Can you help eliminate this bug. I have no control over the NETIO APP – which works utterly perfectly with wired Ethernet.



From: []
Sent: 17 November 2014 02:53
To: pete
Subject: Re: RE: Esp 01


Please test bins as the attachment, if it still has “busy s”problem or not

boot_v1.1.bin downloads to flash 0x00000

user1.bin downloads to flash 0x01000

esp_init_data_default.bin downloads to flash 0x7C000

blank.bin downloads to flash 0x7E000

If it still has“busy s”problem, please tell us your test steps, list of AT commands that you sent. 

Thanks for your interest in ESP8266.


From: Peter Scargill

Date: 2014-10-30 17:39


Subject: RE: Esp 01

Thanks but many of us merely want to USE the module, not develop it – I have no experience of using GCC and the Linux environment, I simply want a WIFI module that works. Please fix the firmware so that the “busy s” problem goes away..



From: []
Sent: 30 October 2014 08:12
To: pete
Subject: Re: Esp 01


Sorry, our schedule is so full that we will put this till later,

but our code is open source now,  on BBS

You can get full source code and do your own development


From: Peter Scargill

Date: 2014-10-30 15:57


Subject: Esp 01


Esp01 esp8266…  When will we see a fix for the “busy s…” Problem?? We

are unable to make serious use of these boards until this is fixed.

Currently using 0922 version software.


Peter Scargill