Monthly Archives: May 2016

Talking ImperiHome

I just added another useful tool to the home control arsenal – speech – not on the PC but on my phone. As regular readers know I use ImperiHome a lot – talking directly to Node-Red to control stuff – and that’s fine – it works – it’s not the only package – I also use Blynk. I just found another reason to concentrate on ImperiHome.

Today I discovered what the “API http server” in ImperiHome is for, at least, one use for it. You don’t normally need this with Node-Red as the phone talks to the Node-Red http link and that’s all that is needed. However I was aware that there was a TTS Engine available in ImperiHome but had never taken the time to find out what it could do.

Now I know. You can fire text at the API from Node-Red and it will speak the text, even when the phone is sitting idle and it sounds ok!!

So the first thing you need to know - in SETTINGS, GENERAL PREFERENCES in ImperiHome, tick the API server.

You need to know the IP address of your phone  - so that kills using this outside of the house or office unless someone can think of a wheeze. You should ideally do an IP-MAC binding on your router to ensure the phone always get the same internal address when on the WIFI.

And with that done, you’re almost up and running.  In Node-Red you need this simple SUBFLOW – create a new sub-flow, call it “My phone” for want of a better name and create this.

SubflowThe HTTP request is empty – the work is done in the orange function – put this in the function…

msg.url="" + msg.payload;
return msg;

That’s it – you’re done. Whatever you send in the payload to that sub-flow will speak on the phone. Couldn’t be easier.  Oh, that IP address – that needs to be the IP address of your phone.

June 2, 2016: I have found a slight bug. So you can let the phone go idle and run other tasks – the speech continues to work – but if you go out of signal area, perhaps onto a mobile network then come back in – noting that the mobile signal is now off and you are on the same IP address, no speech. Bring the app to the foreground – the speech comes back.  I reported it and for once got quite a quick response – they think it might be Google power management shutting the API down – so looks like some re-writing may be in order.. will have to wait and see but at least they’re aware of it.


Background Beavering

You could be forgiven for thinking I’ve gone off the boil as I’ve not written much in here this week… far from it in fact. This week I’ve been working on my ImperiHome setup and the new Raspberry Pi software.

ImperiHomeImperiHome: In case you don’t know, ImperiHome is an app for Android and IOS that enables remote IOT control. It does this by trying to appeal to just about every system out there, none of which I use.  I’ve taken the approach of having IBM’s Node-Red control everything – and thankfully ImperiHome has a generic API to allow control if you don’t have ANY of the devices it supports.

I’ve written more than one item on this subject and I have to say despite a rather lacklustre approach to answering people’s questions by their team and something of a lack of generic controls (such as a momentary push-button), the product actually works and works quite well. I have RGB lights, relays, sensors and a host of gadgets attached to Node-Red. Those which are required to just come on and off at varying times of the day are controlled by my BigTimer (which, recently updated, works a treat – or rather, it does if you remember to set the time zone when setting up the Pi as I found out last night when all the lights were still on at 2am, defying all explanation until my wife said “did you ever set the clock on that thing?”).

Those gadgets which require interaction are controlled by ImperiHome on my HTC Smartphone.

On the subject of Node-Red, we are promised non-volatile global variables in future by the Node-Red team and I for one can’t wait – but for now I’ve just completed a function to save a global object (buffered in time) when any change is made. That global object forms the variables used in my ImperiHome project – so now at last, the phone is always aware of the state of my lights – a handy thing. Essentially the object contains a counter which is set whenever any other variable in the object is altered. This is monitored by a timer which also kicks in on power-up.  If the counter is true, it is decremented – if it hits zero I update the file on SD which contains that object.  I also check to see if the file exists – and if not, I create it. If the file DOES exist and the object doesn’t – I populate the object.  So now, my lighting and other settings can survive power-cycling.

Raspberry PiRaspberry Pi: On 10/05/2016 the Raspberry Pi foundation put out a new release of Jessie (Debian) and with it, items you might expect like better support for Bluetooth etc., but then something I wasn’t expecting – a decent backup program. After (what seems like) years of struggling with arcane Linux commands some of which I never really got to grips with and hence never achieved a satisfying backup solution, at last, a simple push-a-button backup program that not only allows for live backups, but also allows for the use of varying size SDs both larger and smaller.

WHY did this take so long…  I can’t tell you how this has changed things for me – backup time is reduced, no need to shut the house controller down when I’m doing backups, the use of smaller SDs, running multiple copies of the same software on different boards – the list goes on.

But for days I’ve been struggling with upgrades – the backups just did not want to accept upgrades (apt-get-upgrade) and when they did, invariably Node-Red would fall over with missing nodes etc. I didn’t know if it was the backup program or what…  (I knew it was not the SDs as I use only good ones). Well, it turns out that my script was in need of bringing up to date. I still scrap node, npn and node-red and re-install to get the very latest but I’ve done it a different way, more by trial and error, but I got there in the end and now my backups and restores are working perfectly. I’ll publish the updated script soon, replacing the older one and I’ve added some tricks I’ve picked up along the way from readers like you.

Tiny part of my controls

I started this blog entry before our BBQ yesterday and here I am up early on a Monday morning finishing off the job. The lights worked a treat last night now the clock is set correctly – thanks to NTP it will now stay that way.

Coming up this week hopefully – a couple of new boards from Friendly Arm, the new Nextion display and more. But first things first, some supply shopping,  I’ve lost a filling and Maureen’s done her foot in – this should be good – dentist and hospital – in Spain (and not in the tourist areas where they speak English).


Ivona Again

A recurring theme in software development is re-inventing the wheel because you don’t know about or don’t understand what is available already. Well, sometimes it is for me anyway.

And so it was that my PERFECTLY working, well appreciated but totally un-necessary workflow for Ivona speech on the Node-Red – went in the bin.

But first:

So (here come the links) – Ivona is an online service from Amazon, free within reason – with REALLY nice quality sound. The Ivona NODE is a free node that lets you talk to Ivona in Node-Red easily using, say a Raspberry Pi  (which in it’s latest incarnation remains the fastest and easiest to use SBC in anywhere near that price range) – as easily as passing a text string to the node – and out pops high quality speech. Don’t like the idea of relying on an external service? Read on…

Yesterday we started working on a better caching mechanism to reduce calls to the Ivona speech API – and this morning – I took a LONG look at the instructions and….. it’s already in.

So here is the MK 2 explanation of how to use the Ivona Node-Red node – this time with the benefit of having actually read the instructions.

It is THIS easy.Ivona

Yup.. all that buffering work for nothing. But I’m making assumptions – let’s start from scratch:

We’re talking about getting high quality speech on, say a Raspberry Pi – using Node-Red.  In my case Node-Red is the central control for my home control… and speech is part of that – I want to know when devices are logging in etc.

There are speech synths for the Pi and other SBCs – and not to put too fine a point – most of them sound like someone being strangled. Ivona on the other hand provides REALLY nice speech in a range of languages. Google used to have a good API but they got greedy.


From my Pi script…….

sudo apt-get install -y mpg123

and in the .node-red directory wherever that is on your system…

npm install node-red-contrib-ivona

Oh, Err:

In my original version, having put the speech into a first-in/first-out buffer,  I passed the output to MPG123 – a program (accessed by an EXEC function) that plays MP3 files. Why? Because the Ivona node takes in speech and dumps an MP3 file on your disk/SD with the recording in it.

All fine and good but what about overlapping messages – and what about constant use of the API? Well to cut a LONG story short it is all handled in the node itself. If you play the same message twice, it just uses the file it made last time.  The node successfully queues messages as well (all that work…)  If like me you didn’t read the instructions – the file went into the /tmp directory and you probably thought you’d have to develop your own file system.,

And now:

So – let me show you the setup for the Ivona Node – and then I’ll go through it piece–by-piece.

See installation above – see also my original blog for more details and putting in the credentials that Ivona give you. A one-off task and free.



So… in the message area above – just leave that as it is… the “moustache” system refers to using braces around stuff. It can take a little grasping but you don’t have to here…  In this case – the message entry simple means – if you fire a msg.payload like “Hello there” into the node – then it will be used. You’ll do that by, for example an INJECT node (see above) sending TEXT in the payload.

Voice: Well that’s simple enough – dropdown box – pick a voice! For UK users , Brian is good.

Exec:  Here you put in the name (and path if needed) of a program to play the file. I definitely recommend installing MPG123 as it is easy and reliable. {{{file}}} simply means – use the file generated by Ivona node.

File: At the start, to the left of {{{ put the name of the directory you want to store files – I made one called “recordings” under my /home/pi directory. The directory should exist before you use it. Don’t forget the slash at the end of the directory.

Then you see a number of items which together take the name of the speaker, the language and the actual text and make these into a filename. I suggest you leave them as-is. In this case..


That’s it – when you fire speech at the node it should play it (assuming you’ve set the audio output to the right place – check your audio first – I didn’t and got ZILCH – then I realised it was set to go out of HDMI and the monitor I was using had no speakers!!!)

The sound will stay in that file. The next time you go for an identical piece of text with the same speaker (Brian in this case) – it will merely play back the file you already have instead of going off to get more. In a closed system with fixed messages, eventually the Ivona service won’t be needed.

This offers up a possibility for sound effects.  Let’s say you send to Ivona “Alert” in the payload. In my case that will generate “brian—alert.mp3”.  Now, let’s say you have a nice alert sound effect…  by simply giving it the file name “brian—alert.mp3”, that file will be used instead of Brian saying “alert” – so you can have a complete library of MP3 effect files used alongside your recorded speech!!! All without any special mechanisms.  

Fire multiple messages and they are all played in sequence without you having to worry about overlaps.

All in all an excellent node – just a shame some of us didn’t read the instructions the first time around!!

Update May 22: I have now implemented an improvement to the Ivona node and sent this back to the author – time will tell if he implements it.

So it would be nice to be able to control the VOICE dynamically. For example – you might wish to have your gadgets TALK. 

If you want Ivona to work via MQTT the problem is you ONLY have TOPIC and PAYLOAD. The latter is obviously the speech.

The changes I’ve made allow you to strap an MQTT input node to the Ivona node – with the topic subscription ivona/#

This means that Ivona will listen to any message send by MQTT to ivona/  - but if you put a name after the topic – for example ivona/brian – that will change the voice temporarily!!

In the Ivona .JS file is a line as follows..

text = mustache.render(node.message, msg);

Affer that line, add this code (and then restart node-red of course)


// Dynamic voice control using topic: ivona/XXX where XXX is a voice - i.e. brian.

node.voice = config.voice; // default voice otherwise any change will be permanent
if (msg.topic.substring(0,6).toLowerCase()=="ivona/")
    for (x in voices)
         if (voices[x].name.toLowerCase()==msg.topic.substring(6,msg.topic.length).toLowerCase()) node.voice=x;
// end of modification

Simples! And so here we see MQTT-SPY in action.

ivona on mqtt-spy

Or with Brian talking…

ivona mqtt with brian


And so what about sound effects?  Unless you want the words “alert 1” coming out for example, you need to ensure that pre-recorded sound effect files always use the same name. As the default in my example is “emma” – ensure you do NOT send a voice when you want a sound effect.

To make this easy and compatible with the above MQTT – I used “—“ as a separator so that for example you might say…

Topic: ivona/brian

Payload: alert 1—This is an alert

The first part is automatically sent to Ivona with no topic – hence the default voice and hence the need for a file emma—alert-1.mpg  whereas the second part should be sent with the topic.


And here is the code for the sub-flow:

var tPayload,tTopic;
var ar=msg.payload.split("--");
if (ar.length>1)

Here is a VERY handy list of star-trek alert mp3 files.. – just rename the files to have dashes instead of any spaces – and prefix with emma--


BeagleBone Green Wireless

Beaglebone GreenThe BeagleBone Green Wireless is the result of a joint effort between Seeed Studio and It is based on the open-source hardware of the Beaglebone Black and they’ve added 2 Grove connectors. You might recall I did a blog on the Grove stuff a while back – basically the usual sensors for temperature, humidity, moisture along with relays etc., all on nice little boards with a standard connector.

Important items here are: WIFI and Bluetooth, AM3358 1Ghz ARM Cortex A8 processor, 512K RAM, 4GB EMC, 3D graphics accelerator, NEON floating-point accelerator, 4 x USB 2.0 connectors.

If you check out the Seeed site they have all of the little adaptors and so here is a system you can put together with minimal or no soldering.

Planned shipping 31st May – price $44.90. Apparently Mouser and Digi-Key are distributing internationally and NKC Electronics in the USA.

So this isn’t going to be one of those “gee this is wonderful” reviews – I’ll comment as I go along – it may be nice, it may be brutal. The first thing that grabbed my attention was 512K of RAM – I don’t know why people do that when the leaders out there like Pi have 1GB but I guess it all depends what you want to use these boards for.

So, enough of the official press release stuff, here’s a photo taken this morning on my bench as I took a first look at he BeagleBone Green Wireless. Clearly they want you to use this with their other modules (though you don’t have to) because as well as the two 4-way connectors on the side, there’s a plug in board with a TON of connectors.

BeagleBone Green Wireless and top hat

I’m quite at ease with a soldering iron personally but plugging these two boards together (see photo above)… well, I can see the attraction – they’ve sockets for EVERYTHING on there – as you likely can’t read them – the 12 sockets are:

2 UARTS, 2 analog inputs, 4 digital I/O (totalling 7 I/O pins) and finally 4 I2C sockets… now as it happens I just bought a couple of I2C I/O expanders so straight off I can get 16 extra (well, 14 when you take off SDA and SCL) outputs for a couple of quid!! The switch on the left lets you switch between 3v3 and 5v and I’ve not figured out what the one on the right is yet.

BeagleBone Green WIFI

There are 4 USB 2 connectors on the left of the main board, Power is micro-USB and there’s an on-board ceramic WIFI antenna.  3 buttons include reset, power and user. The board is the same size as a Raspberry Pi (but rounded) and there are 5 indicator lights in a neat row. At the bottom there’s a 6 way connector which basically is power and serial I/O. There are also a couple of connectors for external antenna.

All very pretty. I powered it up.

A blue light over on the right of the image above started to flash along with a green light upper left.  At this point I had no SD in.

Before long a plethora of lights were flashing and after several seconds this settled down to a blue and green lights over to the right – and one green and 2 blues on the left (top behind the USB sockets above).

As I often do – I got this far without reading a thing. Could I go further? With no HDMI out I wasn’t that sure what to do next without cheating and reading online – so off I went to check for WIFI access points on my phone. YES – “Beaglebone80997” showed up. I signed into it, picked a web page at random and sure enough my phone came up with a VERY pretty home page.

My WIFI is called “wififorus” and I was a bit confused to find that the board was seeing half a dozen of them with numbers on the end – no idea why but I picked the first one – put in the password and also it wanted a “board password”  - I was unsure what that meant but assumed a new password – so I put one in. That worked.  No visible change in board lights but I was told the board was now

Remember this is all played by ear. I hit OK and a page of instructions came up on the web page – this was all looking very polished up to now. All in good English as well.

It told me that the board was running with Debian, Linux drivers for countless USB gadgets and that there is an interactive tutorial. I think this info is for the BeagleBone BLACK as it was mentioned. There’s even a script for flashing outputs… right there at the start.

The Cloud9 IDE is supported so that you can develop live on the board… somehow I didn’t think that would work too well on my phone – so I opened a browser on the PC to the address given.  At first nothing but just as I was getting despondent…. the page popped up on my browser – all local. Call me easily impressed but this is one of the first boards I’ve reviewed (and I’ve done a lot of reviews but not Beaglebone) where everything worked as expected without having to read anything up!!!

support build in

I remember one of the guys telling me that I should update the software – so off I went to updates… (remember the board was merely plugged into USB for power and I was doing this on my PC browser – what could be easier).  Here are the instructions as read off the board.

The following was me going down the wrong path but I’ll included it anyway.. if you can’t be bothered with a sob story – skip to “The right path”.

The wrong path:

There are multiple ways to run initial software on your board, but it is likely that the simplest way to get an update is to create an exact replica of a bootable microSD card and boot off of it. The BeagleBone Black Rev C has 4GB of eMMC storage (2GB on previous revisions) that can be initialized by a program booted off of a microSD card. If you want to update to the latest software image for your board, this is a way to do that.

Step #1: Download the latest microSD card image

Download "Angstrom Distribution" from

Note: Due to sizing necessities, this download may take 30 minutes or more.

The Angstrom Distribution ships with the boards. The file you download will have an .img.xz extention. This is a compressed sector-by-sector image of the SD card.

ANThe second item down was for various boards including the Beagle Green Wireless – this is nice as often when you get a brand new board (released this coming weekend) there’s zilch out there for it… but in keeping with my experience so far this is looking painless. 775 Meg to go – time for coffee…..

And then it all went wrong for a second…

To turn these images into eMMC flasher images, edit the /boot/uEnv.txt file on the Linux partition on the microSD card and remove the '#' on the line with 'cmdline=init=/opt/scripts/tools/eMMC/'. Enabling this will cause booting the microSD card to flash the eMMC. Images are no longer provided here for this to avoid people accidentally overwriting their eMMC flash.

I don’t have the foggiest idea what that paragraph above means. Thankfully elsewhere there were instructions for unzipping the file with 7-zip – that produced an .img file – and I know what to do with that – WinDiskManager !!!!

Sure enough – the image wrote successfully to one of my 16GB micro-SD drives. That gave me plenty of time to drink my coffee. I blew the image – and realised that unlike a Pi image – the result was unreadable by PC!! This was starting to turn ugly.

I pulled out my trusty WINSCP and put in the IP address. I had no idea about username or password so picked one at random. The board started to connect then popped up a window telling me what the username and password were “debian” and “temppwd” – handy! I put that into WinSCP and up I was up and running!!!

With only the vaguest knowledge of Linux I plugged in the microSD into a USB adaptor and plugged that into the board. Yet another light came on – this time a green light near the USB socket. 

GroveEncouraged by this success I went off looking for devices… in /home/debian I created a directory called “petes” (as I write this I just know this is all going to fall to pieces as I haven’t a clue what I’m doing).

I then tried:

sudo mount /dev/sda1 /home/debian/petes

I have to tell you – I was DEAD CHUFFED when it actually worked. Maybe all this reading about Linux is doing some good after all. NOW hopefully I could follow the instructions. Sure enough there was a boot/uEnv.txt file. Of course TYPICALLY I didn’t have permission so I had do go into a terminal (instead of WinSCP file few) and use that awful NANO editor.. “sudo nano /home/debian/petes/uEnv.txt”

The problem then was – the instruction above – line starting #cmdline  - simply didn’t exist.


The right path:

Anyway it turns out that in trying to update the eMMC memory, I was using the wrong IMAGE – I asked SEEED support and they came back very quickly with a user forum which had the link to the latest image. I blew that onto an SD and tried holding the USER button down while powering up – SURE ENOUGH it updated the eMMC and then I could run the board without the SD in place. Magic.

I just happened to be looking at the online documentation when I noticed a reference to NODE-RED !!! Well, quite excited I clicked the button and it promptly tried to run Node-Red but with the wrong IP address. I corrected that and sure enough, Node-Red came up.  But here’s the thing – Node-Red with NODES FOR GROVE!!!!

In all the reviews I’ve done – I have never seen a board come out of the box already kitted out with Node-Red and full support for I/O – the nearest is the PI with Pi GPIO support – ALL of the other boards I’ve tested just left you to get on with it.

Could I be this lucky? I didn’t get any sensors with the board but I just happened to have a bunch of them from some time ago. I plugged in the top board and of course that immediately killed the processor. I should know better. I rebooted the board and shortly thereafter tried again – Node-Red came up.

I plugged the relay into one of the GPIO connectors – marked 115/117. I dragged the relay node – and… there’s a helpful PICTURE!!!! Now why can’t others (like me) do that…


I selected GPIO 115  (seriously!!!) and added two inject nodes – one sending 1 – the other sending 0.


It WORKED.  I tried the temperature sensor and that produced a strange value – then I realised – that my temperature sensor though pin compatible was not the one they had in the photo – fair enough and again – good idea including pictures!!!

I tried the servo – I had one of those – none of the connectors on the top seemed to match the pin selections so I picked the first 4-way connector on the main board. I made 2 injectors – one outputting 0, the second outputting 100.  IT WORKED… straight out of the box, no soldering – I had a servo up and running. This is FUN!

I don’t have all of the sensors and I noticed that some of the little modules I have don’t appear to have nodes for them – at least not out of the box. I will revisit these at a future time.

I tried the LED output – there are – wait for it.. SIXTY FIVE OUTPUTS!!!

And that – is that for now. I need to get more plug-in sensors etc. to give this a good hammering..  but if you ignore my incompetence with the setup – we’re talking out of the box to having gadgets running on Node-Red in – what – MINUTES.  This then from the perspective of someone absolutely new to Beaglebone and this board – is a TOTAL improvement on previous experiences I’ve had with boards. I’ve reviewed lots of them and of course I’m a Raspberry Pi addict – especially with the extra power of the 3, but given that I’ve not even read the documentation – to get this far in so short a time with so little effort…  I’m WELL impressed.


Between ease of use and online programming this is a good board.  Normally I would install my own Node-Red. In this case it is pre-installed with the various modules to control their boards.

So one might think it would be easy to just add one’s normal nodes to Node-Red? By default I initially could not add nodes – even though trying both globally and normally, the directories were created – the nodes were not added to Node-Red.  I could not start from scratch as that would mean losing the control nodes they have fitted.

Then I discovered that the settings.js file at /usr/local/lib/node_modules/node-red could be altered (as root – which initially has no SCP password but once logged in you can use passwd root in a terminal to add one)

Uncomment and modify the file as such..

nodesDir: '/home/debian/.node-red/node_modules',

After stopping node red (again as root  - service node-red-stop) and then restarting (service node-red start) – my BIGTIMER sitting in /home/debian/node_modules/.node-red-contrib-bigtimer  appeared (I created /home/debian/.node-red  and had previously installed the timer from there).

From there, as the DEBIAN user, I was able to install the various nodes I would normally use – including the admin node (the global version didn’t work so I tried the local version and that installed.

I did however have issues installing some of the nodes – unusually i had to install them as root – and SQLITE3 node was just NOT having it – I also noted that all of this took longer than a Raspberry Pi 2 and MUCH longer than a Raspberry Pi 3. MQTT also failed to start up – even though Webmin SAID it was starting it up.  Clearly there is some setup here interfering with what would normally be a simple setup.

I hope you found this useful. For more see here – officially announced today -



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

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

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




Raspberry Pi Backups

Backups the easy way

One of my biggest issues with the Pi has always been – backups.  Using a PC to backup a 16GB SD is a pain and of course necessitates turning the Pi off to remove the SD. Well, now there’s a better way.

A slightly less painful way than backing up the whole SD with a PC is to use BerryBoot which can do a good job of running Raspbian and at power-up giving you the option to store a compressed version of the SD to USB memory.

It was with sadness then that I updated Raspbian today to the latest version.

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install piclone geany usb-modeswitch
sudo apt-get install python-pigpio python3-pigpio

Nice theory but in practice, on reboot, I ended up with an utterly dead board – something to do with the update and BerryBoot.  I’ve reported this to the BerryBoot author.

But here’s the thing – the latest version of Raspbian Jessie now for the first time includes a live backup facility. Once you have this you’ll wonder why it was not always this way – especially if, like me you’re not a Linux fanatic.

It does not stop there however. Not only will this new utility copy from live to SD (I’ve yet to figure out how to run the SD copier from the command line but it runs from menu – accessories – SD card copier  without issue) but also – and I’m quite excited about this – you don’t need the same size SD – which means expansion or reduction is now a snap – thank heavens for that.

So in order to test this new backup facility – I grabbed the latest Raspbian (not the NOOB version) and blew it onto a16GB SD with Win32DiskManager as usual. I started up the Pi3 and put another identical SD into a convertor and stuck the USB convertor into a spare USB slot. I ran the backup, powered down, swapped SDs over and rebooted – no problem at all. Fantastic.

For my second test – I ran my script on the Raspberry Pi 3 so it was fully up to date with all of my tools – Apache, PHP, Mosquito, Node-Red, SQLite etc. – on a 16GB card. I then made a  backup the same way as above to an 8GB card…  the transfer took place while writing this blog – all in around 15 minutes.

I powered off the Pi3, put in the 8GB card and powered up. IT WORKED!!!!

With that success behind me I decided to get brave. I took the new card and put it into a Raspberry Pi 2 – surely this could not possibly work? IT WORKED!!!!

For some this may be nothing – for others a life-saver – so now it is easy – without even powering down to make copies of a working system – even on different size cards and it would seem interchangeable between Pi2 and Pi3.  Other Pi-like manufacturers take note!! Now I can be WAY more adventurous as it is so easy to make backups.


connectionsWhile I was on I thought I’d try the new pigpio GPIO interface.

Firstly I started up the pigpio daemon – at this point being new to me I have no idea how to make this run at power up – nor do I know if there is a reason you should NOT run this at power-up.

sudo pigpiod

Bear in mind that everything was originally set up on a Pi3 – but by this time I was running the SD on a Pi2, not the Pi3.  I like doing things interactively when I’m learning so I simply typed python <enter>

I was greeted with >>

I fastened a LED/resistor combo (I always keep a few ready with female connectors on them for testing)  between connector pin 6 (ground) and 12 (GPIO18).

>> import pigpio

>> mypi=piggpio.pi()

>> mypi.write(18,1)

And it worked – the light came on and off when I used the same command with 0 as the last parameter. I’m dying to try the other more complex commands in a Python program. indeed today everything just seems to be working – the sun is shining, my gadgets are working – what more could one want. I have one duff Electrodragon (more on that later) but apart from that…


BMP280 for HC 2018

I have just added a working BMP280 implementation into the Home Control 2018 code (see right menu in blog) returning temperature and pressure.  Add that to the (already implemented) BME280 code, Seeed display, 16,channel PWM, port expansion and more, it’s not been a bad development week really! Manual updated.

The BMP280 as you know does not have humidity – but is cheaper than the BME280. The manual is updated and has details on addresses etc.  Just waiting now for the A/D board to turn up from China.  I’m quite getting into this i2c expansion.

This little picture attempts to show the current state of play for Home Control 2018. No doubt I’ve missed loads off but as you’ll see quite a bit has been added recently.

Home Control 2016


Speech … the Final Frontier

Ivona speechUpdated 02/01/2017

Buffered, SD-cached high-quality human-like speech working alongside sound effects for your IOT project.

Requirements: Raspberry Pi or similar with audio out, Node-Red and a little of your time.

But you don’t need this blog – there’s a WAY better way to do this – in my latest entry about the Ivona Node.

As you may know I’ve done a couple of blog items on Speech on the Raspberry Pi over time. I was quite happy with the Google Translate API until recently when they stopped making it available for free,  so I was forced to go off in search of alternatives and settled on local synthesizers like eSpeak – the problem being – they generally sound AWFUL. eSpeak sounds like someone’s dog being strangled.

And so it was that one of our readers (thank you for that) contacted me and suggested I take a look at Ivona.

This is new: I’ve just gutted the code from the original blog to produce a much better version, better thought out with cacheing for off-line use, unifying speech and sound effects into an auto-created library. In the event of an external comms failure so that you cannot access the outside world, your Ivona is going to fail and this happened here at Bedrock – SO the idea hit us to CACHE all mp3 files (assuming you’re not going to do unique messages every time). That way the SECOND time you ask for a message you will already have a file with that name – the total file space for dozens or even hundreds of these MP3 files is a tiny fraction of a typical SD storage capability and not even worth taking into consideration in most projects. Currently we are working on modifying the Ivona node to handly dynamically changing voices. More on that soon.

I originally did a video to accompany this blog -

If you use the link I’ve provided above (to Ivona) and select a suitable voice on their web page then enter some text in the box, you’ll find it does a pretty good job. Ivona is free to developers – just grab a free account and get an API key and secret key. I spent the entire evening playing with the code and when I looked at the percentage of my “free use” – nothing  - so you’re unlikely to run out of free use and with the mods here even less so.

Take a tip when you copy and paste that API code information (which you should immediately on getting an account as you won’t be able to get the same key later) and pass them via NOTEPAD (paste then copy again) to get rid of any hidden characters.

So now you have an API key and secret key to be used in the Node-Red node Ivona (node-red-contrib-ivona)

Your API key for Node-Red is the ACCESS code and the PASSWORD is the secret key !!!!! I used my email address for the username – this is all a bit non-intuitive so beware.

Over to Node-Red. So what this node does is take in your TEXT, send it off to Ivona which returns an MP3 file with your chosen speech. You should also have MPG123 installed on your end computer (I’m using a Raspberry Pi2 for all of this).

In the simplest case you would send off your text, get the MP3 file, send that to mpg123 for playback. But then you are stuck with a file… and what if you send 2 in quick succession – they will overlap each other as Node-Red runs asynchronously.

Here’s the solution and it’s a lot better than I had in the past. You can fire off several speech requests including requests for other .mp3 files.  for special effects I have a bunch of MP3 files already stored – such as “alert” and “hailing frequencies open”.

Ivona speech

In the example above (that red block is NOT the Ivona node – it is a subflow I wrote – more in a minute)… let me show you those two INJECTS on the left..

Ivona speech

Ivona speech

The first has “alert” in the topic and some text “Red 1 logged in” – the second simply text.

I can click one, wait for it to speak and then click the second – or I can chose not to wait, clicking wildly – and they will still play in order.  So if you specify speech for the TOPIC AND THE PAYLOAD, simply both will go into the queue in order.

How do I do that – so looking at the red Node-Red SUBFLOW…


The yellow’ish blocks are user functions, the red block is a Node-Red EXEC functions – the purple item is a simple 1 second delay for good measure. The purple item is the node-red-contrib-ivona node.

I take in text… if the topic has the word “alert” in it – I put that on the queue BEFORE the main text – other than that there is NO difference between the two.

If there is no text, just a blank message coming in, I check the queue and if not empty, try to use the items on the queue (first in, first out) one at a time.

The INJECT function is needed to start the ball rolling for the first item in the queue. Once I find text in the queue, it is send to the Ivona node IF such a named file does not exist - and then on to the mpg123 player – either way setting a BUSY flag so that those one-second ticks can’t pull another item off the queue until I’m done.

When done – I  send empty messages back into the input to trigger off any further items in the queue.

Here is the main function:

var frompush=0;
if (typeof context.arr == "undefined" || !(context.arr instanceof Array)) context.arr = [];
if (typeof == "undefined");
if ((msg.payload==="")&&(
if (context.arr.length)

if (msg.payload!=="")
// just push but not recursively
if (frompush===0)
if (msg.topic!=="")  context.arr.push(msg.topic);
msg.fname=msg.payload.replace(/ /g,'_');
return msg;


Note the busy flag and the use of PUSH for the queue.

The “copy file to payload” is trivial – Ivona returns the filename in msg.file which is not where I want it.

return msg;

The reset flag function simply clears the busy flag and returns a blank message.;
msg.payload=""; return msg;

The trigger is the Node-Red DELAY function simply set to delay for one second and then pass the message on.

Ivona speech


The MPG123 EXEC node calls mpg123 and passes the file name as parameter. The DELETE node simply deletes the file that Ivona creates… Here’s the Ivona setup. Put your credentials in the top box.


Note the triple moustache {{{}}} -  Ivona examples use a double – but that then interprets slashes and we don’t want to do that because we have a file path in there.

And that is about it – works a treat and produces high quality buffered speech – for free – for your IOT endeavours.

Pick your own file directory (note that I used /home/pi/recordings but that isn’t in any way special) and any words or phrases you want SOUNDS for instead of voice – simply replace with files of the same name (not that spaces are replaced in files names by underscores).  So “alert 2” as a file name would be “alert_2.mp3”

Of course I'm always on the lookout for alternatives, especially those which profess to need no connection.

This looked great - and the short  example in their videosounded like a human. Sadly, on installing this on the Pi (it can't play without drivers which don't come on the Pi as standard - but it can generate files) I gave it my favourite micktake of a certain politician "I'm a little tea-pot short and stout, open my mouth and shite comes out"...  and I have to say it made an UTTER and complete mess of it, sounding like a quite ill Dalek. Think I'll stick with Ivona.


Remote checking Home Control Units

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

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

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

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


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

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

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

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

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

Click on any of these images for larger versions.

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

I hope this proves useful to others.


Home Control and Nextion Updates

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

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


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

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

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

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

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

Logic analyser

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



Special UK quality

Is it just me or do others find this kind of thing annoying? I thought it might be a good idea to get a PCF8574T I2C I/O expander as a little add-on to the home control system, so you could plug it into, say GPIO4 and GPIO5, losing 2 outputs – and gain 8 – net gain 6 outputs…

So off I went to Ebay – and clearly being a Brit I’d like to support British companies.  I wonder what extra value the UK version would bring? I’m currently in Spain as many of you know.. aside from customs (which would not apply at this price) and tracking…

Chinese version (and not untypical pricing).

Chinese PCF8574T

UK version (not seeing any extra gold-plating).


Not surprisingly I’ll be ordering from China – keep eyes peeled in a couple of weeks or so for blog updates on this.