Monthly Archives: February 2015


Ideas anyone? Installed Domoticz just to see how well it might work… needs an add-on for MQTT here  - grabbed that, put the files in nodejs\node_modules\domo and ran node server.js as per the recommendation.. and.. it threw an error “Cannot find module “mqtt”

Update September 2015: MQTT is now part of the Raspberry Pi image for Domitz - just note that you need to add MQTT as hardware by going to setup/hardware. Tested with MQTT spy.  You can grab a complete Raspberry Pi image – or do what I did which was to add it to the existing image. The instructions are here.

6 lines of setup including clean-up can’t be bad!

However when we tried to install Domoticz from the instructions on an existing system, everything worked but I put in the wrong port for MQTT. I then went to bed and the next morning the installation had crashed – hardly a good start for getting my confidence up.

To cut a long story short, a complete re-install seemed the best idea and this time everything worked. 

Things I control – lights – lots of them – and RGB lights –lots of those too.  Once you have everything setup you can simply add new lights and when you turn them on or off, an MQTT message is generated…. with a light ID and it’s status. And so it is with RGB… but for one issue  -there is no RGB status  - which begs the question – how on earth do you use Domoticz to control an RGB virtual light – via Node-Red. It would APPEAR that you cannot. I’ve looked at their forums – people are asking the same question and coming to the same conclusion.

And with that I’ll put this to one side until someone tells me I’ve missed the point – but I can assure you that the MQTT package coming out of Domoticz when you change the colour of a virtual RGB light – does NOT include the colour!


Landing on two Feet

feetSometimes I really do land on 2 feet.  So the ESP/MQTT rig now appears bulletproof and in a timely fashion the Raspberry Pi appears just in the nick of time. All I need is an easy to use Mosquitto/Node-Red setup and …. what should appear but a link to this …

I can see it’s going to be a busy weekend of discovery.

I was wondering how to make the thing programmable without having to blow the flash – and it hit me tonight… give the unit a default unit number to prefix any subscribes… and… use MQTT messages to rewrite the default unit number and any other info – and reboot!! Easy (well, of course, it won’t be).

That’s enough for one day.


ESP12 and More Pins

ESP-12I’m just about to have a go at one of the larger boards – the ESP12 (or 201)…   so can someone save me (and others) re-inventing the wheel.

Here’s what I do to initialise an ESP-01 port bit GPIO0 as an output.

Firstly the setup..

// For GPIO2 just change the 0 to 2 - there is one init line.
#define LED_GPIO 0

then initialisation



and here it is set to 1.



As you can see, I’ve already figured out how to do the same with GPIO2 (though I’ve not used GPIO2 as an output yet)

So – what other pins can we use in exactly the same way and are the numbers as you would expect or different?? This general principle also seems to work for GPO4 and 5 but not for the higher numbers.


Rubbish plug-ins

Another rubbish spam plug-in - apologies to anyone who's been trying to comment this morning - I really do not understand some of the people that give stars to WordPress plug-ins. I used an anti-spam system that got high ratings - and it would not let people comment - when I went on the web, loads of people with blogs had the same issue. It's history now, I'll deal with spam by hand until I find something that actually works...



ESP8266 and MQTT Exciting Times

I don’t want to jump in prematurely here but those of you who have been reading the blog will know that I’ve had no end of problems with the MQTT stand-alone software on the ESP8266, but as each problem has emerged, the author (Minh Tuan) has been keeping in touch and working with me.  

MQTTLast week having apparently gotten everything working (that’s a real project continuously firing out temperature, responding to incoming time correction signals and accepting commands to turn GPIO0 on and off,  connected to a solid state relay controlling a lamp) when I realised that one of the real-life tests I’d missed out was … what happens if the broadband went off.

To my horror, it resulted in absolute failure.  The software would not reliably reconnect. I had some great suggestions from people – including one to think outside of the box, could it possibly be the MQTT broker not reconnecting properly. I worked on everyone’s suggestions to no avail.  I even updated my development environment (Windows 8 with Eclipse) to the latest SDK + patch (0.9.5) – no difference.  I can’t tell you now many evening hours I spent on this.

ESP-01Then this morning I had a contact from Minh to say he’d sorted the problem. I downloaded the code – and tested it – turned the WIFI off for a few seconds – turned it back on – HURRAY, reconnect no problem, re-subscribe no problem, queued outputs sent no problem. I was just about  to report success when I thought I’d see what happened if I left the WIFI off long enough to fill/overflow the queue (there is a RAM queue for messages and it includes incoming subscribes and outgoing messages, I had a hunch that a full queue might stop re-subscribes). Sure enough… the grim news on leaving the WIFI off for several minutes and reconnecting was that the software started up again – but all subscribes were lost – no room for them.

Thankfully Minh was around and immediately spotted this – we agreed that if the queue filled up completely and the WIFI restarted, the queue would be SCRAPPED.  Ok there are better ways and I’ve asked him to look at this – but for a quick fix he sent me a replacement mqtt.c file and… I put it to the test.

MQTT[6]3 hours later I cannot crash the software. No matter how long the WIFI is off it always reconnects properly. Some earlier strange issues on power up have disappeared (I feared they might be my own non-volatile variable storage additions.. but no).

The library has been updated accordingly just minutes ago and is here

You really should take a look at this. For the first time we potentially have the means to make an ultra-reliable control system with the ESP8266 boards. Recent mods to the code free up RAM (an issue for example with the Lua software) and so I have no doubt there is lots of room in there to add your own bits.

To recap for those who’re looking in for the first time, anything I refer to here will be covered in other blog pages – but I’m using MOSQUITTO – in my case running on a Diskstation NAS Drive for reliability but it will also run on various platforms and there are servers out there for people to use as well. I’m testing this with the excellent MQTT-SPY and all of this without having learn a word of Linux Smile  thanks to the excellent feedback I’ve had on this blog and the work of others around the world who like me are so keen to get this working.  If all goes well I can now concentrate on mastering the likes of Openhab so that once I have boards in place controlling stuff, I can easily monitor and control the boards themselves from a mobile phone – and for the first time with a little security in place – the point of investigating MQTT in the first place!

phpIncidentally, the PHP page I use under CRON to push the time out to my MQTT broker – I had some fun with that as I realised it was pushing out rubbish (wrong time) and further to a PHP upgrade at my provider – was throwing in warning messages to boot. Here is the latest working version (been up there running 24/7 for a week now) with security information altered to protect the innocent. To keep things simply, the dawn and dusk information is only accurate to the nearest minute. That lowers the number of times it will be updated and as I keep this in FLASH, the number of times the FLASH is updated.

error_reporting(E_ALL ^ E_NOTICE);

function varcheck($var, $default)
return isset($var) ? stripslashes($var) : $default;

$locn = varcheck($_GET[‘loc’], "Europe/London");
$lon = varcheck($_GET[‘lon’], 55);
$lat = varcheck($_GET[‘lat’], -2);

$dateTimeZoneLocal = new DateTimeZone($locn);
$dateTimeLocal = new DateTime("now", $dateTimeZoneLocal);
$localDateTime = date("H:i:s d-m-Y", time());
$localDisplayDateTime = date("H:i l d-m-Y", time());

$mqtt = new phpMQTT("your.mqtt.server", 1884, "whateverYouLike");
if ($mqtt->connect(TRUE,NULL,"yourwifilogin","yourwifipass")) {   
            $sun_info = date_sun_info($localTime, $lon, $lat);
            foreach ($sun_info as $key => $val) {
                if ($key=='civil_twilight_end') $mqtt->publish("dusk",(int)(($val %86400)/60),0);
                if ($key=='civil_twilight_begin') $mqtt->publish("dawn",(int)(($val %86400)/60),0);

Hopefully now I can stop worrying about reliability and start having some fun. I have suggestions for better ways to store things in FLASH and there is much to learn about Node-Red, OpenHab and much more so this is really just the beginning.


Raspberry Pi 2 Fast Enough?

The Raspberry Pi is a nice, cheap little computer but for me it has never been fast enough – I’m not interested in making another media server (I have a DISKSTATION which does that just fine) but as I’ve recently been working with MQTT in my home control setup, I did think it would be nice to have an MQTT broker and some ability to send commands to it in one little reliable box. 

Repeated messages out there indicate that the Raspberry Pi is pushing it’s luck to do all of that at high speed as it approaches the limits of speed (and possibly even memory).

What I’ve been looking for is the same thing with much more memory and much more speed. Well, how does (claimed) 6* more speed and twice the memory sound – for the same price?

I’m sure those who have recently purchased the original Raspberry Pi will have a million reasons why it’s not necessary – and I feel sorry for them but now it looks like the Raspberry Pi II (2) at long last has the power I need.

I wonder how long it will take before the price settles to what we would expect – I have NO doubt that early copies will be expensive – that tends to happen in Britain.

And as for Windows 10 – apparently Microsoft will make this available for free – that could be desperation or it could be EXTREMELY good marketing – for those who don’t really want to get into Linux – Windows development + Windows in the embedded code… has to be some mileage there.

More on this when my board turns up!



There’s a new MQTT-SPY out – here This program has been invaluable to me throughout all the time I’ve been testing and learning about MQTT. It sits on my desk running constantly and never falls over. Properly set up it can send timed messages out and coming soon – logging graphs – the author is very helpful – and it’s free – what more could you ask for.




Memory use ESP8266

Can someone explain this to me..

I’m using the ECLIPSE environment in a PC and only starting to get to grips with the MAKE files – I really still don’t understand most of what’s in there.

I’m looking at the MQTT installation which is one of the easier ones (I don’t understand why the likes of the LUA compilation throws out 18 million lines of un-decipherable gook while the MQTT files churns out very little – only showing you what you need to know about – i.e. errors).

So I understand how non-volatile storage is being done – at the segment 3C000  (I’ll probably get the number of zeros wrong  but that’s not important here).. So we blow some code at 0000, we wipe a little bit at 3C000 – which seems utterly pointless as the startup routines check a checksum at that area to see if it needs wiping/updating…  and then more code at 40000… now that last block seems to fill up rather quickly..

It not possible and indeed more sensible to start at 00000 and work all the way up in one block, leaving, say some blocks at the top free for non-volatile variables. I’d give this a shot myself but I need to understand why everyone splits up the code like this leaving a huge chunk of (unused?) memory down near the bottom.