NODEMCU Board–a little winner

I think this has chance to be a little winner – in many respects. The NOCEMCU guys have made an open source board for ESP8266 that looks the business and should let more people experiment with this great chip – between that and AT LAST getting a proper Windows environment to program in (Eclipse) things are moving along nicely – I hope they don’t mind me replicating one of their diagrams here but it’s so good it deserves an airing – the numbering of course refers to their board but you should be able to cross link with the pins on other boards – here’s an excellent pictorial view of the ESP8266. NOW we can see for example that GPIO-16 is the wakeup lead – tied to RESET (RST) it can enable putting the thing to sleep for ages and saving power.. etc.. anyway you have the link to the site….I’m not promoting that over anything else and no they’ve not sent me a free sample. https://github.com/nodemcu/nodemcu-devkit – my thanks to GLENN for this information – well spotted.

ESP8266 Development Board

Advertisements

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. https://github.com/tuanpmt/esp_mqtt – 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.

Regards

 

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 www.facebook.com/esp8266wifi

ESP8266 and MQTT A Marriage Made in Heaven?

It’s been a very busy day – and a very frustrating day. I’ve had to make a start at figuring out how MAKEFILES work because of a fellow who implemented MQTT for ESP8266 so I could seamlessly compile his code and blow ESP-01 chips with the Eclipse environment in Windows.

It all started a couple of days ago when I utterly accidentally stumbled on a project to implement MQTT onto an ESP8266. I don’t know why I went for this but I’d just gotten to grips with the Eclipse setup so I was now a fully fledged Windows developer of ESP8266 software.. by that I mean I’d figured out how to alter code to get a light to flash on and off in the AT command software.

I remember playing with MQTT a while ago and I mentioned it in here or on the ESP8266WIFI Facebook page. Anyway I sat down with a large glass of wine and started to tinker. Essentially, MQTT is a lightweight protocol for sending messages around a network – apparently Facebook Messenger uses it.  You have a “broker” – call it a server if you are a techie… so this is free software like for example MOSQUITTO which you can run hosted, on your PC or on a Raspberry Pi. you can make an account with it – which might be open, have a simple password or have something far more complicated.

One of my fears of controlling the house remotely has always been security and I’ve made some primitive passwording which is really not worth a light.. so this caught my interest. My other issue as regular readers will know was that I was getting utterly hacked off with the ESP8266 as it can’t really do server and client at exactly the same time – so you would have trouble making a network of them – you CAN do it and there’s a slow moving project on the subject… but right now, not a viable solution – that might change.  The instant I saw MQTT my heart skipped a beat as I thought… can’t one device send a message to another?

I put IBM’s free MOSQUITTO on my PC (powers up with no passwords etc, doddle to use even if the command line environment makes some people feel physically sick – including me). IT uses a single port which you can change so it’s easy to make available outside via a little port mapping on your router.

I blew the code for this onto one of my ESP8266 boards – and left that connected to a serial monitor. Sure enough, it connected first time to MOSQUITTO. It SUBSCRIBED to a couple of messages (utterly arbitrary and they don’t need to exist at the time of subscription).

I grabbed a free but not very good program for Android called MyMQTT. IT’s not seen an update in AGES but I remembered it worked ok. I told it about my MOSQUITTO setup (ie the IP address of my computer) and that was that. I subscribed on the mobile APP to the same “topics” my ESP8266 had. I sent a message to that topic… sure enough instantly on the phone, the topic I’d replied to came back with a message – the same one I’d sent out… simultaneously the same message came into the ESP8266. We’re talking INSTANT here – no visible delays.

Immediately I grasped the possibilities. I modified the MQTT code (in the new sparkly ECLIPSE environment) on the ESP8266 to check the content of one of the topics it had subscribed to… a quick STRSTR on the zero-terminated incoming string… I made 2 comparisons – one for a message “GPIO0 ON” and another for “GPIO0 OFF”. I borrowed the heater and port info from a BLINKY sketch (all of 3 lines of code for everything)… and compiled away. I sat in the corner of the room and gingerly entered “GPIO ON” into my mobile phone app… and… BINGO the light came on.

Step 2. When the light comes on – SEND a message to the same topic but a different device number – I should say the author engineered auto device numbers based I think on the mac codes – they’re all unique…   /0033342342/data as it happens – I sent a hello.

Sat back with the phone, put my GPIO message in again, the light came on and IMMEDIATELY the message appeared on the SECOND ESP8266 as expected.

So with the minor inconvenience of a piece of “broker” software minding it’s own business on a minimal PC, a Raspberry Pi or some external server (your choice) the ESP8266 boards can now talk to each other without another processor. Not only that, I reasoned but if the server machine also had a client, it should publish a “TIME” message every 10 minutes or so…  the boards would IF APPROPRIATE be programmed to subscribe to this channel and LO  – ESP8266 boards which can turn things on and off – and also know what time it is. But what of the power of an Arduino – what about all those extra pins? Another project implements I2c on the ESP8266 and when my skills are ready I’m adding THAT into a mix – which means any number of peripherals to do things or return info using MQTT.

It’s a grand total of £40 or so investment to get yourself into the Android App trivial programming brigade using B4A.  Mine of out of date, out of warranty and so I’ll ahve to start again. For £10 a guy has written a library for MQTT and this afternoon on a friend’s PC – someone who has the full B4A, we wrote a simple messenger program that will send and receive MQTT messages. The results – again absolutely instant message passing back and forth.

Imagine – you have a button on the phone – you press it and it does two things.. it turns a little indicator called kitchen_lamp to grey then sends a message to /kitchen/lamp which it does not subscribe to – the message is ON… the kitchen lamp ESP8266 box which features nothing more than an ESP-01, a 3v mains PSU and a relay, gets the message and turns off GPIO0 which turns on the relay (there’s a good reason to do it backwards like that). It then sends a message back to another topic which it does not subscribe to called /kitchenresponse/lamp. THe phone however DOES respond to that – and when it sees an incoming message to that topic, it turns that same indicator green or red depending on the message.  So the lamp is off – you press the on button and your indicator on the phone almost immediately turns green so you know for a FACT that the kitchen light came on.

You might take that a stage further – because you’ve written the client on your PC to send messages like TIME, the kitchen lamp knows what time it is because it also subscribes to TIME.  if no-one turns that lamp off, at midnight it turns it off itself.

Multiply this by dozens of similar gadgets, some DO stuff like turning things on and off, others merely sit there, read the temperature and report it back – either every now and then – or on demand… same technique..

An old Android tablet sits on the wall, it has a program you wrote which subscribes to as many or little of the topics as you want and reports in pretty graphical format the various statuses-  it might even have a large round touch control reminiscent of a a certain apple-esque temperature controller…. and everyone talks to each other securely over WIFI..

BUT you might say, I really want to use Arduinos – ok you have the little ESP8266 do all the hard work of handling messages incoming messages it sends out of the serial port and if you want to send a message that could come in through the serial port… so now you have an Arduino that has to do nothing but take in serial messages and send them out – polling is easy – and you can of course wrap messages in any control character or sequence you want.

But hang on – isn’t Arduino serial interrupt driven? YOU BET – which means if you go in and tinker with that you could have that look for the starting sequence, start storing bytes until the ending sequence occurs, copy that temporary buffer to another, set a flag to say there is a massage – and simultaneously go back to looking for the next message – all using existing resources that are used in the serial handling anyway.  The Arduino ends up with a few bytes less than a full pack and can now receive serial messages and act on them with virtually no extra overhead which means the simple 328 has LOTS of room to DO stuff.

That enough for now? It certainly has me excited but I’ve had enough for one day… I need to turn most of this from thought processes to reality. The MQTT project is apparently in it’s early stages but I can assure you it sends messages with password protection as reliably as it receives them. Even if the designer does nothing else you have this at your disposal – links in earlier entries in this blog. Go get ‘em.

Now if anyone’s up for some collaboration I’d much rather someone else write the Android APP – a decent replacement for the promising but dead in the water myMQTT..  All in good time – good night all.

ESP8266 Development in Windows AT LAST

ESP8266 on WindowsHere it is… on the surface of it a MASSIVE Christmas gift to those of us who simply have to little time on our hands to get involved with Linux.

I got so frustrated waiting for up to date BIN files and the continuation of Chinglish error messages (I should not complain because many Chinese speak far better English than I speak Chinese) – I decided this morning to down tools and see if I could get the compiler working in Windows – but I wasn’t expecting THIS.

I was stumbling through various blogs and discovered THIS.

http://www.esp8266.com/viewtopic.php?f=9&t=820&sid=783b2f3021078ab65722108fdfadd5d8 – the link gives you all the files you should need to get working environment in 64 bit Windows – and this video https://www.youtube.com/watch?feature=player_embedded&v=eWGjADdjH98  shows  a demo in the video of the whole ESP8266 compilation and rom-blowing – WITHOUT reams of irrelevant warning messages!!

ESP-01AT LAST, ESP8266 compiling and blowing in human-readable form. I got VERY exited about this as there are several developments out there which are ALMOST what I’d like but not quite – a stress free way to mod the source codes would be lovely. For example one fellow has developed the AT command set for ESP8266 using the latest SDK and added NTP support – another has added a well needed internal buffering scheme to the serial – what would be great would be BOTH of these in one package – the only way to do that is to get the sources, compare, mod and blow your own chips – and now my Windows friends – you CAN.

Check out the link and follow the instructions EXACTLY – don’t go off on a tangent as there’s a similar page with failed links and lots of Russian – you’ll find the JAVA file on the linked website is later than the one he specified – won’t worry about it – still works. There is an issue also that in his diagram he shows the ESP-01 with pins GPIO0 and GPIO5 connected to the FTDI (USB-RS232 convertor) – well, you don’t HAVE GPIIO-5 available on the ESP-01 – I’d tell him that but I don’t speak Russian – I did leave a note on his YouTube site. . Matters not – you merely need to ensure as before that GPIO-0 is grounded before you start blowing chips – and don’t forget to cycle the power to the board before and after.

Follow his instructions TO THE LETTER. I installed each of the packages (with the updated Java package – when it came to his EXTENSION package which consisted of a BATCH file, I noted (typical command line stuff – whizzes by you too fast to see) some errors to do with packages already installed. Mad no difference, still worked.

Eclipse on Windows compiling ESP8266I followed the instructions for the Eclipse Luna program including point 8 in his documentation though that last paragraph I simple could not understand. But then I realised this was explained in the short video.

So – 5 files in all totalling maybe 400Mb – and worth every byte!

By the time I was finished (NO extra work other than following the instructions and no “assumptions” other than having Windows 8 64 bit)… and I ended up with this.. As you can see, pretty damned impressive,  a working rig with various projects already included on the left, all set up INCLUDING the latest AT v0.2.0 on SDKv0.9.4 – which is the one I’m currently interested in. No Lua but I’m sure someone can help there.

Compilation WORKED (wheeeee)…

tmp26DDBut then when it came to the last bit – blowing the file in to the ESP-01 – FAILURE.

I found at least 2 places in the MAKEFILES referring to COM2 – which I changed to COM5 (all done within the environment) – that just seems the WRONG way to do this – surely you would set the COM port outside of the MAKE file and pass it as a parameter – if you figure this out – please WRITE IN… 

I changed the COM port manually and eagerly double-pressed the button to blow the chip. My little board flashed for a second and… failure. I’d forgotten to short GPIO-0 to ground. Power off then back on with the link, plug into the PC via my FTDI –and…..SUCCESS. 

Right about now I can make a minor mod then compile and blow all within 26 seconds – which is amazing.

ESP-12So – there you have it – that and the revelation that my FTDI can indeed generate it’s own 3v3 and hence I can run the Arduino and the ESP8266 on 3v3 instead of messing around with level convertors…. it’s been a GOOD DAY so far. No longer the poor cousins of the Linux crowd..

I hope you get as much fun out of this as I intend to. Next stop I need to ensure you can just pull in a GITHUB folder structure as I’m sure these won’t be ENTIRELY up to date… he doesn’t seem to have the LUA interpreter in here – as that has only JUST gone open source – again if you manage to pull that in and compile and blow, please come back in here and give us a step by step along with any other news of updates to install – I can see this environment getting a lot of use.

I installed this on 64 bit Windows 7 without ANY issues, next stop I hope to repeat this with Windows 8. If only Dropbox was faster…

07:04PM – Tested in Windows 8.1 64-bit – no problems – same procedure, same results – success.

08:02PM – Tried the MQTT demo – loaded it in from the site ZIP, imported all fine, compiled all fine but did NOT generate a firmware directory and so blowing the files could not proceed. Maybe this is a one off problem?

If you’re on Facebook don’t forget to LIKE my Facebook page – where I can concentrate purely on Windows users.. https://www.facebook.com/esp8266wifi

ESP8266 More Christmas Goodness

News:  There is an SDK beta at 0.9.5 out…

There is also a new AT beta with buffered output and a CTS pin (yes, REALLY needed) – but as it’s beta I’l leave you to find all of that at the Expressif BBS site below..

timeBut here’s the more interesting one http://bbs.espressif.com/viewtopic.php?f=15&t=105&p=352#p352

I just grabbed the AT binaries based on 0.9.4 with NTP support added – hell of a lot faster than my website interrogation!!

Set the board up – do AT+CIPNTP=0

(where 0 is no offset from GMT – if you’re in the UK – adjust accordingly)…

Assuming it comes back to say it sorted it – (I HAVE asked if we can have “OK” or “ERROR” on the end)  use AT+CIPNTP? to get the time and date.

A good move forward – NOT tested the rest of the code as it’s Christmas and we’re now off to see the family – enjoy.

ESP-12 Prototyping Board

There’s a prototyping board out there quite cheap – http://www.ebay.co.uk/itm/391009833643?_trksid=p2060778.m1438.l2649&ssPageName=STRK%3AMEBIDX%3AIT and on the surface it looks like a good deal – it APPEARS to include the ESP-12 – so overall amazing – but looking at the description either the person writing it had really bad English skills or doesn’t actually understand what is being sold – I certainly am unsure what you get for the money. But here’s the thing – the regulator looks to ME to be too small.  The LEDS look to me as it they are permanently wired… erm what if you wanted to use the pins as inputs? and it’s kind of big. GREAT IDEA though.

Here’s my idea for a board – and remember you could make this up in Eagle or similar and have them made in China for next to nothing.. I mean if you had half a dozen ESP-12s it’s surely worth considering it you’re a dab hand with a soldering iron?

tmpC4A1

So what we have here is the ESP-12 on the left with 0.1” connectors to either side as the ESP-12 comes with 2mm connectors – not exactly conducive to prototyping.  I’d then put a suitable number of LEDS on the right complete with series 2k2 resistors and a 2 way 0.1” header for each so they could be enabled with a simple header (or link if you’re really cheap).  In addition I’d want a pullup and link for programming and a couple of resistors to divide the input to the UART from 5v to 3v3 (try 1k2 and 560r for example) for the FTDI connector over on the right.  I’d use the 1amp 3v3 reg with decouplers… and a power led and resistor bottom right.

Ok, I’m sure to have missed something out… but you get the general idea. There’s even room there for a couple of mounting holes…. all of this could be done on the free EAGLE package (I think it lets you do up to 100mm square) and sent off to China for one of those $15 for 10 prototype deals…  ok this is really only suitable for those who are familiar with a soldering iron but I’m thinking it might be a reasonable attempt at a design for a test board ot let you play with the units with standard 0.1” headers, FTDI, test leads etc. the cost of the parts is very little. 2k2 series resistors, 1k2 and 560 for the divider, 0.1u for decouplers…

Seem reasonable? If anyone turns this into a set of boards, Happy Christmas, be sure to send me one for my lone ESP-12.

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.

ESP8266 Mesh Network

mesh networkI don’t want to raise false hopes but there’s a fellow over at http://www.esp8266.com/ who claims he’s getting on with creating a mesh network with ESP8266 boards. If he can do that AND have one of them talk to the outside world – for example an Android APP using TCP/IP — then I’m throwing my radio network in the bin. This would have to be very reliable but given the rubbish range of most of the little radios and the fact that most places are wired for WIFI… there are just SO many possibilities for this. I’ll be keeping an eye on this chap  – look in after Christmas for more.

08:49AM – You’re going to love this – he has something to demonstrate – and the more I think about it – the more I think he’s onto a winner. The units as you probably know are able to be access points – and clients at the same time.  You may also know that you can get a list of available access points and signal strengths nearby. This is where the NRF24L01 devices go wrong – you can’t do that.

esp-01So given that you can scan for the best signal – and given you could have a given range of access point names which you  would know about – and a passwords you’d agree on, then is it really that far fetched to imagine a unit regularly checking access points and hooking up to one. Starting to make sense already? I’ve not thought this through, I’m hoping the fellow who’s writing this has.  I can’t get my head around how they’d actually talk to each other AND the outside world…. ok, they can be TCP/IP listeners and handle multiple connections but using serial I could never get the multiple connection bit to actually work. Maybe it’s better when you’re not using serial.

If nothing else I intend to set up 3 of them and follow this project through… lots of potential here I think. Some exceedingly preliminary code is available already to play with…

09:48AM – Not looking good up to now – followed the instructions here.. http://www.esp8266.com/viewtopic.php?f=6&t=903&p=5581#p5581  pretty much to the letter… checked my locations, blew 2 chips – and… nothing – not talking at 115,200 or 9600 on serial, not showing any thing new up on my network…

tmp3133

New Lua update is open source

No I don’t mean the new implementation that has sprung up and is early days – I mean the one that Zeroday put together. As of yesterday it’s using the new SDK 0.9.4 (I’m on the lookout for AT binaries using 0.9.4 if anyone knows where they are hiding)…

LuaSo what’s new? Well, the screen powers up making it clear which build it is on and a quick heap check shows a healthy 18k of RAM available. Sadly that crap is still in the firmware on power up.. I don’t know why they feel the need to leave that in – but as you can see it’s based on 0.9.5 and has 18096 bytes available.

Of course that’s all very nice but the implementation I was using yesterday drove me nuts due to it’s inability to call a simple web page reliably. At the time I had no idea if it was me, the interpreter, the board or what – but having had my AT implementation calling the site repeatedly without a hitch since then I can categorically state the issue was with the interpreter.

So what’s changed? Well for one thing the code is open source so HOPEFULLY instead of people rushing off to make a name for themselves, we might see some fresh eyes looking at this – in fact that HAS to happen really – lets hope we can look ahead to more features – more RAM. I’d like to see support for serial LEDs in the code as there is no way you can bit-bang with the interpreter fast enough to drive them  – simultaneously there is no doubt in my mind they are the future of lighting (single wire, 5v operation high brilliance RGB leds – look them up on Ebay). It would REALLY be nice if one of these boards could drive them with little more than a 3v3 regulator and a heavy duty 5v supply.

So, back to reality – I put my code back in – the same code that was driving me nuts yesterday.. and….

Sadly… same again… run the code live – it goes off to my web page and gets the time – make a file to do it and..

Note that a simple timer function and web page reduce the 18k of RAM to 12k!!

NodeMcu 0.9.4 build 20141222  powered by Lua 5.1.4
lua: cannot open init.lua
> dofile(“setclocktimer.lua”)
> 192.168.0.23 13544
192.168.0.23 13240
192.168.0.23 12944
192.168.0.23 12624
192.168.0.23 12648
Sent time request
time request processed
Sent time request
time request processed
04:32:35 23/12/2014

Once running I called print(head.node()) to check the RAM and sure enough – 12k remaining even though I’m erasing the COMM variable when I’m done with it. There is no further loss after that which is a good thing! The really excellent ESPLORER ide from Russia (I believe) is having trouble with the new version, something to do with handshaking – I found I had to have several attempts (and resets) to get the code up there – something that did NOT happen with the previous version of Lua – but sadly the guy does not have and English website so I don’t know how to leave him a message.

second=0 minute=0 hour=0 day=0 month=0 year=0
host=”www.scargill.net”

tmr.alarm(2,8000, 1, function()
if (year==0) then
     print(wifi.sta.getip() .. ” ” .. node.heap())
     conn=net.createConnection(net.TCP, 0)

     conn:on(“connection”,function(conn)
          conn:send(“GET /time1921681974.php HTTP/1.1\r\nHost: ” .. host .. “\r\n”
              ..”Connection: keep-alive\r\nAccept: */*\r\n\r\n”)
          print(“Sent time request”)
     end)

     conn:on(“receive”, function(conn, payload)
          hour,minute,second,day,month,year=string.match(payload,”.*timestr=(%d+):(%d+):(%d+) (%d+)-(%d+)-(%d+)”)
          conn=nil
          print(“time request processed”)
     end)

     conn:connect(80,host)
    
else
     tmr.stop(2)
     tmr.alarm(1,1000, 1, function()
     second=second+1
     if second>=60 then
        second=0 minute=minute+1
        if minute>=60 then
            minute=0 hour=hour+1
            if hour>=24 then
                hour=0 day=day+1
                if day>=32 then day=0
                end
            end
        end
     end
    print(string.format(“%02d:%02d:%02d %02d/%02d/%04d”,hour,minute,second,day,month,year))
  end)
end
end)

I suggest if you want to try this – you get my PHP code and make your own as the page is temporary – clearly I don’t want everyone using my web server to get the time but you can do this with any PHP page… as you can see the code is split in two.. and ASSUMES you already have a connection to your router.

Run as is it works most times. A timer (timer2) starts up 8 seconds after power up (easily enough for the board to pick up the WIFI connection) and attempts to call the web page . Because of the way Lua works (ie non-blocking) it sets up 2 callbacks – one for when you have a connection (and one for when you receive something from that connection. Finally the connect is made to my website.

Until the time is picked up nothing else happens. Hopefully, the connection is made and a GET request is made to the site for the time. Then when the board gets a response, the time is set and the connection is emptied to save space.

AT THAT TIME the timer (2) is stopped as it is no longer appropriate – and timer (1) is started up to show the time every second – incrementing seconds, minutes etc each time. The time is displayed once per second.

My new ESP-01 tester boardOnce it gets going it is fine – and if you run the code, it is likely to connect first time – but once you put it in a file – it seems to take several attempts to get the time. The AT code does NOT do this – only the Lua code.  Incidentally, Zeroday was very helpful in showing me how to use the callbacks – but it’s still not quite right!

And why it ends up eating up 6K of precious RAM is WAY beyond me…. thoughts welcome and if anyone speaks Russian – please let the ESPLORER designer know his IDE is acting up a little in the latest version.. also it he would care to NOT clear the screen when you close the connection – it would really prevent a lot of heartache when trying to screengrab output!!

(the picture of the little red board on the right is my new (couple of bits missing) board for testing ESP-01s – had a few of them made in China as I got sick of wires all over the bench. Plugs straight into an ESP-01 and an FTDI cable, has regulator, LEDS and some level shifting – more on that when I find out if it works or not).

NodeMcu 0.9.4 build 20141222  powered by Lua 5.1.4
lua: cannot open init.lua
> dofile(“setclocktimer.lua”)
> 192.168.0.23 13544
192.168.0.23 13256
192.168.0.23 13280
Sent time request
time request processed
04:52:55 23/12/2014
04:52:56 23/12/2014
04:52:57 23/12/2014
04:52:58 23/12/2014
04:52:59 23/12/2014
print(node.heap())

12648
> 04:53:00 23/12/2014

Note: The new Facebook page is coming along – still struggling to get the likes up to 100 – clearly Google+ is a lot more popular for this kind of thing. https://www.facebook.com/esp8266wifi