ESP8266 Woes… a Ray of Light

tmp7BABSo I’ve been continuing to test the Espressif (manufacturer) ESP8266-based WIFI module called the ESP-01 and I’m starting to get somewhere with the “busy s” problem. This board is the more common of a few variations of the board and has power, ground, transmit, receive and 4 control lines called GPIO0, GPIO2, CH_PD and RST. The board runs on 3v3 and consumes up to 250ma (note that some of the smaller Arduino-type boards which have 3v3 power supplies internally, cannot supply this much current. Better to use a 3v3 regulator capable of handling much more. I use one on my home-made Arduinos which can handle up to 1 amp.

Some more hardware info – the pins are not 5v tolerant… clearly the output TX can be connected directly to a 5v Arduino input but you need level conversion for output from Arduino to the WIFI board. I use a resistive divider. 560r from the Arduino output to the WIFI input and 1k2 from there to ground. In normal use including programming you only need 2 of these dividers. This fellow gives a lot more info on hardware.

I’ve done some in-depth tests with an Android mobile phone (Samsung S4)  sending commands to the board over a WIFI TCP socket (using NETIO) – and monitored what happens (I use a 1284-based board so I have 2 serial sockets – AWFULLY handy for testing but you could do similar with a bog-standard Arduino). While the phone was sending polling commands constantly, all was working well, until I swapped apps on the phone (or shut it down or had an issue with WIFI signal)  in which case it might only get part way through sending the command.

You CANNOT avoid this happening with WIFI by the very nature of it being wireless, there might be a glitch, might be a lack of signal momentarily, interference etc., there will always be occasions when you lose data.

Rather than recover gracefully, the ESP8266 (I imagine) has a flag set to say it is in mid-command… as it pulls in data. A new command coming in is NOT clearing that flag (this is a sheer guess) and so no matter what you do it will just say “busy s” until you reset. One kind gentleman has added a blanket reset command to the ESP8266 but that’s not the answer as you then have to wait for the reset and set up your modes again – what’s needed is for the designers to fix this bug.

SO yesterday afternoon I wrote to them, not very hopeful as I figured they’d be Chinese and might not even understand what I had to say.

Imagine my delight when this came back from ESPRESSIF  – a lady by the name of Sue Chen….

Dear Sir,

Thanks for contacting Espressif Systems!

This is due to a software bug. We will fix this bug in a software release soon.

Have a great day! Thanks.

Best regards,
Sue Chen 陈思祐

ESP8266 typical pinsThis not only confirms that it IS a bug as I thought – but gives us hope that they will soon sort it out – I’ve asked ESPRESSIF to let me know when the update is available and I’ll be sure to put the info in here (make sure you follow my blog – there’s a “follow my tech blog” blue indicator on the upper right of the blog screen).

In the early hours of this morning, I received another email from them asking for debug info – basically which version I’m using – I told them 0019000902 which is the latest though I’m not sure now if it’s the official latest number, as my version has the AT+XRST command which was added by a third party (detained in this or previous blog items)… which WORKS but really you don’t want to be resetting the unit as it takes too long and happens too often.

tmpC37ESPRESSIF confirmed that the issue is incomplete commands – I suggested that such commands should be quickly timed out… you might even be sending data with AT+CIPSEND=ID,value,data and if it’s a mobile device sending this, it could fail at ANY point… the ESP8266 needs to recover from this rapidly and move on without losing the current mode – this should be simple enough – if I were designing this I’d simply time out commands. So let’s say you are talking to the board at 115k baud, that’s 10k characters a second – let’s say 1k characters a second to be charitable… so if there is a gap of say 1ms or more mid-command, or an unexpected character then the unit should simply wind back and start looking for AT….  I believe this would solve the problem…

I’m getting excited already…I could be using these boards in so many projects…  #ESP8266  #ESPRESSIF #ESP-01

Further back on this blog you’ll see other items on the subject of the ESP8266 as I fumbled my way along with very little info. There is also some technical blogging regarding Arduino and similar on my home blog

There is some code for the ESP8266 on this blog for the Teensy 3.1 …   http://forum.pjrc.com/threads/26873-ESP8266-with-Teensy

Advertisements

123D Circuits for a bit of fun

If you want to have a little bit of fun with electronics and basic programming without actually having to buy or make anything, head on over to 123D circuits website where they have an emulator for the Arduino Uno and other chips and components. You can even write a program and run it on your virtual breadboard.  It’s no perfect, the fact that the microchips run on a 9v battery whereas in reality they’d blow up at somewhat over 6v – so you have to give them a little artistic licence (though WHY they picked a 9v battery I do not understand)… In this example, I originally made a simple traffic light sequence but then ramped the speed up to 1Khz and according to the virtual scope, it’s still working – all this in a web page for heaven’s sake!!

Good fun with meters, scopes, pushbuttons and more.

tmpD06B

The Microview, another Kickstarter Winner

I now have my hands four of these “Microview” modules, a smashing little display module featuring an OLED display at 64*48 pixels and using an ATMega328P chip. Takes unregulated or regulated power, has 12 I/O pins 3 of which can be PWM, 6 analog inputs and is compatible with Arduino – i.e. it has a bootloader! The display is a clear blue on black background and the quality is excellent. NOT cheap AT ALL but if you need a tiny display with minimal code overhead you can’t beat this one. I can’t wait to come up with an application putting this and the ESP8266  WIFI module together! Only thing is there is no 3v3 output to power such a module. Here’s the direct link. https://www.sparkfun.com/products/12923

ESP8266 Busy S (updated)

I’ve set up an ESP8266 as a socket server and an android app with a couple of buttons to turn a light on and off… no problem.  If you press the buttons continuously as fast as possible, most of the time everything is fine but eventually the ESP8266 will lock up after returning a “busy s…” signal. Incidentally I’ve tried this with the unit operating as a router – or simply logging into my main WIFI router.  Result is the same – both work well but the former is a pain if the thing locks up as the reset kills the internal router.

tmpCC25Amazingly, the only way out of this is with a hard reset – that is not the command but holding the reset button down for a half second and release.

As of yesterday there IS an update which takes us part way there… we’ve been provided us with not only the latest FLASH update but additionally an AT+XRST command. If you use this update you will likely find your default baud rate set back to 9600 initially.  You need to use AT+XIPR=115200 if for example your working baud rate is 115200. That is stored in EPROM and survives reset/power cycle.

Here’s the link for the update..

http://www.esp8266.com/viewtopic.php?f=6&t=294&sid=ce984d8af7dcffbc6d5e8710d242296f&p=1719#p1719

Another article suggests adjusting the timeout as below…I’ve not yet tested to see if that gets one out of every situation… let me know if you have any success with this.. It HAS gotten me out of most situations up to now.

AT+CIPSTO=60 Sets the socket timeout period to 60 seconds
AT+CIPSTO? gets the current timeout value

If you install the latest update and are unsure you can go back to the 0922 software here … http://www.electrodragon.com/w/Wi07c

Incidentally the only change you have to make to wiring to blow the firmware is to take the GPIO0 line (the upper left green line in my diagram) and ground it. Cycle the power as it does not know it’s in programming mode until you do that… run the update software on the BIN file and you’ll see it updating.. I’ve had this work even when the whole board has gone heywire due to a bad update… when you get there – in my case it says it’s not coming out of update mode – ignore that, reconnect the GPIO0 line as normal and reboot – it will initially power up at 9600 baud and you can use the relevant command to put it back to whatever you use – 115200 in my case. AT+CIOBAUD? Tells you the current baud rate, to set the baud rate you can use AT+CIOBAUD=9600,19200,38400,57600,74880,115200,460800, 921600

Click on the image above right to enlarge.

None of this really sorts the BUSY problem…. but for example with the CIPSTO set to 10 seconds – I have on and off buttons on an Android App and a status indicator updating every 1/2 second (state of the lamp). It is working and if it screws up – that timeout gets me out of it – UP TO NOW…

ESP8266 as an Access Point

If you’ve been following my articles on the new ESP8266 board (https://scargill.wordpress.com/2014/10/05/esp8266-working/ for example) you’ll know that you probably need to FLASH the board to the latest version (0018000922 at the time of writing though it reports 08000902 it has the new baud rate control and defaults to 9600 baud initially) and you’ll know there are a few sites – one to help you flash the ESP8266 and another with a fairly up to date instruction set.

And that’s fine – but today someone was showing me their new all-singing electric car which is controllable by phone – and it has it’s own access point – and I thought – I WANT ONE – which reminded me – how on EARTH do you make an access point from the ESP8266? Well, that’s not obvious – a quick look at instructions show that it CAN be an access point and there is a vague reference to this..

tmpC182

The imagery above comes from NURDSPACE – it’s fairly obvious how to join a network but if you want the ESP8266 to BE the network – what’s that vague reference in CWSAP? What’s an ECN for example – is THIS the command to set up your own Access point – doesn’t look like it as it says “connect to your router”?

Well, it IS the access point setup – the description is just a little misleading and there is some missing information. I found THIS on an another site…
tmpE104

BINGO – so actually this is to make your OWN access point with a choice of channel and encryption method. It returns OK incidentally, usually within a second. You need to set CWMODE=3 – and that information survives a power cut – so you only need set it once.  And here’s the thing – the CWSAP ALSO survives power cycling – so just as you need only connect to an access point once – and on power up it reconnects – you only need to set the board up as it’s own access point once and it keeps that through power down (though in both cases I’d be checking on power up that it’s still working).

So after username and pass you wish to use to protect the unit, pick a channel (your mobile might have an app to tell you which channels are clear where you are) and a mode 0=no encryption – i.e. open – 1=WEP, 3=WPA_PSK, 3=WPA2_PSK and 4=WPA_WPA2_PSK.

And so where are we now – web server, web client, socket listener, access point. This just keeps getting better and better. Everything is there – provided you don’t mind setting this all up with a serial connection. What would be nice would be for the unit to default to it’s own access point – complete with setup screens just like a simple router – for example the access point seems to have a fixed IP range.. I can’t up to now see how to adjust that. Not sure if I’d want to but there’s always a chance it might conflict with your own setting. When I hooked my phone into it the phone ended up as 192.168.4.100…

So how does that work? Well, the unit IS running DHCP as I disconnected once and reconnected and was told (using the Android tool IPCONFIG) that I was 192.168.1.101 – the constant is the address of the Access point itself which is 192.168.4.1 –  it also has an address built in for a DNS server and I have NO idea where that comes from – maybe a hangover from previous connections.

Of course in this mode your phone or whatever device can’t do anything with the REST of the world – it can only talk to the ESP8266 – but that’s the point – you can then control something.

I turned the unit off – hooked it up to my Arduino toy that turns a light on and off – after changing the access point to 192.168.4.1 – and LO AND BEHOLD without using external WIFI I can turn the light on and off – and if I can do THAT – I can control ANYTHING – next stop – WIFI house controller.

This is of course as far as many tutorials would take you – leaving you then to find the problems yourself. it occasionally locks up occasionally and I have no satisfactory solution. You can try as I have, controlling the physical reset line when you see “busy”… I reset for a second and re-issue the main mode command… and that’s fine BUT of course your phone by then has disconnected from you and reconnected to your normal router – so that REALLY isn’t a solution. I found a customised ROM with a new instruction to reset in software – but I don’t yet know which ROM it is BASED on – when I find that out I’ll report back as that’s a definite reason to update the firmware.  I have left this on overnight and it’s been absolutely fine – but if you send commands way too quickly it might just lock up. I’m currently requesting the status of my LED every 200ms – so I can see the status of it on the phone – and I have 2 buttons one for off and one for on. By and large it is fine – but there ARE times when it locks up and the reset is the only answer for now.

So – there we are… this incredibly cheap unit looks like it just MIGHT be useful – not sure about that internal aerial though – I was going to order one of the ones with a socket to put a decent whip on it – but they only have 4 pins (ie power, ground, in, out) which means no firmware upgrades from a file – pretty useless then given the current variations of firmware. I hope this is helpful – if you find better sources-  please be sure to return the favour.  I’m pete@scargill.org and you’ll find my home control stuff at www.scargill.net

ESP8266 Now Working/Updated

tmp4A50Getting this pesky ESP8266 working has been one of the most frustrating things I’ve done in recent months. Thanks to a combination of newness, just plain WRONG information out there and documentation slowly and sometimes inaccurately being translated from Chinese – not to mention software bugs, I’ve spent several evenings getting myself annoyed at this new and interesting WIFI product from China, until last night when it finally all worked.

For anyone looking in here who is wondering what this is about – I’ll explain – for those looking to fix something – skip to Cheap WIFI. For instant results (like maybe you don’t think the board works as I didn’t – check out my short video but do come back here.. http://youtu.be/08RlcuyeKSI )

The ESP8266 is a VERY low-cost tiny WIFI module for embedded systems. Anyone familiar with, for example Arduino will know that just to open a remote web page via the Internet will cost you most of your code space and almost all of your RAM memory.

I will refer to Arduino here as that’s one of the cheapest and most popular ways to do embedded processing – in fact I use a chip called the ATMEGA1284 and build my own supporting hardware as this chip has more memory and more IO than the standard ATMEGA328 – but I’ll argue here from the perspective of the standard product.

Ethernet Card: A typical Arduino installation of Arduino processor and standard Ethernet card will see at least half of your available FLASH memory used up to simply open a web page. The Ethernet card will cost you between £10 and £30 depending where you buy it from.

EN28J60 Board: These are the cheap end of the Arduino Ethernet spectrum coming in as cheap as £4 but with another price – the chip is fairly primitive meaning you need a lot more software in the Arduino to make it all work. There are a couple of libraries, i.e. Ethercard which is frankly awful and Arduino-UIP which emulates the standard Ethernet library but who’s client software is unreliable and either way you lose most of your RAM memory and again end up with less than half of your program space left. This board needs 3v3 to operate.

WIFI Solutions: The above boards assume you can hook up a wired Ethernet connection. There are also WIFI solutions varying from solutions as above with WIFI added to the rather novel idea of having an intelligent board you talk to serially using AT modem commands. The latter have the advantage of dramatically reducing the amount of FLASH and RAM memory needed – but the downside has always been the cost. By the time you’ve finished you end up with a product that is just too damned expensive and you may as well have cannibalised an Android tablet.

Cheap WIFI: Along comes the ESP8266 – a board from China, using a 32-bit processor with on-board aerial, requiring a few simple commands to get a WIFI connection and a cost as low as £3 – this is potentially THE BUSINESS.  Out there very many people have ordered, very few have results – and is it surprising? Most of the examples of code are based on one or two originals and are just plain wrong.

Typically you will see code that shows a connection to your router – and time and time again when the response “OK” comes back  the articles will suggest you have a connection.. NO, NO, NO. Not in the early versions of the board’s software.  The board features the ability to look at the IP address it has been assigned – and if that does not respond with a valid address, you are not connected.  When actually setting up the AP and password the board will come back and say OK to any old rubbish provided it is formatted properly. You NEED to ensure you have a valid IP address. Up to now I can’t see how to set this manually – that in itself is an issue but one thing at a time.

It LOOKS like (still testing) the latest version of the software (which will likely NOT be included in the ones you get from the factory) now comes back with a useful indication of success or otherwise when you actually try to connect. By latest version I mean..

AT+GMR  returns this….    0018000902

See lower down as there is more than one set of software bearing this version number.

I’ve spent nearly 2 weeks using a version that simply doesn’t work properly – and only now have I found an article that actually tells you firstly how to get the software up to date but also potentially how to keep it up to date (that bit doesn’t work for me yet ) and even then, some of the responses from the unit are distinctly poor English… like this one.. when sending data to a website for which you don’t yet have a connection, the board replies “link is not”.  I think we’re a long way before this can be described as “the finished product”.

Some time ago I made myself a little PHP page to return the time along with lighting up times for my area – this is for a home control project.  I  did this because NTP time servers are notoriously busy and just not something you can count on and then if you want lighting up time – you have to write some code to work this out.. Would it not be great, I reasoned if I could offload this work to my own website and those of a few others (preferably using other providers) for backup.

The web page returns the usual header stuff and this simple statement…

{time=1412468381;timestr=01:19:41 05-10-2014;dawn=06:42;dusk=19:09}

In there you see the time in a format suitable for Arduino real time clock software, you see readable time and you see dawn and dusk. By adding parameters to the page call I can make it work for any area in the world. LOVELY but for many projects, like my wife’s SAD TIMER, adding an Ethernet card and an Ethernet cable to the project is a no-go.. hence my excitement at seeing the EAP8266 board. for a nominal sum I could add time facility and do away with all that display and keyboard nonsense necessary just to set the time!! I could even develop a nice web interface to the page for setting different days etc. and return that in the string above…. the sky’s the limit.

But no, try as I might, I spent over a week trying to get this little board to talk to this simple web page.

Last night (or technically this morning) that all changed and it works. I’m documenting this to save others a LOT of wasted time.

So, you have your little WIFI board and I’m hoping you have an FTDI board, if not, get one – in other words a USB serial convertor used for programming some types of Arduino and talking to devices over serial from your PC. They cost a few pounds only.

Read THIS article and it will show you how to talk to your new ESP8266 board AND how to update it from a file (link is in the article) and potentially from that point how to update it automatically via the web. THIS article was the turning point as it correctly describes (for my board and note not all boards are identical) the use of the control wires often ignored elsewhere.

http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/

This article http://hackaday.io/project/3072/instructions shows a diagram of the board itself and was particularly helpful – I do indeed use the CH_PD wire, the example suggests a 10K resistor holding it to 3v3 but I just shorted it to 3v3.  For boards like mine – NOTHING works unless you do this. You can’t send or receive AT type commands to the board if you do not connect up this wire.

So we’re talking 5 wires for normal use… 3v3 and ground, signal in and out – and the CH_PD wire held to 3v3. IN ADDITION if you want to program the board itself, using the software in the first link, you’ll need to hold GPIO0 to ground and release when done.

With those wires and nothing else connected, I’ve managed to upgrade the board almost to the version mentioned in the first link – but more importantly, it now works. Once you have selected your access point (AP) and settings and successfully achieved an IP address, you can turn the board OFF – back on and it needs NO code to get hooked up and get that IP address again as the details are stored in EEPROM.  Sadly you cannot easily test all of this with just a serial connection to the PC unless you have a fairly advanced piece of modem software (unlike the Arduino IDE serial monitor) because by the time you’ve connected to a page and then started typing commands to it, the thing has timed out (see later-  you can now control the timeout).

So a combination of setup and testing with your PC and then some simple Arduino code and you should be up and running in no time.

Oh, wiring before I forget – I’ll assume you have a 5v Arduino and this thing needs 3v3. Note that you really do want a decent amount of power at 3v3, maybe 300 ma or more – check elsewhere as I’m not sure the actual requirement but I suggest for experimenting you ensure plenty of power is available. In my case my own 1284-based boards have a 1amp 3v3 regulator on-board so power is not an issue.

Things to remember… this little board can talk to web pages – and you may find yourself taking in more than 64 characters at once – why is that important? Well most of the writers out there seem to have missed this – the Arduino can only take in 64 characters into it’s internal buffer before throwing the excess away!! The existing Serial.wait() function call that some writers out there advise using – falls fowl of this limit – so I wrote my own. The limit incidentally is set in software in the Arduino and you can go poking a file and fix it – I’ve written about that elsewhere – but of course in the standard Arduino you only have 2K of RAM so you don’t want to get too ambitious – but my preference is for a 256 byte buffer.

Ideally you want to wait X amount of time for incoming characters until you see a string – like “OK” – and THEN wait another Y amount of time in the loop just to get rid of any rubbish that might come in after that, returning a result and a nice empty buffer. That’s a fairly easy thing to write and you can test it with the PC serial port and a standard Arduino. So for modem use you might say  mySerialWait(“OK”,5000,200);  or wait for up to 5 seconds for incoming data – if you get nothing, return after that time with a FALSE response, if you see “OK” in there, scrap the original delay and  hang around for another 200ms and come back with a TRUE response.. Well, that works for me. I’ve since added parameters to optionally store useful info in an array and have a working “light on, light off” demo as per the video referenced elsewhere. That will soon turn into a fully blown SAD light controller.

I am experimenting with code that returns the information from my web page and as yet does not do anything with it – the TOTAL code (no libraries) is just over 3K – compare that to ANY other Arduino Ethernet solution.  Something in the back of my mind says this serial approach is going to have some severe limits – but already it is the solution to my wife’s SAD light for very little code!  I can make a really sophisticated web page, store all the settings from, say a mobile phone into a web page (SQL database) and every now and then the little SAD light can poll the page to get all the updated info, ready processed for use. Lovely. Well, that’s the plan.

Today I discovered THIS link http://www.electrodragon.com/w/Wi07c

This has commands not featured in other lists – including CIPSERVER. I need this to serve up a TCP socket!!

So how do you do this? I set up a little socket communicator on my phone as a socket talker – with 2 buttons.

On the WIFI board I set CIPMUX=1 – you have to do this on power up unlike the rest of the stuff – if I was to set up a client to a web page I’d set that to 0 but this CIPSERVER command will fail if you do that.

Bear with me. I set up AT+CIPMUX=1 then AT+CIPSERVER=1,4000   that means start a socket listen – on port 4000. It says ok and sits there.

I press a button on my NETIO setup – which is pointing to the WIFI address of the board – and set up to send to port 4000.  Magically – the board responds…

+IPD,1,4:YES

and the button on NETIO remains sunk it. That first figure is 1 is the ID of the command….

I send AT+CIPSEND=1,4   – which say I’m going to send 4 characters back – to ID 1 on this socket.   I get a little > in the response window..  I type nothing more than OK in the terminal window and hit ENTER

> OK

SEND OK

As if by magic, the little button on my NETIO Phone app lifts up – all is well.

But after a while I get “unlink” – that’s my phone timing out – bring the phone back to life and I can talk to the WIFI unit again with no further action needed on the WIFI link… AT+CIPSTO? says 180 seconds timeout but it’s kept on working WAY beyond that…

Not sure yet what I need to look out for in terms of the thing timing out… but right now – I’m THAT far off having a working controller APP on WIFI!!

I do with they’d fix the error message “no this fun”

Update: the software version you should be looking for is this…

0018000902

HOWEVER if you got that from the CLOUD update – it is NOT the same as the later 922 version which still sadly calls itself 902 and reports the same but in fact NOW defaults to 9600 baud… and will let you use stupid high baud rates as well as new commands. See these docs – the first is how to update – and the second at the bottom has the actual latest update, the third has the pins!

http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/

http://www.electrodragon.com/w/Wi07c

http://hackaday.io/project/3072-ESP8266RetroBrowser

If you want to read all about what started this off – ie my home control stuff – check out www.scargill.net

Update: Two more things – I now have the board running as a socket listener – which is ideal for, say pressing a few buttons on your mobile phone to turn things on and off.  I’ve discovered how that works – and how it doesn’t.

I’ve been doing some further work with the ESP8266 – as I want it to act as a Socket listener.  Check my posts to ensure you have the latest firmware because without that you won’t be able to use the command AT_CIPSERVER.
Armed with that update, in order to use this mode, you must first set CIPMUX=1
i.e. AT+CIPMUX=1
Then to activate the listening mode for, say port 4000, you should use this.. AT+CIPSERVER=1,4000
The “1” is for start.. 0 for stop is supposed to work but I found that needs a reset…  once in that mode the ESP8266 will reliably STAY in that mode..  I wrote a little code to work with NETIO software on my mobile phone so I could press buttons and have the Arduino talk to me – when reading this code bear in mind I have 2 serial ports on the 1284 chip…

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

void loop() 

{ 

Serial.println(F("Changing mode")); 

Serial1.println(F("AT+CIPMUX=1")); 

SerialFinder(Serial1,"OK",4000,200); 

char PROGMEM cmd[]="AT+CIPSERVER=1,4000"; 

Serial.print(F("Sending ")); Serial.println(cmd); 

Serial1.println(cmd); 

SerialFinder(Serial1,"OK",3000,200); 

while (1) 

{ 

   if (SerialFinder(Serial1,"+IPD,0",1000,20)) 

        { 

         char PROGMEM cmd2[] = "OK\r\n"; 

         Serial.print(F("Sending AT+CIPSEND=0,")); Serial.println(strlen(cmd2)); 

         Serial1.print(F("AT+CIPSEND=0,")); Serial1.println(strlen(cmd2)); 

         Serial1.print(cmd2); 

        }  

} 

}

SerialFinder (I wrote myself, trivial, waits for the string and returns true or false after a further delay – that simple).
So – it all works a TREAT… it’s waiting for “+IPD,0” which just so happens to be what comes back in this case, might be different in yours, followed by some info on whatever key you press on the phone – I’m not ready to start parsing info yet, just testing reliability, so no matter what it sends, I send back “OK”.
Now all of this works REALLY reliably. However, if I press buttons on the phone too quickly – the board at some point returns “busy” or otherwise locks up. It’s pretty hard to replicate and happens only occasionally but trust me it DOES happen and resetting the processor does you no good most of the time.
You need to reset the ESP8266.. and there is a reset line for that. It will re-establish the connection to your router etc and will simply need you to re-send that CIPMUX command and put it back into server mode.
So now our simple serial chip is not quite so simple – needing RESET and CH_PD pins (CH_PD is on my setup permanently hooked to 3v3) and GPIO_0 if you want to go flashing the board – which is easy – see my blog).  So if you want to reset the board from your 5V Arduino you will need a resistor divider pair just as you did for CH_PD. Actually as reset is hardly a high speed effort – you could use a 4148 diode pointing to ground… I’ve tested that and at least on a rig it works well.
As far as I can tell, no matter what goes wrong, the ESP8266 recovers if you use that reset pin. More as I learn more. It would appear that NURDSPACE site now has now been updated to include the CIPSERVER command but still claims the unit runs at 57k baud. Last but one version actually ran at 115k baud and latest defaults to 9600 baud and you can then set whatever speed you like, right up to 512k baud.