Category Archives: General

NEO2 NAS Part Two

NAS BoxI’ve separated this off as it has gained a life of it’s own. When I originally opened up the NAS box from FriendlyArm and plugged in my NEO2 (same company) I’d just planned on trying out the free NAS software. Little did I know how far this would develop…

it occurred to me as I was wondering why on earth I needed a NAS without RAID in the first place, that this is a nice box with a nice power supply for a NEO2 and disk (I have the version of the box for the original NEO so a little filing of the ETHERNET opening was necessary – no big deal)…

The Disk:

So I put my SD with FriendlyArm’s Ubuntu  into the NEO2 – along with my script for Node-Red etc etc, all set up and plugged in.  As you might expect it started as normal so I went in to see if SDA (the hard disk) appeared.

Sure enough – along with SDA1 – so off I went to the web and found out how to use FDISK  - deleted the partition, created a new one,  made a directory in my PI directory and MOUNTed the disk. More on that later.

Well, I have to say that worked swimmingly well, so next using WinSCP I tried copying a 3.8GB file across. It copied flawlessly at 35MB/second!

So a couple of things – I’ve just finished my solar installation and I just happen to have 12v available from it – with lots of power to spare – I figured it made sense to plug this box in – ok, the network can still go down but there is NO chance of the 12v failing.

Of course you can’t access the GPIO pins via their connectors but the back is available so with a soldering iron I figured if need be I should be able to access a few of them given that there are schematics on the FriendlyArm site for just about everything  so it would be no problem to out which ones are still free.

So I ended up with a disk (available via Samba once I remember how) and a nice sturdy box for my NEO2 and disk. As the NEO2 also has an audio in and out – it would be no problem with a drill to add a 3.5mm jack on the front panel. If I could think of a decent small socket for the job I’d bring the UARTs out too – remember – there are four of them – that back panel is sitting doing nothing…

NEO2The next step was to allow the NEO2 to use the hard disk properly – i.e. instead of the SD.  I’d already done a mount and tested a file transfer and achieved 38MB/s on a large (3GB) file – so I was happy to try.

The instructions are somewhat different to a Raspberry Pi due to this little machine not having a cmdline.txt file.

If you've used my script – absolutely make sure LOG2RAM is NOT running before doing this... best install without Log2ram. If Apache loses it's log file in the setup, it won't run - and that happened to me (mind you that is easily fixed).

Alternatively, if you already have it installed,  disable log2ram (which is in my script for all my machines now but isn’t needed when using  a hard drive).

sudo systemctl disable log2ram

then  go to /etc/cron.hourly and delete the log2ram file – and reboot.

So the basic idea is to make a folder and point the hard disk to it – mount it – then copy almost everything to the hard disk… then change the settings in the boot folder to use the hard disk.

In this case – no changes to fstab – but one simple change to a file in the boot directory (boot.cmd) and having made the change you then you have to run a command to create a new boot.scr  - this is not what you’d see for a Raspberry Pi.

This is what I did:

Assuming a hard disk on /dev/sda and assuming for now being logged in as ROOT to ensure there are no issues with privilages…

I wiped any partitions in the drive (d, n, p, defaults then w for write) and created a new file system

fdisk /dev/sda
mkfs.ext4 /dev/sda1

I then rebooted. Some say you don’t need to – I found I did. I then made a directory called mnt (for want of something better), mounted the disk over that folder (which now means that folder is actually on the hard drive and not the SD – simple when you get used to it) and copied everything across  (excluding /boot and the /mnt directory itself)

mount /dev/sda1 /mnt
sudo rsync –ax   / /mnt

At first this all seems odd but becomes second nature very quickly. You could add a progress option in there but the whole thing takes only a minute or two and I didn’t want to slow things down. The -a option means "archive", which should preserve file permissions, modification times, etc., and the x option means "don't cross filesystem boundaries", so it'll skip /boot and /mnt

I then altered /boot/boot.cmd 2nd last line.. changing the reference to the SD to the new hard drive – see bold.

setenv bootargs console=tty1,115200 earlyprintk root=/dev/sda1 rootfstype=ext4 rw rootwait${} panic=10 ${extra}

To make that work I had to run this line (again as root)…

mkimage -C none -A arm -T script -d boot.cmd boot.scr

So above, I’ve changed the boot setup firstly to get rid of serial debugging as the serial output on that NAS box is serial port 0 and I didn’t want debug on there – and secondly to change the normal pointed to the internal SD – to the new drive partition SDA1.

I rebooted…. and sure enough I was on the new file system – I knew that as previously I’d put a dummy file in my /home/pi directory after copying everything – and that file had now disappeared.

The terminal sign on message,on reboot, showed I was using 60% of RAM and 2% of the 111G hard drive.

A quick test of a file transfer from the PC to the NEO2 showed around 37MB/s transfer.

All that remained now was to use Samba to share a folder. I am assuming here that Samba is installed – it is on my script. In my PI user folder I made a folder called “share”. From here you can do this stuff as user Pi or ROOT but Pi need SUDO permissions for accessing some places.

I created a user PI for Samba…

sudo smbpasswd -a pi

I then went into /etc/samba/smb .conf to add information (thanks Antonio) to share a folder called /home/pi/share

comment= Sharing dir
only guest=no
create mask=0777
directory mask=0777
force user = pi
valid user = pi

I then told Samba to update (reboot would no doubt have done the same thing)

sudo service smbd restart

And that was it for the disk… on my PC at \\neo\share I was asked for username and password – I put in pi and my new password – this then became available on the network and I used Windows to MAP the drive – now drive Z: is that folder. A quick attempt to copy a 3GB file over proved successful.

The Real Time Clock:

So the NEO2 has I2c but like most non-Pi machines I’ve never been able to make use of that until now. The NAS box has a connector for this – nothing special but they’ve put the necessary pull-up resistors on so we don’t need to.

In a previous article I pointed out that FriendlyArm recently released a WiringNP at my request (and no doubt the request of others) and that is part of the operating system assuming you have their latest ROM. Well… I could not resist it.   I tried this:

sudo gpio i2cd

That’s the I2c scanner and hey – it worked – it spotted the real time clock on the NAS board. Could this possibly work? Well yes but the clock was wrong and the timezone was wrong so…

sudo timedatectl set-timezone Europe/Madrid
sudo hwclock –w
sudo hwclock –r

Sorted. Now I was getting somewhere – got serial, got access to some ports by the GPIO utility, got real time clock, I2c…

More I2c – the SSD1306 Display

It occurred to me that a little status display would go down well on that back panel.

I spent a lot of time trying to get other people's libraries to work with one of those SD1306 128*64 OLED modules with only limited success – of course the connector wiring was different. On the FA board it was gnd, 5v, SDA, SDL – which strangely is what Itead use – and the 128*64 OLED clock had clock and data the other way around. No matter as I had to solder to the OLED anyway. I plugged the board int (first checking the OLED could handle 5v) and sure enough – a quick scan revealed that address 3C was now used and I happen to know that’s the right address for the OLED (see my earlier blog on power supplies where I put one of these to good use.

I found one library that worked and talked about it in the previous version of this blog – yes it worked but it also killed the board by introducing a “segmentation error” which I simply could not get rid of.  I wasted a lot of time on the wrong libraries and eventually got in touch with FriendlyArm to see if they had anything - well, of course, they did! I should have asked in the first place.

They pointed me to something called Bakebit and in particular, code for the SEEED displays - which just happen to be the same as the generic 128*64 displays I use. I ended up on this page where I could do the install of the Bakebit code and examples.

Having done the install I very quickly realised that the Python PSUTIL library was version 0.5.0  - i.e. ancient. Using PIP I uninstalled that and put in the latest and though I was not not happy with the wide font they used. Again FrienlyArm helped out by pointing out that one of their examples uses TTF fonts – YES. Of course the example assumed you were running the Python code in the same directory that their examples and fonts were in – that took some figuring out – and there was a missing include.

sudo pip install Pillow

That sorted THAT out (don’t try missing the sudo off unless you are user ROOT – it appears to work then the board dies).

Here is my  displaying some stats.   As I'm planning to use a similar display with only two lines, I've since split the code to show 2 lines at a time, cycling continuously - but the info is the same. I managed to put a fully qualified link in the /etc/rc.conf folder – to have this run from power up.


<code>#!/usr/bin/env python
# BakeBit example for the basic functions of BakeBit 128x64 OLED
# The BakeBit connects the NanoPi NEO and BakeBit sensors.
# You can learn more about BakeBit here:
# Have a question about this example?  Ask on the forums here:
## License

The MIT License (MIT)

BakeBit: an open source platform for connecting BakeBit Sensors to the NanoPi NEO.
Copyright (C) 2016 FriendlyARM

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.


import time
import bakebit
import os
import psutil
from math import log
import multiprocessing
import platform
import socket
import bakebit_128_64_oled as oled
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import socket
import fcntl
import struct
import sys
from datetime import datetime

global width
global height

global image
image ='1', (width, height))
global draw
draw = ImageDraw.Draw(image)
global font10 
font10 = ImageFont.truetype('/home/pi/BakeBit/Software/Python/DejaVuSansMono.ttf', 10);

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])

oled.init()                  #initialze SEEED OLED display
oled.clearDisplay()          #clear the screen and set start position to top left corner
oled.setNormalDisplay()      #Set display to normal mode (i.e non-inverse mode)</code>

<code>#oled.setPageMode()           #Set addressing mode to Page Mode

byteunits = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
def filesizeformat(value):
    exponent = int(log(value, 1024))
    return "%.1f %s" % (float(value) / pow(1024, exponent), byteunits[exponent])

def bytes2human(n):
    >>> bytes2human(10000)
    >>> bytes2human(100001221)
    symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
    prefix = {}
    for i, s in enumerate(symbols):
        prefix[s] = 1 << (i + 1) * 10
    for s in reversed(symbols):
        if n >= prefix[s]:
            value = int(float(n) / prefix[s])
            return '%s%s' % (value, s)
    return "%sB" % n
def cpu_usage():
    # load average, uptime
    av1, av2, av3 = os.getloadavg()
    tempC = ((int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1000))
    return "LOAD: %.1f %.1f %.1f" \
        % (av1, av2, av3)

def cpu_temperature():
    # load average, uptime
    av1, av2, av3 = os.getloadavg()
    tempC = ((int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1000))
    return "CPU TEMP: %sc" \
        % (str(tempC))

def mem_usage():
    usage = psutil.virtual_memory()
    return "MEM FREE: %s/%s" \
        % (bytes2human(usage.available), bytes2human(
def disk_usage(dir):
    usage = psutil.disk_usage(dir)
    return "DISK FREE: %s/%s" \
        % (bytes2human(, bytes2human(
def network(iface):
    stat = psutil.net_io_counters(pernic=True)[iface]
    return "NET: %s: Tx%s, Rx%s" % \
           (iface, bytes2human(stat.bytes_sent), bytes2human(stat.bytes_recv))
def lan_ip():
    f = os.popen('ifconfig eth0 | grep "inet\ addr" | cut -c 21-33')
    ip = str(
    # strip out trailing chars for cleaner output
    return "IP: %s" % ip.rstrip('\r\n').rstrip(' ')
def stats():
    global looper
    draw.rectangle((0,0,width,height), outline=0, fill=0)
    if looper==0:
        draw.text((0, 0), 'WELCOME TO NEO2', font=font10, fill=255)
        draw.text((0, 13), 'Starting up...', font=font10, fill=255)
    elif looper==1:
        draw.text((0, 0), cpu_usage(),  font=font10, fill=255)
        draw.text((0, 13), cpu_temperature(),  font=font10, fill=255)
    elif looper==2:
        draw.text((0, 0), mem_usage(),  font=font10, fill=255)
        draw.text((0, 13), disk_usage('/'),  font=font10, fill=255)
    elif looper==3:
        draw.text((0, 0),"%s %s" % (platform.system(),platform.release()), font=font10, fill=255)
        draw.text((0, 13), lan_ip(),  font=font10, fill=255)
        uptime = - datetime.fromtimestamp(psutil.boot_time())
        draw.text((0, 0),str('%a %b %d %H:%M:%S')), font=font10, fill=255)
        draw.text((0, 13),"UPTIME: %s" % str(uptime).split('.')[0], font=font10, fill=255)
def main():
    global looper
    looper = 0
    while True:
        if looper==0:
if __name__ == "__main__":
    except KeyboardInterrupt:



I’ve had a quick check of the schematic – I may be missing something but it appears the following GPIO remains unused… GPIO-A0, C0,C1,C2,G6,G7,G8,G9, A1 and C3 – amongst those, you have UART 1 tx and Rx – and the SPI wires… might take some subtle soldering of the NEO2 but it is do-able to get these out.

Meanwhile Antonio wanted me to test the new disk I'd fitted:

sudo apt-get install smartmontools --no-install-recommends
sudo smartctl -H /dev/sda -d sat | grep overall-health | tr -d " " | cut -d: -f2

The disk said "PASSED" - and so off I went to order some connectors.


This blog entry could just keep going on forever and I could turn it into a book... I decided to have a go at making a second unit.  Now, I could have started from scratch but there is a lot of work gone into this.  So - I made a new SD - just a basic operating system.  I put it into the second unit with a new drive and followed the steps I've already done right up to putting all the files onto the hard disk but I stopped before that.

It turns out you can use rsync remotely... so having mounted the hard drive and made a temporary folder - I repeated the rsync operation on the FIRST machine - but as ROOT to ensure I had permissions - but pointing as a destination the SECOND machine and that particular folder..... the destination (again addressing a ROOT connection at the other end) being root@

And LO AND BEHOLD after asking for the password of that user, not only did it start the copy but it finished it within minutes.

I changed the settings in the boot file just as before but on the second machine this time - and rebooted. Stunningly, everything worked. I changed the domain name of course and rebooted again but I now have two identical machines both of which are now on solar.

Two units

I did have some difficulty in installing BakeBit but in the process, FriendlyArm wrote to say they had the LCD working – and they put a ROM up with the updated Ubuntu AND the Bakebit software already in there.   I’m waiting for a response to confirm that this ROM will stay online and I’ll update the blog accordingly. Essentially – install the Rom, install my script (for Node-Red etc) – add in the bits to run off a hard drive and you’re done. More on that later.

Update 27/05/2017

I’m waiting for confirmation from FriendlyArm but they have an image with the OLED code and example already in there. I’m hoping they’ll leave it available. It needs PSUTIL uninstalling and re-installing (2 lines) as the version they use is old – but other than that it works a treat. I DID notice that in the install is python-SMBUS and in the process of finding out what that was, I stumbled on some Adafruit code to run one of those PCA9685-based 16-channel PWM boards – you may recall some time ago I wrote about these and made my ESP8266 code compatible with them. Well, I could not resist it so I wired up one of the cheap Chinese PCA9685 boards to a connector and plugged it in.

After installing the Python library (one liner) I tried the example which outputs 2 levels of PWM for a servo. As I didn’t seem have a servo handy I tried a LED – and it worked a treat.

PWM board

Then I remembered that amongst some SEEED stuff, I did indeed have a servo.

ServoNow, if you’re not familiar with these, I guess the simplest way to explain at least this type of servo is that it is the kind of thing you see on model aircraft.

You feed it power and ground – in this case 5v… and a pulse signal – the width of the signal determines the position, accurately. I took the connector off, put on 3 new connectors and fastened it to the PWM board. Immediately it started moving from one extreme position to the other – perfectly.  I can’t believe how easy this was – and that little board will handle 16 of them (not power-wise but signal-wise.

NOW I was on a roll – I rummaged around and found a TG9e servo – yellow control wire instead of white but otherwise it looked the same – would I be so lucky – yes, worked PERFECTLY. Pity they’re not a lot larger, I could put them in charge of a solar panel!

All good fun and no doubt much more to come. I was beginning to think the only way to easily access control boards like this was to get a “genuine” Pi or ESP8266/Arduino – but it seems that this view is now history. I can imagine there are lots more drivers where these came from.

The Adafruit code I mentioned above includes drivers for the BMP085 (sadly not the BME085), TCS34725 colour sensor, VCNL4000 proximity detector, MCP4725 DAC,  DHT and a whole lot of other chips. Worth looking at. I’m sending off for a couple of 4-channel ADCs so I can monitor various battery voltages while the NEO2 is idling.

Port Extension

One of the things I learned early on when dealing with the NEO2 is that it does not like LOADS on it’s outputs. When I very first mastered the IO I had a bright LED on one of the outputs – and for reasons I put down to code, sometimes the board would not reset properly – or rather it would not come out of reset properly. I quickly discovered  that if I removed the LED – all was well.

So i2c comes in as something of a relief when you consider the magically cheap PCF8754T port extenders at under £1 each.

I hooked one of these with the 3 switches all OFF to the board and did the I2cd check – port 0x20. That was a good start. The next thing – and the limit of my achievement so far was to read these. I’ve already done this with the ESP and they are REALLY easy to use – fire the address off – issue a read and BOB’s your uncle. Similarly the write.

Of course I had NO idea how to use the I2c and went looking at the BMP example in the Adafruit folder.

This is what I have – now I should say from the start… firstly I have no idea how to use the libraries and I have even less idea how to use Python. But this works – I can read the port.

So the first thing to remember is that these devices do not swap modes – they are effectively open-collector – that is to say you if you set the outputs to 1 – they can be used as inputs and shorted LOW… they float HIGH.  if you use them as outputs and want to put any load on them – you need to take your load (a LED for example) from +v to the output – which will pull it LOW.

This is just as well as I could not find an 8 bit WRITE instruction – but there’s an 8 bit READ instruction with a parameter for writing to the control register… so RATHER handily you can just read, passing parameter 255. The pins will read 255 back unless you’ve shorted one or more to GROUND.

As outputs – imagine you have 8 (led+resistor) with the negative going to the pins and the common positives going to VCC, read(255) will output nothing – read (254) will turn the first LED on etc.  Works a treat. The only thing I don’t like about the cheap extender boards – come on guys – some more ground and VCC connections would have been nice!!!

From sheer guesswork to this…

from Adafruit_I2C import Adafruit_I2C

i2c = Adafruit_I2C(0x20)
port = i2c.readU8(254)
print port

It doesn’t get any easier than this - clearly here you are importing the Adafruit library.  I had to put the library in the same folder as my code as I have no idea how to make a shortcut to it – which is apparently how it is done elsewhere.

i2c is what I would call an object (could be any name)– no idea what you call it in Python… and so you call the I2c setup function with an address – i.e. the address of the board and you get your object(i2c)  back. i2c.readU8 is a function you pass a value to – and it returns an 8-bit number. Simple as that. Make the number you pass 255 for all inputs, anything you want as a LOW output you simply invert that bit….. 254, 253 etc.

port expander

I’m sure someone will tell me there is a write function and that’s fine as I’m still new to this (I’m a whizz at C). And, erm, well, it works – so there’s your port extender – you could have 8 of them with different addresses – that’s 64 bits and if you mess something up in hardware, there’s a chance your NEO2 will survive!! I will modify this as I get more clued up!


Big Nextion

ITEAD DisplayQuite a while ago now I did a project based on the little Nextion displays, resistive touch-LCD displays which run on serial commands and come with an editor to make simply touch displays for even the simplest of micros.

Well, that project has proven to capture a lot of interest and I have one of those displays running 24-7 in a holiday rental property – and it has been doing that for a couple of years now.  I’ve not done anything new with the displays for a while but this morning, a new generation display turned up for me to take a look at.

The NX8048K070_011C is a new 7” Enhanced HMI Capacitive Touch Display complete with case (also available without the case) from Itead – the company who also produce the Sonoff units we’ve discussed many times in this blog.

The unit runs on 5v at 550ma and is to use the company’s own words, a powerful 7.0'' HMI TFT capacitive multi-touch display with a beautiful enclosure, with 32MB Flash data storage space, 1024 byte EEPROM, 8192 byte RAM, and GPIO supported.

The “GPIO supported” means there’s an 8-bit port connector. There is also an SD connector for storing info and a small 4-way connector for power, serial in and serial out.

So first things first – the advert headlines with $88 but in fact that is for the resistive version – for the capacitive version, add $20 for a total of $108 + shipping. The shipping via normal e-parcel was $11.40  (I’m only using dollars here because the ad is in dollars). DHL shipping is a horrifying $57 – but then I would not use DHL even if they threatened to cut off my toes. I STILL think the best thing ITEAD have done is the original Sonoff – and I say that because of the price. Right now they are going at $4.85, which for a boxed unit controlling the mains via WIFI is just stunning. The later units are in better boxes and are more powerful but by the time you reach $20 each the price to control a lamp is starting to get a little less enticing.

Anyway, I digress. So the Nextion displays work in a strange way – you don’t write directly to them like a typical Raspberry Pi display – but then you don’t have that overhead either. Once set up – which you do with the free “Nextion Editor” – the display merely needs serial text commands to do updates hence the simple 4-wire interface.

I’d rather hoped the rather nice display case would have some kind of feet – but instead it comes complete with 4 wingnuts which come complete with elongated bolts for mounting into existing installations.

One of the most annoying features of the original Nextions was the SD – you could not actually store data in it – that has now been addressed along with supplying real time clock, GPIO (well, on an ESP8266 you lose 2 wires to run the display so it can be useful to get that and more back) and of course the smoother capacitive touch display.

Display and caseThe actual display itself is only 800*480 which means you can see the dots but from any distance at all this is fine. The design of the case means it would easily fit into a cavity in a control panel and the whole thing is quite sturdy. I do wonder however why they made such a large case compared to the actual size of the LCD itself – as you can see in the photo.

As if to demonstrate the new features, when I powered up the Nextion display – it showed a swipe as you might find on modern smartphones – once I’d swiped, I was asked for a password (1111) – I put that in and the display proceeded to demonstrate the time and date. Might have made for a more posh demo if it hadn’t been set to 2044 – but never mind.

So, simple operation, nice easy, light touch compared to the older (but cheaper) resistive displays)  but at the end of the day, ease of use or otherwise comes down to the Nextion Editor – because they have done their own thing you really need to be able to use the editor to set the display up.

I downloaded the latest Nextion editor (free) on my Windows PC. After all this time it is still 0.47 – you might think considering the amount of time the Nextions have been out they would at least be to 1.0 – but then perhaps one should not judge a book by it’s cover.

Nextion Editor

It did occur to me that just MAYBE you could fit a little ESP8266 or NANO into that case – but on opening – no – not unless you cut off any connectors.   Oh, and I found out why the clock was wrong – there is indeed a battery connector on the board – but no battery was fitted – well, that accounts for that!

At this point, rather than going through all the fine detail of the , here’s a video.


Also take a look at my Nextion WIFI Touch Display -  the size is different but the general idea is the same. I’d like to hear from anyone who’s been using these displays for any length of time to hear what they think of the current editor – and what do you think of the price (please don’t write in to say you’ve used an old tablet  - already had that discussion). Is this good – or is there something better out there?


Amazon Polly Speech

Regular readers will know that I am an Ivona fan. In Node-Red I use the free Ivona service to provide high quality speech for my Raspberry Pi in Node-Red at the heart of my home control setup. Well, Ivona is now defunct. Amazon Polly is a replacement.

I’ll clarify that, Ivona is SOON to become defunct and you can’t create new accounts. The Amazon Polly system, is for most purposes a replacement for Ivona.

So – if you go to the Ivona site – you will see the reference to Amazon on the front page. The short, sharp answer is: Polly works, it is effectively free and it is as good as or better than Ivona. Read on.

So the Amazon system “Polly” works via an account. I have an Amazon Developer account and when I tried to add Polly – it said I didn’t have the right permissions – so – I added user Pete to my account and made him part of the Polly group – and that didn’t work either – then I noted something about payment and realised I’d not put any payment details in – I did that – and all of a sudden the thing came to life and I got the only things I needed – my user ID and secret password.

DON’T PANIC about payment – there is a free tier of up to (wait for it) 5 million characters per month for the first 12 months then $4 per million characters – by which point you probably won’t need any – read on) – for my purposes there is not a hope in hell I’ll ever reach the free limit. In addition  - the way I use it is the way they seem to want you to  – download a phrase as a file (MP3) and save it with a meaningful file name.  Next time you want that phrase – check to see if the file already exists – if so, play it, if not, get a new file from Amazon. In a typical use case that I might have, once the messages are used once there is very little chance of me needing to download anything and hence NO chance of incurring charges at least in the first year.

There are no doubt more elegant ways to do this than calling a command line from Node-Red and sometime someone will write a node to do it – might even be me – but right now this works perfectly and as far as I know it is the only published solution for Node-Red and Polly. If I’m wrong please do tell.

I’m assuming you have your credentials – don’t worry about location – they don’t have a location for England but all it means is to tell the code which server to use. Ireland works for me and it is working from here in Spain.

You need to grab the command line code – I used this on a Pi2.

sudo pip install awscli

Once that was in I used:

aws configure

to set up the user ID, secret key and location which I’d already set up on the Amazon site.

That done I tried this:

aws polly synthesize-speech --output-format mp3 --voice-id Amy --text "Hello my name is peter." peter.mp3

The resulting file was sitting in the /home/pi directory – this used the voice Amy (British female) to store a phrase into peter.mp3.  Good for testing but as you’ll see the final solution is much better.

The rest is about queuing messages, storing them with meaningful names, playing them back and making sure you don’t re-record a phrase you have already recorded. If you don’t like Amy – use another voice. If you want different voices for different phrases then you could incorporate the name into the filename (I’ll leave that to the reader).  If you want to add sound effects – just put .MP3 files in the relevant folder with your sound effects and call them by name.

Polly Speech

Looking at the above diagram, a test inject passes  what you want Polly to say in the payload.

The first function looks to see if the payload has something in it and if so it pushes that onto a stack. The code then looks to see if speech is busy – if not and if there is something on the stack, it checks – if it is an mp3 file it sends the file to the MP3 player. If it is not an mp3, it looks to see if you’ve already created an mp3 for that speech, if so it plays that file, otherwise it passes the message onto Amazon to create the file – which is then played back.

It would have been nice to process new speech while playing something else back but that would get more complicated, involving more flags. As it stands this is easy to understand. You can fire in more speech or .MP3 files while one is playing and they will simply be queued.

You clearly need your Amazon account setup and Node-Red for this – you also need MPG123 player. Both Node-Red and MPG123 are in my standard script.

Here is the code I used in each of those functions…. the MPG123 exec node simply has mpg123 for the command and the append payload ticked. The AWS exec node has  aws for the command and the append payload ticked.

Here is the code for the three yellow function nodes:

if (typeof context.arr == "undefined" || !(context.arr instanceof Array)) context.arr = [];
if (typeof global.get("speech_busy") == "undefined") global.set("speech_busy", 0);

if (msg.payload !== "") context.arr.push(msg.payload);
if ((global.get("speech_busy") === 0) && (context.arr.length)) {
    msg.payload = context.arr.shift();
    global.set("speech_busy", 1);
    if (msg.payload.indexOf(".mp3") == -1) {
        var fs = global.get("fs");
        var mess = msg.payload;
        var messfile = mess.toLowerCase();
        messfile = messfile.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
        messfile = messfile.replace(/ /g, "_");
        if (fs.existsSync("/usr/audio/" + messfile + ".mp3")) {
            msg.payload = "/usr/audio/" + messfile + ".mp3";
            return [null, msg];
        else {
            var voice = "Amy";
            msg.payload = 'polly synthesize-speech --output-format mp3 --voice-id ' + voice + ' --text "' + mess + '" /usr/audio/' + messfile + '.mp3';
            global.set("speech", messfile);
            return [msg, null];
    return [null, msg]; // mp3 or synth        

// now play function node
msg.payload="/usr/audio/" + global.get("speech") + ".mp3";
return msg;

// clr busy function node;
msg.payload=""; return msg;

That was version 1. But ultimately I wanted new speech to be processed by Amazon WHILE a previously recorded item was playing (assuming a previously recorded item was playing and the next item had to be created).

Several hours later I came up with this – it appears to work!

Polly 2

and here is the latest code – probably not QUITE as straightforward to read – but when you run it – indicators on the EXEC functions (brown) show clearly that the software is able to play a recorded message while fetching a new one. Could do with some extreme testing.


if (typeof context.arr == "undefined" || !(context.arr instanceof Array)) context.arr = [];
if (typeof global.get("speech_busy") == "undefined") global.set("speech_busy", 0);
if (typeof global.get("create_speech_busy") == "undefined") global.set("create_speech_busy", 0);

if (msg.payload !== "") context.arr.push(msg.payload);
if (context.arr.length) {
    msg.payload = context.arr.shift();
    if (msg.payload.indexOf(".mp3") == -1) {
        var fs = global.get("fs");
        var mess = msg.payload;
        var messfile = mess.toLowerCase();
        messfile = messfile.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
        messfile = messfile.replace(/ /g, "_");
        messfile = "/usr/audio/" + messfile + ".mp3";

        if (fs.existsSync(messfile)) {
            if (global.get("speech_busy")==1) { context.arr.unshift(msg.payload);  return [null, null]; }
            else { global.set("speech_busy", 1); msg.payload = messfile; return [null, msg]; }
        else {
            if (global.get("create_speech_busy")) { context.arr.unshift(msg.payload);  return [null, null]; } else
            var voice = "Amy";
            msg.payload = 'polly synthesize-speech --output-format mp3 --voice-id ' + voice + ' --text "' + mess + '" ' + messfile;
            return [msg, null];
    if (global.get("speech_busy")==1) context.arr.unshift(msg.payload); 
    else {  global.set("speech_busy", 1); return [null, msg]; } // mp3 or synth        

and here, the two small function nodes

// clear creating
return msg;

// clear playing
msg.payload=""; return msg;


Espruino For You Sir

As a once-dedicated C programmer (I learned with the K&R book) I originally dismissed Javascript as an interpreted toy (great for websites of course), that is until I started playing with Node-Red.

At that point, after much struggle, I started to get reasonably good with it and once I got used to the string handling, C by comparison started to feel annoyingly awkward when dealing with strings and objects, despite it’s vastly superior speed.

Some time ago I looked at Espruino in a bored moment – saw that it was very much under-developed – didn’t even handle WIFI at the time – a bit pointless on an ESP8266 -  and dismissed it.

Fast forward to this week.  I had set in place some copying of files from here to Spain which, according to FTP was going to take an hour. I could not tell you why but suddenly I got the urge to go see what was happening with Espruino.

So – I believe the model here is that they developed JavaScript for a range of devices – including the ESP8266 and their funding comes from selling the boards and from contributions. I can’t help with boards right now as I have some of my own but I could not resist grabbing the code and sticking it into one of my ESP12 boards to see how they’re coming along. 

Regular readers will know that I like to revisit projects, most of the time great ideas unless they really take off, end up in the bin but just sometimes they go on to be something better.

So off I went to the site. As I’m using their software for free – here’s a push for them – take a look here  – maybe it is worth looking at one of their boards?  Anyway, I grabbed their general ESP code – and using the horrible ESPTOOL but the much prettier ESP8266FLASHER.EXE  I blew the modules into my 4MB ESP-12-E module.  I grabbed the code and followed instructions on this page.

Programming Espruino

Node the bulk of the code at 0x1000 – don’t make the mistake I made of making that 0x10000 – it won’t work and will cause hours of fun. All 4 files are in their download along with instructions.

I grabbed their web IDE (Espruino IDE) to test the code at 115K baud…. my own serial terminal does as well but theirs is prettier. For the life of my I could not get it to start up properly in their IDE – but in my terminal, on hitting reset on the ESP8266 I got this.

_____                 _

|   __|___ ___ ___ _ _|_|___ ___

|   __|_ -| . |  _| | | |   | . |

|_____|___|  _|_| |___|_|_|_|___|


1v91 Copyright 2016 G.Williams

Espruino is Open Source. Our work is supported

only by sales of official boards and donations:

Flash map 4MB:512/512, manuf 0xe0 chip 0x4016


Now I have to say two things – for a complete beginner I found the documentation totally confusing – making reference to LED1 which doesn’t exist and other things – but it turns out you have to read again more carefully. Secondly when I went onto their forums totally confused – two guys came in immediately and helped me.

Once I had the board responding which ultimately did not take a lot of effort – I went back to their IDE and the board was then responsive – I still don’t know why this is – but just so you know if it happens to you – you can talk to the thing with a serial terminal.

Here’s the first issue I encountered…


Espruino Web IDE

Every time I hit enter – the interpreter would come back with undefined. I could not fathom this out until someone pointed out that the interpreter always returns either a value – or if no value is defined, undefined…. kind of makes sense though not what you’d expect from, say, a BASIC interpreter.  Once I’d gotten to grips with this I got more ambitious.


The answer to that was “=3” – seems fair enough.

If I reset the board however I could get nothing out of their IDE – I went back to my simple serial terminal – no problem.

My next problem was following examples – one example referred to flashing a light called LED1 – turns out this doesn’t exist in their ESP8266 implementation but the ports can be expressed as numbers where 0 is GPIO0.

var  on = false;
setInterval(function() {
  on = !on;
}, 200);

I entered the above – perfectly valid JavaScript – and blow me – it WORKED!

Of course – on resetting this would be lost unless you typed “save()” or “reset()” to clear everything out. Running that timer command with different values WITHOUT hitting reset would result in multiple timers.

So – reset – then run that code then save… and the flashing light survives power off!

Espruino does not sadly handle hardware PWM – a shame as Espressif HAVE implemented this at quite reasonable resolution (14 bits) but then their implementation is not perfect – turn it off and that timer keeps on ticking anyway – making a mess of other high speed events like SPI. So maybe that’s why they implemented software PWM – which, well, works!

Some things you should know – they’ve not implemented use of GPIO16 and space is limited at least at first glance – 12K for program storage (including OTA they only seem to use 1 Meg so that does leave nearly 3MB available on an ESP12)… you’ll find the limitations here – but to be fair many of those are ESP8266 limitations – no DAC for example – well of course there isn’t – the ESP8266 doesn’t HAVE a DAC. So the list of limitations is not as bad as it seems by any means. I’ve no idea why they did not implement GPIO16 as a simple output – I use it all the time.

What they DO have are libraries for a good number of peripherals so you might well want to take a look.

Speed? Well, they use the ESP8266 at 160Mhz by default (and that’s fine – I don’t know why we normally stick with 80Mhz given that the extra speed doesn’t take much more power) and claim that for general I/O the unit should be fast enough for general purpose use.

I used example code to connect to my WIFI – no problem – but when I tried to MQTT – I came unstuck  -their source library for MQTT simply would not load successfully.

I read that you had to put the REQUIRE into the right hand side of their IDE to load the module -  I did that and it worked but I really would like to understand how to load the module WITHOUT their IDE – as mentioned above I’m not too happy about it’s behaviour from power up.

So – armed with the MQTT library it was as simple as…

  host: "",
  username: "admin",
  password: "mypass"


mqtt.on('publish', function (pub) {
    console.log("topic: "+pub.topic);
    console.log("message: "+pub.message);

I fired many messages at it from an MQTT publisher and sure enough  - they came in.  If one can get both WIFI and MQTT running on this interpreter and if it stays up reliably then maybe here’s yet another way to write code for the ESP8266.

To test, I disconnected the WIFI access point – and reconnected – a message came up to say MQTT was disconnected.. but on re-applying power to the WIFI access point… nothing.   When I ran the MQTT code again it connected (indicating that the WIFI connection automatically reconnected itself). What is needed now is a check for broken connection and indefinite MQTT reconnect and resubscribe attempts until it is back in running order.  If anyone has done this already – please do let us know.

Lots of modules…

I can see this 12k storage for code being a REAL bottleneck – I do hope that gets sorted…


A Question of Lifespan

I’d like to start off a conversation about SD Lifespan. How can we make our SBC projects run for longer? In comments I've seen elsewhere, people seem to think it is ok that a Pi may well fail within a year due to SD - I don't think that is even REMOTELY acceptable unless you're making a novelty games machine.  People make a big deal about the reliability of Linux - not a great deal of use if the entire file system will come to a halt in a year...

I've never suffered this problem - my first heating system issue has appeared after more than a year's continuous use (and that includes doing lots of experiments on the same system).  You may have seen comments in earlier blog entries about this – for the first time ever I recently suffered a dead SD on one of my Raspberry Pi projects – stone, cold dead – read only and NOTHING on the Pi or my PC could encourage the SD to write again.

It has been said that some cheap SDs are not as large as they seem and as soon as you exceed use beyond their ACTUAL size – the chips become read-only.  I’ve yet to test this out but TKaiser has suggested testing all new SDs and in a previous comment has recommended SanDisk Extreme Plus.

The test program H2TESTW is widely available for free. I’m testing my first 16GB disk now – looks like it will take 20 minutes but as no user interaction is needed… time well spent.

In here you will find questions and opinions. In the comments hopefully you will find some resolution – lots of bright people read this blog and I’m hoping they have solutions rather than opinions.

If you read on the web about the subject of eMMC and SD and USB memory – it is hard to tell what is hard science and what is opinion.

For example there are blogs suggesting that instead of relying on SD, use a USB memory stick. I have trouble with this as the technology is similar. Why should a USB stick last any longer than an SD.

You’ll see reference to eMMC – there can be no doubt that eMMC (usually an internal module or chip) is usually faster than SD – but does it LAST any longer – some say yes, some say no. To be sure it is less convenient to back up compared to an SD you can simply pull out and replicate!

Then there is the hard disk. I have a natural tendency to think that a spinning disk has to be less reliable than solid state memory but every experience I have says the opposite. I could not tell you the last time a hard disk went bad on me. Of course – they tend to be more expensive – and they are very much larger than SD.

The general idea is that you can READ SD as often as you want but there is a limit sometimes described as 10,000 write cycles, sometimes describes as 10 times that amount. I suspect the latter and that there is just a lot of old information out there.

Then there is WEAR LEVELLING wherein some SDs have a chip inside that helps prevent a single location being written to, too many times – knowledge on this seems to be akin to witchcraft. WHICH manufacturers use this in WHICH SDs and HOW effective is it? I’ve not found a single source of information on the subject that is up to date and verified.

Today I read about putting some directories into RAM.

In the /etc/fstab file you can add for example

tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0

Works a treat but for one tiny item – Apache would not start up!

Several people have mentioned RAMLOG – but from what I can see –that no longer works with Jessie (the problem of old material hanging around on the web. This looks modern – and is reasonably straightforward to install – takes just a couple of minutes. – I installed it – and it works at treat. The default action is to update the disk every hour  - but moving the file “log2ram” from /etc/cron.hourly to /etc/cron.daily to me makes more sense.

So many questions – so many potentially wrong answers. See comments about actual number of writes to SD – would you believe any given location (not the one you see but the REAL location) could be as low as 1000s rather than 10s of thousands  – I had no IDEA it was that low).

On the subject of power supplies, in the comments you’ll find code for testing the likes of the Raspberry Pi – as there are registers in the Pi which pick up voltage issues… I was horrified how easy a long USB lead would allow the the Pi to work – but continually to register issues.

In testing – I found comments from TKaiser useful – then when wondering about the CPU frequency I found THIS article – and the associated script useful..

So already we see a need to reduce writes, only use good, tested SDs, use good good supplies with short leads. Not new, not rocket science but I am seeing some good science behind the need for this and look forward to reading more of your educated comments.

Keep the comments coming!

A Little Test

In the process of this discussion, TKaiser supplied us with a little script to return some information about power from the likes of the Pi2 or Pi3. This was intended to be used as a command line tool – repeating until told otherwise. Well, I like REPORTS…

I took out the loop section so as to return a single line of information – and that can conveniently be run in an EXEC node in Node-Red

Node Red showing Pi variables


I changed the script to simplify output – if someone can tell me how to produce output without “’C” and “V” so we have just numbers coming out – would be nice… I called this (changing permissions – don’t forget) and ran that inside an EXEC node in Node-Red…

     Maxfreq=$(( $(awk '{printf ("%0.0f",$1/1000); }'  </sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) -15 ))
    Health=$(perl -e "printf \"%19b\n\", $(vcgencmd get_throttled | cut -f2 -d=)")
    Temp=$(vcgencmd measure_temp | cut -f2 -d= | tr -d C | tr -d \')
    RealClockspeed=$(vcgencmd measure_clock arm | awk -F"=" '{printf ("%0.0f",$2/1000000); }' )
    SysFSClockspeed=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
    CoreVoltage=$(vcgencmd measure_volts | cut -f2 -d= | sed 's/000//' | tr -d V)
    if [ ${RealClockspeed} -ge ${Maxfreq} ]; then
        echo -e "${Temp}$(printf "%5s" ${SysFSClockspeed}) $(printf "%019d" ${Health}) ${CoreVoltage}"
        echo -e "${Temp}$(printf "%5s" ${RealClockspeed}) $(printf "%019d" ${Health}) ${CoreVoltage}"

(If you see a question mark above - the word is sampling)

As you can see we have some space-delimited values! If you look at the bitfield, semi-permanent recordings of issues are on the left (most significant bits) while on-going issues are on the right. Extracting from TKaiser’s notes..

The bits on the right are:

0: under-voltage

1: arm frequency capped

2: currently throttled

And corresponding on the left:

16: under-voltage has occurred

17: arm frequency capped has occurred

18: throttling has occurred

It is easy enough to break this down..

Here is another version where I have split up the values


The first is the input – the second is the split version – the same except they are now in 4 different places

var reading=msg.payload.split(" ");
msg.payload=reading[0] + " " + reading[1] + " " + reading[2] + " " + reading[3];
return msg;

And from there you can do what you like with the data of course – one idea might be to read every minute and turn that string bitfield into an integer,  totalling up errors in the lower bits (you could just read bits of the string to achieve the same thing) … after a period send off a report email…

No need to report over-heating as the governor should take care of that – however – min-max summary in the email might be nice while testing.


Newcastle Maker Faire

Maker Faire Newcastle 2017What a great day. Newcastle has an annual Maker Faire and it is on this weekend – and what a faire it is.

I headed off first thing to get some parking and was pleased to find that Newcastle College had some cheap parking - £4 for the day. I arrived 45 minutes to early, thankfully the security guard was a chatty type who wanted to know what all the fuss was about so we filled in time while waiting for my friend Aidan to turn up.

We got talking about cars as that was his thing and so by the time Aidan turned up in his Tesla, the guy was itching to see it and up to his armpits in questions.

Self-balancing one wheel vehicleThe faire started at 10am and we arrived shortly thereafter – it was CHOCKER full of people.

I’m so pleased this has turned out to be a success over the years – there was a time when “makers” – were treated a little dismissively by the public but today everyone wants to come and see what they are up to.

The first thing we came across was a self-balancing one-wheel vehicle and we had a great time talking to the designer – this is not a production job or commercial in any way, he built it because he wanted to – and it works extremely well. Yes, the pad on the front is for “emergencies”.

Rather than design in a modern way, the panelling was very retro – something my friend Melanie-Jane would love to have seen.

As we walked around we were amazed by the variety of stuff people do – from machines that do knitting, to robot hands,to retro gaming machines. A friend of ours Tony was responsible for a mini-version of the PAC-MAN arcade machine, though it had a flat top and I did remind him that the miserable pub people had this changed to round quickly as people were putting their pints on top of the machine. Well, if you’re going to spend all night playing you need somewhere to put your beer!!

Aidan Ruff making a flying thingNext off we came across an interesting idea – a bunch of clear tubes maybe 12” diameter and 6ft or more high – with air blowing up them. The public was provided with cups. paper plates, glue and sticky tape and invited to design the gadget likely to Flying thingreach the top of the tube without falling to bits or coming back down. Aidan could not resist the challenge and so while I manned the phone he proceeded to build a very high-tech device – which actually went in – out the top and continued on for some time – no doubt setting a world record – but then – that’s what I’d expect.

If have to say, if you saw the contraption he built, there was no way this was going to fly – but it did! Flimsy as it was the device went into the tube and headed straight up at tremendous speed and cleared the top of the tube by a long way. I’ll bet the kids who were competing flying thing in actionwere hopping mad. Afraid you can’t beat a gadget man who is also an experienced, qualified pilot…

Big round of applause and we were off to get some coffee before the next challenge..

Next stop, tPDP 8here were LOTS of tables with things that people had made – LOTS of them – some trivial – a few flashing lights – but not this – a genuine mini-version of the old classic, the PDP-8 computer – all done with wood, loving care and a Raspberry Pi.   I’ve been planning to build an IMSAI for some time but this was just wonderful.

There can be no doubt that modern computers are fantastic – and the computers from mid-last century were toys in comparison – but the Open Source Robot Handsdifference is – you could SEE and understand what they were doing (well, a relatively small number could – most people don’t know how their TV remote works but they’re probably not reading this blog) – it’s almost worth having one of these just as a piece of furniture – in some ways it reminds me of the bank of flashing lights on “Voyage to the tmpD569bottom of the Sea” or “The Time Tunnel” and similar. But this is a real, working machine. If you can click the image and scale it up – you’ll see it was made with love.

Open source robot hands, open source 3D printers – what a combination. We met up with an old pal of ours Dave Alan – a fellow who I met at the start of the microcomputer revolution – he has speech running on a 6800 processor WAY before the big boys thought of doing it (funny enough I had the same on a PIC and have an award on the wall to prove it – then along came PC speed and that was the end of that).

We saw and had explained a new 3D Printer – no more than £350 inc. VAT which used a new recycled plastic which does not bend and warp Dinosaurlike older materials – and I have to say, some of the parts they built with this were almost production quality – a non-technical person would not know the difference between that and a milled plastic part – VERY impressive – and not even a special heated cover over the thing!!!

Want one (but then I want a router and a laser cutter and….)

tmp73BAmong other delights there was a genuine dinosaur wandering around with his (her?) handler. Very impressive. Oh and you see those drawers on the right – wow – I SO miss the old radio rallies and computer shows where people brought their old junk 0 but better, suppliers brought tons of surplus stuff and sold dead cheap.  And so it was that the bearded fellow on the right – SO missed this – he decided to resurrect the idea – he had many dozens of £1 trays (3 for £2) and the prices were REAL bargains – anyway I think he’s called ABX


And that was about it – we talked to loads of people including friend Tony at the Newcastle Maker group – I hope to get to go see them in the autumn when we come back to the UK.  A GREAT day out for all the family, good prices on food – which makes a change as sometimes these things are a rip…

If you you are in the area next year, same time I strongly recommend a visit but of course such events are on all the time, all over the western world really. If nothing else you can guarantee that if you put a bunch of techies together – they’ll be dying to tell you how they made their stuff – and that is what makes these events so special. Well done to everyone involved in organising this.


Android Phone as Resource

This  is the following up the previous Android Phone as Server article. Last update 22/03/2017.

Bust up K10000Servers: So having now tried various phones and tablets, it does look like the Linux Deploy App on a rooted Android phone makes for a good Debian installation in order to run software like Apache, SQLITE, MQTT and Node-Red – in some cases surpassing the capabilities of the likes of Raspberry Pi by some way. When I say it looks that way, it is to early to comment on reliability – though my little K10000 monster phone has now been sitting on the bench for several days running this stuff without a hitch.

Resource: The next step then is to add value to this – modern Android phones are awash with features, none of which are currently being used in this setup. With MQTT communication, it seems natural to take all of those sensors and outputs and use them, firing info back and forth in MQTT or similar between Debian (Node-Red for example) and the Android phone (or tablet).

Some time ago when messing with the infamous TASKER  on Android – which can access most phone/tablet features, I noted the Tasker/MQTT plug-in – which means that Tasker can communicate via MQTT. The only problem with this – is that the MQTT app has not been updated since 2015, recent reviews suggest that it packs in after a while and the author does not at first glance appear to be responsive. I’ve written to him and not yet had any answer. This makes me extremely reticent to go down this route. I’m wondering if there are other ways to use Tasker to do the same thing. Remember that for this to be useful, this has to be something that will start up automatically when the phone is on – and also something that will run in the background when the phone is on standby.

So recently, friend Antonio sent me a link to another option – Sensor Node – the link here is to the free version and I splashed out and bought the full one. This seems ideal, instant access to at least sensors (though not controls) via MQTT at a user-selectable rate. Well, it didn’t quite work out that way when I tested it – firstly some of the touted sensor readings for some inexplicable reason are not included in the options for MQTT output -  like battery power and percentage charge – which would be really very good for sensing if the power has been lost and doing something about it – (like backing up any RAM cache to disk).  I’ve written to the author and asked about this – but when I started testing this it got worse, the software would not store my MQTT readings properly and there is no facility that I can see to run this in the background or ensure that readings commence when the phone starts up.

Anyway it turned out that Sensor Node was CRAP – even the paid version-and it turns out that there is an updated MQTT Client add-in for Tasker so I gave THAT a go.

Door pressVerdict:  It is looking like TASKER and the MQTT Client plug-in are winners. It did not take long to have Tasker sending BATTERY STATUS back to Debian every time the percentage changed – and in the process I found this link detailing a LOAD of variables you can use. The next thing was to get a Tasker task taking in an MQTT message and SPEAKING it out – that works a treat.  If I could just figure out how to get it to take in serial (see the article on the RFLINK gadget) – I could take in my doorbell presses and have them play bells!!! I do however have the thing taking in MQTT and playing a REALLY nice doorbell.

Update: All of this incidentally while in standby  - I fully charged the K10000 phone and disconnected from the mains. The screen is off and occasionally as well as running Debian and my Node-Red stuff, it acts as a doorbell. THREE days later the battery is around 76% – how many server backup systems manage that!!! We're talking at least a week in the absence of power. I can see a solar project coming on here.


Raspberry Pi Zero WiFi

Raspberry Pi Zero WiFiI should have just entitled this “Raspberry Pi” as it keeps expanding (now covering the rest of the Pi boards – but keep reading).. as you will see, the title is a little restrictive given what we’ve done over the last few days. Friend Antonio over Italy and I (still stuck here in the frozen wastes of the Northeast of England) have been working quietly in the background on making the script compatible with the new Raspberry Pi Zero WiFi (RPiZW) having already managed to get it working on a range of boards and operating systems including RPi2, RPi3, Debian, Xenial, various Orange Pi boards, various FriendlyArm boards, the Odroid C2 and more.

At under a tenner, no-one can claim this tiny WIFI enabled RPiWZ is going to break any records. It is slow. very slow compared to a Raspberry Pi 2 or perhaps an Orange Pi Zero... and at first attempt I nearly gave up after waiting a whole day for my script to run (and fail) - something that can take maybe an hour on more powerful single board computers such as the RPi3 or the Odroid C2 etc.

However, having failed to get the script to run on the official Raspbian distribution for this board, for a variety of reasons, we next tackled DIETPI. Here, this slimmed down operating system comes into it's own and the PI Zero WiFi runs a lot more swiftly than it does with stock Raspbian. Still, by lunchtime yesterday I'd stopped the script due to various errors. By late last night however, with a little manual injection I had everything running on this tiny board - Apache, PHP, Node-Red with all my usual Nodes, MQTT, Sqlite, PhpLiteAdmin, Ha-Bridge, MC and much more, all with no manual intervention (just as well, given the time it takes).

This weekend while I was out shopping for a new milk-frother, our friend Antonio over in Italy was busy working on some last minute amendments to the script which, you'll recall now runs on a range of devices and systems including Xenial and Debian. We’ve now completed the  updates to the script, including the ability to run on the RPiZW.  The sheer size of the RPiZW (or rather lack of it, being exceedingly thin) means you could fit this board, able to control a house, on the back of an LCD display and have the whole thing mounted in a reasonably slim wall-mounting box. The Orange Pi Zero on the other hand has that large Ethernet connector which means a slim case is out of the question.

There is of course competition for this board, the Nanopi Neo Air is actually smaller (different format of course, being square) - and no doubt a lot faster - but like the RPiZW it has no Ethernet. One issue I've had with many boards is that of WIFI reliability. Up to now, the WIFI on the RPiZW is rock-solid - just as well, as it doesn't have hardwired Ethernet capability (well, not without some soldering or a compact-size-defeating USB dongle). The NanoPi on the other hand works well and is way better technically but I'm not 100% happy about the WIFI on the latter. All of this could change of course with future software updates.

Raspberry Pi Zero WiFi: Here’s what I did (total time 4 hours -  VERY little of which I was actually doing anything – well, watching YouTube videos actually):

  • I grabbed the file DietPi_v145_RPi-armv6-(Jessie).img
  • I used SD Formatter to format a 16GB card then Win32 Disk Imager to blow the image onto the SD card.
  • I plugged the card into the RPiZW and powered the board up, plugged into a screen – and with keyboard and mouse connected via a USB hub.
  • I started up the Pi – that takes a little while and it eventually wants you to login as root (initial password dietpi).
  • As per initial dialogs in DietPi-Config, I set up the WIFI.
  • The board went off to do some downloading and came back to the DietPi-Software - I swapped from DropBear to OpenSSH Server and lighttpd to Apache2 - but didn’t install anything else.
  • At the end of that I could get into the board remotely using WINSCP and no longer needed the keyboard and mouse.
  • I copied the script across to the root directory – ensuring it was in Linux format (Line feeds only) and that it had execute permission.
  • It went off and automatically set up a PI user with password “password”. I logged into the board (using WinSCP) as user  pi. I copied the script across again and once again made sure it had execute permissions. I ran the script.
  • Several items were downloaded. I waited patiently until the main menu came up. I accepted all defaults but added HA-Bridge.
  • I was asked for a user name (user) and password – and an admin name (admin) and password… (you can opt out of that now and leave defaults if you like) and at that point the script – as you’d expect – went off for 4 hours (using a half-decent microSD from Samsung) doing it’s own thing. And yes, watching the WEBMIN setup DOES feel like watching paint dry.
  • At the end of all of this – I rebooted the board – and that was the end of that – a perfectly working RPiZW.

Something that has come out of this – is the importance of SD speed… I’ve always known this but NEVER has it been as obvious as it is here with this slower board. 4 hours – recall I mentioned an earlier attempt which failed but also took longer. Well, now I’m using a decent Samsung microSD.

Raspberry Pi Original: Which brings me to the Raspberry Pi – not the 2 or 3 but one of the originals. The script appears to be working perfectly now even on pre-Pi2 boards with full size SD card (Raspberry Pi © 2011.12). Sadly when I was using those I was not aware of the need for the best SD and THIS install took 7.25 hours – if you plan to try one of these – get a decent SD! Still – all working so an otherwise useless Pi is now up and running.

Raspberry Pi Zero: On a whim, I took a copy of the microSD I used on the RPiZW and dropped it into the lowly, cheap and cheerful Raspberry Pi Zero (the one with nothing) – I then took a USB adaptor and plugged it in, with one of those really cheap unbranded WiFi USB blocks at the other end.  I plugged in power, waited, checked for new IP addresses and LO AND BEHOLD that was online too!

Raspberry Pi 2:  I tested the modified script on the Pi2 and as well as being a darn sight faster to install than the units above – it does work well.  I did however notice that the yellow Node-Red GPIO node does not work – possibly something missing in DietPi. However – there’s a great utility called GPIO which gives you full command line access and I’ve now added that as an option to the script. I’ve tried GPIO access including PWM and it all works a treat as Pi user.

git clone git://
cd ~/wiringPi

The above it what I added… then use GPIO – now, with the –g option, the pins correspond to the actual connector which is nice – so for a nice dim LED on GPIO13

gpio –g mode 13 pwm
gpio –g pwm 13 20

Not tried that on the Zero but I assume it will work as well. If anyone knows why that yellow GPIO node sits at “connecting” do let me know. Remember in all of this we’re using the DIETPI image – NOT original Raspbian – which IMHO is a little heavy handed if you don’t want a graphical interface.

Things are looking up.

Raspberry Pi backupAnd now for something completely different: Meanwhile I thought you might like to see this Raspberry Pi battery backup  (not for good reasons) -   I bought this a couple of weeks ago and it turned up today. 4 brass spacers and it fits onto my Raspberry Pi 3 a treat.

But – pull the power out – and the Pi reboots – who on EARTH dreamed this up!!! They claim 9 hours of backup but no good if power loss causes a reset… worse -  I bought it from Europe at £9.49 and I COULD have bought it from where they probably got it from in the first place at £8.73 and no postage. Oh well. I’m assuming I got a bad one – surely they could not have designed it this way. Anyway, it has a 3800maH battery and it all fits perfectly on the back of a Pi.  On the FRONT of my Pi I have an LCD display and the whole thing was intended to form the backbone of my updated home control in Spain when we go back there in April. A clue to the problem may be that there is a small yellow power indicator on the Pi, suggesting the pack might just be putting out insufficient voltage for the Pi + LCD. So – I tried it with a Raspberry Pi 2 on it’s own – same result. Just thought you’d like to know in case you were thinking of buying one of these. THIS looks GOOD (Thanks Antonio) – any experience of this??  I have some goodies from another company coming in the next couple of weeks which look promising as uninterruptable supplies– more on this soon.


Odds and Ends

Just a few odds and ends… we’ve arrived safely in Spain and I’m not getting quite as much blogging time as I’d like as there are repair jobs to do – but I managed a little item on Node-Red earlier – I’ve had people in here asking for simple-use examples – so that’s the first.

Gauge Progress: I’ve not forgotten my HTML5 Canvas gauge – it’s coming along nicely but along the way I’m hitting minor bottlenecks on image loading – and image pre-loaders are not helping. Most but not all of this came to light when I moved thousands of miles away from home with the attendant delays! I’ll return to this one soon.

Node-Red Menus: Regular readers may recall from earlier blogs that I’ve been griping about the menu in Node-Red being there even if you have only one page. Some may have noticed that a blog reader pointed out a simple CSS solution – well, now there is better – Node-Red master as of now has an option to turn the menu off. I’d give it a day before updating to make sure the latest version had filtered through to updates.

Mint Linux: I wrote a while ago about this – so often these things fall by the wayside – well, I’m still using it – can’t find anything wrong with it on my little black laptop.  It isn’t Windows but for development work – it runs a lot faster on that old hardware than Windows 7 did and everything works right down to my Logitech Bluetooth headphones. Anyone else using this on an Intel-powered laptop?

Raspberry Pi Power backups: You’ll probably know I’ve covered this in the past – various solutions for backing up the little SBCs in the event of power failure. My best solution up to now has been RavPower battery charging units – but not all of them seem to work in the same way. I did find a little LIPO unit that works on one round 3v6 battery but it’s power output would not work for a RPI3 for example (which takes more power than the RPI2. Well, I’ve just discovered and sent off for one of these. It’ll take a few weeks but I’ll let you know how that goes. Anyone bought something similar? How did that go for you?


The Mint Experiment

Anyone who’s known me for years knows I’m a died in the wool Windows man.  Over many years from Windows 3.1 onwards, I’ve done down that road until ultimately all my machines are now Windows 10 – and I have to say that, while it could be argued before Windows 7 that it was not the most reliable operating system in the world, from that point on pretty much all of that changed. I regularly leave Windows 10 machines running for weeks on end and I’m sure they’d keep going for many months if it were not for the only remaining issue- that of pesky updates which Microsoft are determined we have whether we like it or not.

Now to be fair there was a time when Adobe – a company I cannot stand, used to issue updates for Acrobat almost on a daily basis and at least that no longer happens. I can usually tell when Windows wants me to update because Skype conversations become almost unusable and other strange things happen – at that point I reboot the machine and lo and behold – a Windows update is in progress – don’t turn off your machine. Thanks – I’m in a hurry for  train…

In my previous role as IT Director of the FSB, I would take it upon myself, being a hands-on type, from time to time, to try the latest Linux on one of our PCs, only to end up with utter disappointment as it would fail to connect to a WIFI access point or the video would hang over the end or some such issue – there was always SOMETHING – and so I would scrap that idea for a several months before trying again. At one point I used to get hate mail from  members who were clearly selling Linux machines -  for supporting Microsoft! Serious hate mail.  So over the years I kept trying again and always ending up with disappointment. (I’ve never used Linux on my personal machines because yes, I do like the latest state of the art, graphically intensive games and yes I do use lots of proprietary packages such as Magix and others which are simply not available on Linux.

In recent times as regular readers know, I’ve been forced into taking an interest in Linux because Debian (a Linux variation) runs on the Raspberry Pi. 2 years ago I bought a Raspberry Pi 2 (having played with the original Pi, loaded up the graphical operating system and immediately put it on Ebay in disgust at the speed). On the Pi2, I was pleasantly surprised to see that Raspbian ran at a reasonable speed and since then I’ve done many different board reviews and installed Raspbian and Debian on lots of boards, leaning on experts along the way as my knowledge started to build.

A while back I took the plunge and installed Ubuntu onto one of these boards and with help from others soon came to realise that there were not THAT many differences between Debian and Ubuntu and one of the things that has struck me in all this time is how reliable the operating system can be – I’ve a Pi that’s been sitting controlling stuff for well over a year now without as much as a sneeze despite me poking live updated and tweaks into it without rebooting.

Linux Mint on an old Dell laptop

And so with that in mind, last week I took an old DELL E4300 I had lying around which had simply refused to update to Windows 10 from Windows 7 (no matter how many ways I came at it) and which was so old it was really not worth opening up – and grabbed myself a USB stick with Ubuntu on it, ready after maybe 3 years of abstinence and armed with much better knowledge than previously, to try again.

Well, what a disappointment that was. Ubuntu loaded up no problem, with it’s rather dated looking purple interface – and asked me for my WIFI password – I promptly gave it this – and before long I had a working laptop. Or so I thought. The WIFI icon looked broken – yet I could pull up a browser and go on the web  - no problems. I was impressed by the ability to watch video on the BBC website, something that in the past on Linux was just not on.

tmp95E7That enthusiasm lasted maybe an hour. The App store decided not to work – coming up blank. But hey, that was just one program. I noted a nice graphical email client complete with calendar. I set it up and within minutes I had my Google calendar up and running. But as soon as I tried putting in email  - “Cannot get email as there is no Internet connection”. I opened a browser and sure enough the Internet was fine – but still that broken WIFI indicator. From there, things went downhill – it could not store draft emails due to a permissions issue and – nope – sorry life is TOO SHORT FOR THIS – I was reminded of the frustration of previous years… what HAVE these Linux guys being doing all this time, I thought.

I was in the process of giving up when I read something about Linux MINT. I liked the interface. In the instructions for installation I had to go get PendriveLinux so I could install the image on a USB stick. You should be seeing links here as appropriate. I went off to the official download page and picked the 64 bit version using the Xfce graphical interface as it had been suggested that while simple out of the box, this version had lots of options. I put the Mint Linux onto the USB stick and put it into the laptop. I must admit I found a certain satisfaction in wiping Ubuntu. The installation went well and WIFI came up but this time, no broken WIFI indicator. The taskbar seemed to be missing a battery indicator but It didn’t take me long to figure out how to add all sorts of widgets to the taskbar to make me feel at home (including a battery indicator).

I noted that Thunderbird email was installed and I set that up with my two email accounts – no problem whatsoever… but no calendar. Of course, that’s a plug in and it needs another plug-in to get Google calendar functionality – but all of that took mere moments to organise and now I have fully fledged email and calendar. Granted it is a little slow at pulling in the 35,000 emails in my main in-box – but it’ll get there I’m sure.

I hit a few obstacles on the way - my by now standard VNC server would not have it until Mr Shark suggested I try  x11VNC – that worked a treat.  Then I had it asking pesky password questions every time I tried to breath – that was easy to fix  - then I noted on power up that the KEYRING wanted another password – you’d think I was operating a bank. That went quickly – and from there everything went smoothly.  But this was Linux MINT – about which I know nothing at all. The funny thing was, doing an APT-GET UPDATE showed that in fact this is Ubuntu Xenial… now I’d already, with lots of help from MrShark, modified my all-singing install script for Ubuntu. I didn’t really expect it to work on this machine but having written down the steps to put everything together I thought “what the hell” and ran the script – it failed of course as it looks for UBUNU, DEBIAN, RASPBIAN or DIETPI – and this was LINUXMINT. I added a check for the latter THOROUGHLY expecting a host of horrific error and compatibility errors.

I was with some delight that I returned 15 minutes later to find that not only had the script worked – but without a single error – adding NodeJS, Node-Red, Apache, PHP 7, Mosquitto, SQLITE, MC and several other programs to my installation.  I rebooted to ensure I wasn’t dreaming – sure enough – everything worked.

The laptop has no Bluetooth interface so I plugged in one of those cheap Chinese Bluetooth USB units… and went off to the Bluetooth controls – without ANY hassle my Bluetooth mouse connected!!! I plugged in my Bluetooth headset – it got that – I went off to the BBC website and… – the Bluetooth headset didn’t connect automatically – so I went to the volume control – it was in the options – sure enough – perfectly synced Bluetooth.

Now if SKYPE video will just work….

Up to now, hours later, I have a nicely usable laptop with all my development toys (well maybe not NotePad++ but there are a couple of decent Linux editors,  my email and calendar, Chrome browser and a full office suite – making an otherwise pretty hopeless old laptop into a useable tool!

Issues: This morning I ran out of battery. A sign came up to say the battery is low – save your work – but that that point the mouse and keyboard stopped working – hence saving work was impossible. A moment later, the laptop shut down. I charged it and it came straight back up with the same message – I had no option but to shut it down (sluggish mouse response as an aside). After rebooting all was well.   Also Skype does not appear to survive power cycling and has to be loaded again.

If you like this post – please share a link to it by social media, by email with friends or on your website.
More readers means more feedback means more answers for all of us. Thank you!