Monthly Archives: November 2015

Raspberry Pi Zero

Pi ZeroIf you have been hiding recently you may not be aware of the new Raspberry Pi Zero. Hot on the heels of the CHIP and other low cost micros and by the look of it a zillion miles ahead of that daft BBC “Micro Bit” (there’s a shocker)   the Raspberry Pi Zero has some great potential not least because of the price tag – $5 which as you may know is around £3.30 right now.

So what do you get for this ridiculously small amount of money. A Raspberry Pi 1 at double speed, amazingly. Yes, running at 1Ghz the Pi Zero is a full Raspberry Pi and it is tiny.

The official MagPi magazine is out today and will GIVE AWAY one of these on the cover.. not kidding!!! So now every child in Britain etc. CAN have a computer. I have to tell you I am so pleased there’s an alternative to the BBC’s second and hopefully failed attempt at world domination.

Raspberry Pi ZeroSo what could be wrong – £3.30, a full Raspberry Pi – what’s stopping you?

Well, before you rush off.. there is tax – which for example in Chicago is a miniscule 39 cents. Oh yes, this is real – my Pi Zero is ordered and waiting for me to pick it up at the shop – a grand total of $5.31 which is £3.51

But… mostly the ads say “available NOW” – just as they did with the original Pi until you get to the bottom of the page where it says “due to high demand we are currently out of stock” – surely there must be a law against that but hey ho.

I gets worse but before I gripe about British rip-off merchants, let me clarify – this is ALMOST a Raspberry Pi – it has no ETHERNET.. and that’s a big but! Why? Because if you’re familiar with the Pi, you will know that most if not all of the WIFI dongles available for the Pi, which working, are not the most reliable items in the world. This would be IDEAL as, say a dedicated MOSQUITTO server or BLYNK server or similar but would I trust one of those WIFI dongles 24-7 – no.  A real shame.  However, by the time I get my hands on this device and get it back in the office to play with I may well have found someone to prove me wrong about the WIFI reliability. If you know better – please do write in. It was suggested that you could plug in an Ethernet to USB adaptor – but judging by Ebay prices it would be cheaper to buy an Orange Pi which is a better bet than Pi Zero + external Ethernet – or will be once they sort out the software.

So – you can run Raspbian (not entirely sure how to do that yet without the Internet – perhaps BerryBoot might come to the rescue here). – Oh and before I forget – the really good new news on Raspbian is that future versions will have Node-Red built in by default (I love it when I make the right choices) and this just opens up SO many possibilities.

Remember - £3.51 all in -  I just bought one for (the few places in Chicago that do have these in stock are offering one per family so there will be a couple of families going to the store with me Smile )

So here we go -  - MADE IN WALES – which is on the same tiny land-mass as the rest of Britain right?  So if the Americans can charge me £3.31 – what bargains might I get in England you wonder, a mere stones throw from the factory..

Let’s take a look shall we, at the bargains available in the UK right now.  - a mere £10.54 + VAT which comes to £12.65 – or a mere NINETEEN DOLLARS. Oh yes, you get a couple of cables with that – you know, the ones you could pick up for a couple of quid from Ebay.

Pi Hut offer the basic Pi Zero at £4 which is a little more like it – but it is all irrelevant as they are out of stock.

Pimoroni also charge £4 for the basic item - but when you press the buttons – they don’t work – I’ll assume that means out of stock.

For around £6 you could buy the MagPi magazine and get a Pi Zero for nothing!! Except you can’t  as they are out of stock.

So – assuming you CAN find somewhere to buy this – I do think it has a bright future unless someone comes along with the same thing plus Ethernet for £6  - but remember this is a souped-up Raspberry Pi – NOT a Raspberry Pi 2 which remains a superior beast.

IF a cheap WIFI dongle can be found on EBay that works reliably and If the likes of BerryBoot will pick up on that dongle so you can simply download the operating system without needing a PC or jacked-up-price-SD card, then I predict a bright future for this device – not least because of the massive amount of PI-related information out there, the friendly nature of Raspbian and of course the stunningly brilliant Node-Red.

Expect more on this next week – I pick mine up on Saturday, just before heading back to the UK as we have Thanksgiving here in the USA today and there’s no chance of getting into the stores in time today.


A better Terminal? MobaXterm

New reader Lorcan sent a note this morning to point me to this terminal for Windows..

i have to tell you – at least at first glance this appears to blow the pants off WinSCP, TighVNC viewer and others – as it does the LOT!


So the above are your options – I’ve already had VNC and SSH talking to my Spanish Raspberry Pi without a hitch.

As if this wasn’t enough – it has a load of local servers you can run to test stuff! FTP, TFT, HTTP, SSH, Telnet, NFS, VNC, Chron. Sadly these only run while the program itself is running – but hey – for home use it’s free – what more could you want!

In the process of this I noticed that last item – MOSH. You need to install it on the PI to run it, essentially it is SSH for mobile use with potentially bad connections by the look of it. I noticed only the terminal but if you need to control your Pi from the train – this could be worth looking at – indeed, it was worth installing Mobaxterm just to discover Mosh!

Of course, being me I closed the first session with the little cross – next time I opened up it said “You have a detached Mosh session on this server”.  And that’s when I learned how to use the KILL command.

All this in one lunchtime session!

Update 25/11/2015 -  I’ve been using this for a few days now and there are some major and minor issues compared to WinSCP. Firstly, right click a file in WinSCP – and you get to handle properties the way you’ve always done in Windows – tick boxes. Nice – no such thing in Mobaxterm though when I mentioned the idea to the authors the respondent thought it was a good idea. More importantly – drag and drop. Now I don’t know if it’s just the fact that I’m 4000 miles away from home – but updating a couple of files on my Raspberry Pi by dragging from the desktop into Mobaxterm took so long I just gave up. I loaded up WinSCP – and almost instantly the files transferred across.  I’m not writing off WinSCP yet.


Another gap

Depending on what’s on my laptop I may go quiet again for a few days – I’m off to the USA for Thanksgiving. No I’m not American but my wife is and the folks over there very kindly invited me over for the week. Chicago to be precise – I’ll bet it is colder there than it is here in Blighty (meanwhile back in Spain my cameras tell me the skies down at the south coast are clear blue – which is good news for my 12v battery out there as the solar panels soak in energy). I think my Blynk/Nextion/Node-Red/Pi/ESP thermostat is running properly and I’ve just added a “frost” setting – now is as good a time as any to test it.


Blynk Update

Updated 22/OCT/2015 : Rather than write another blog I’m updating this one in the light of new info. New features added to the Bynk App (which allows you to control various IOT gadgets from your phone – OR talk to Node-Red and hence to anything that Node-Red can talk to (which is just about everything) – include the ability to Share the App – allowing others to view and control BUT NOT EDIT the App – which is great – though it does say “30 day trial” without saying what happens at the end of the trial – communication is not these guys’ greatest point.

Blynk using Node-Red

I’ve been asking for multiple pages per project – well they didn’t quite do it that way, they did multiple projects per user with seamless movement – only thing is that means a different access code on each page – I’d have rather had access code selection per item but there you go.  As for multiple accounts, it is still a pain to switch from one to another – they are not stored and so you have to enter details every time you switch – not going to happen. 

hollyberrySo for now the answer appears to be ONE Blynk server. Thanks to the “Raspberry Pi2” setting you can have up to 64 virtual pins per project which I guess is ok (why would you want more – well, let me tell you – thermostat settings – week and weekend settings for peak and off-peak, frost fallback etc, + and – buttons and displays of values –you soon rack up the pins – but I’m thinking the designers thought we might just want to turn a few lights on and off.. Noooooooo.

So you can control things like ESP8266 etc directly with a little code in the ESP and Blynk – but my chosen route is Node-Red –the only problem with THAT is that the only Node-Red node to interact with Blynk – does not like the Blynk server going down – i.e. it reports it – with a “disconnect” notice but doesn’t actually do anything about it – I’ve written to the designer – I’ve looked at it myself without much joy and I’m taking the opportunity here to ask if any of you node-red node-designing wizards would care to take a look. It needs to detect the failure and try again every few seconds until it gets the connection – if I were redesigning the node I’d have an output if if failed after X attempts – and have that send me an email via the email node!

So – the project is coming along – all we need now is a smaller zeRGBA and feedback to all controls and a thermometer. Sync sync between mobiles is apparently taken care of  but still hoping for the ability to import our own images and different size buttons and removing that DAFT Vx numbering on the buttons (apparently it is off for guests – thats’ a start) and the mini-level indicator (as on the box) and the ability to rename zeRGBA (why would anyone think we’d only want one???) ...and... we need to be able to get more stuff on a page!

Right now there is an issue, 2 of us have spotted this – renaming labels – log out – log in – sometimes doesn’t keep the changes – will report as I found out more about this (local server).


Some thoughts on Node Red variables

In learning how to use Node-Red I’ve changed my coding countless times as I’ve found better ways to do things.

Please note that in 2017, the way I use global variables here is out of date. It still works but for example is now written as global.set("fred",1). Read this later article on using globals and context variables.

I’m currently working on my thermostat code using a Nextion touch-sensitive display, Raspberry Pi2 as controller and ESP8266s for relay and temperature/humidity sensing. This was a slow-running project until my old Arduino-based heating controller packed in yesterday without warning and so now the fate of the household heating is in the hands of an on-going project.

So the general idea is easy enough – lots of settings for weekdays and weekends, read sensor, control relay. That’s pretty much it in a nutshell except that on my first attempt I didn’t take into account power cuts – and when the power was restored to the Pi, hardcoded defaults took over instead of the settings I’d put in using the display.

So there’s a need for lots of variables and a means to store them permanently. This is what I’ve come up with and the logic behind it:

In order to pass variables around in Node-Red, you need to use “” variables as these are the only ones that will work from page to page (i.e. from powering up node-red to powering down across all pages of your project). This can make for messy variable names for those of us who like to keep things short because we’re lazy or developing typists finger.


I’m a C person and so a struct is ideal for me – keeps everything together.  The nearest I get to that in JavaScript is an object and that’s fine.

A global object containing everything to do with my stat.

   var stat = {
display_temperature : 22,
display_humidity : 45,
heating : 0,
display_external_temperature : 14,
display_external_humidity : 54,
display_status : "Normal",
display_target_temperature : 20,
display_enabled : 0,
display_last_page : "home",
display_last_colour : 0,
pass : "",
display_dim : 60,
peak : 21,
night : 16,
frost : 12,
hold : 0,
weekon : 480,
weekoff : 720,
weon : 480,
weoff : 720,
week2on : 780,
week2off : 1380,
we2on : 780,
we2off : 1380,
temperature_manual_override : 0,
update : 0

That stat var of course is only valid while the relevant function is in use and is invisible outside of that particular page hence…;

So now we have a nice but somewhat longwinded way to access the variables..;

(I know I should probably use displayTemperature but there’s no global replace in the Node-Red editor (hint)).

Because JavaScript objects are passed by reference – you can use a reference to this in other pages which makes things a little more readable.




That’s more like it and you can write to that new variable and it will update the original as they are one and the same.

The obvious solution for storing variables permanently, is a database, but I’m trying to minimise that to keep writes down for the time when I run all of this and much more on an SD (currently using a little 2.5” drive with the Pi2).

The file node lets you read and write text files and so the next challenge was how to get that object into a text file – easy:


That JSON string can be saved directly to disk and the inverse is true of course…;

The good part of that is that the string saved to disk is readable and if need be directly writeable.

Thankfully when the file node reads a file if the file is not there, it returns “undefined” so in my function I check for undefined and if so – create a new one with defaults in it. I added a timeout variable in there and whenever I update any item in the object I also set a counter to 10.  That counter is decremented every second and when it reaches zero, the object is updated on disk. That means I can do all sorts of adjusting of controls on the Nextion display and only when I’m done will there be a single block write to the disk. The READ is only done once when Node-Red powers up.

Seems like a reasonable solution and it’s nice and warm in here.

In an earlier blog you’ll see my Nextion display solution which is quite pretty ( created my own imagery because built-in Nextion options are currently not that good) – here just for reference is the current Node-Red block controlling the display and the stat itself including disk reading and writing.



APDS9960 Gesture Sensing with ESP8266

APDS-9960A thought for a little display project. I recently came across some code for an LCD display (160*240 - detailed in a previous blog) using the ESP12 and an LCD display. But I'm inclined to use the Nextion display (also detailed in a previous blog) because it is touch sensitive. The only problem with that is that the Nextion is somewhat more expensive and larger.

One of my pals brought this chip to my attention – the APDS9960 Digital Proximity, Ambient Light, RGB and Gesture Sensor.

It is i2c and not only reports back RGB and general light levels but also has it's own IR transmitter and logic inside to decode simple up, down, left and right gestures. So here are my thoughts - for example for a simple thermostat. Put next to the display it would offer simple up/down control of temperature as well as left/right perhaps to show a graph.

For more complex operation, one could make some kind of convoluted movement which would then trigger off a menu - with left/right selection and up/down change.

Worthy of further thought and has anyone already implemented the i2c code (Arduino ESP8266 C for example) to talk to this device?


Node Red Script

imageNow that I’m back in the UK, I’ve left a Raspberry Pi2 in Spain monitoring my solar pergola lighting installation as an ESP8266 measures the state of a solar-charged car battery every 15 minutes and reports minimum and maximum voltages daily by email. The unit also controls lighting and while not actually controlling heating, has a test setup which controls a Nextion display. Meanwhile I have a similar setup here in the UK which is actually connected to a Nextion and which will soon be in charge of the household heating.

But something has been bugging me. Regular readers will know that during the last month or so in Spain I had a lot of WIFI issues, pretty much resolved now thanks to the help of you readers – and in that time until I got to the bottom of it all I spent a lot of time improving my ESP8266 boards to the point where I recently took off the last-ditch reset-the-board option as they are working utterly reliably even in the face of rubbish electricity and the WIFI issues.

In a recent development I decided that in the unlikely event of another power cut (turns out not as unlikely as I’d hoped) I’d have Node-red send me an email on startup.

Well, once a day I was getting these, usually around 11am or so. The unit in the UK was slightly different but still generally resetting in the morning. I wrote off to the guys in the Node-Red Google group – they’re really very helpful and they asked me to check using PM2 some things.

Turns out PM2 (process manager) is a lot more powerful than I’d given it credit for. Anyway I sent the guys a copy of my script or rather the part that starts Node-Red and puts it into a service to run after powerup. It goes like this…

cd /root
pm2 start /usr/bin/node-red -- -v
pm2 save
pm2 startup

The first line is probably irrelevant but I tend to do that a lot to avoid surprises. Anyway, I’ve used this from day 1. I’d sent an example log and one of the things in the log was logging of a LED I toggle off once a second in a simple indicator. I did comment that I thought it was a bit daft logging that every second.

One of the guys in the Google group (Dave) asked me why I was using verbose mode for Node-Red and don’t you know – I spotted the “-v” in my script. How that got in there I’ve no idea.

Anyway to cut a long story short, I needed to scrap that service and create a new one without the –v for verbose.

pm2 list

The above line shows list of services running under PM2 – turns out only one – service 0 so…

pm2 delete 0

got rid of if which allowed me to start again…

cd /root
pm2 start /usr/bin/node-red
pm2 save
pm2 startup

So now I have Mode-red running on both machines (since last night) without the verbose logging. I should stress I made absolutely NO other changes.  Now bearing in mind that my total work on these Pis is using a couple of percent of processor power typically and maybe 50% of the RAM…. let me throw this at you…

Since restarting the services without verbose mode last night – and bearing in mind it is now 4:30 pm the next day – NEITHER of the Node-Red installations has rebooted yet both have sent in their daily battery state email reports.

There is time yet of course – I may be going off on a complete tangent – but it does seem odd that simply removing verbose logging would stop regular Node-Red reboots!

Update 21:00:00 Wednesday – oh, well, I just had an email from the local Pi to say Node-Red has reset itself. Sigh.


Espressif New Board

imageWell we know that the ESP8266 replacement will have Bluetooth low energy, a different architecture and more RAM – something to look forward to – so now here’s a sneak preview – this is not the latest PCB but it’s better than nothing I’m sure you’ll agree.

So we’re looking at something with a few more pins than we’re used to and very little else – I’m seeing a crystal – I’m not seeing EXTERNAL flash or RAM here so one can only assume that it is internal this time? I’m looking forward to seeing more of the new wireless SoC with two Tensilica L108 cores and called ESP32. So, faster WIFI, Bluetooth, dual core, low power improvements, more peripherals, more RAM, better security and simplified APIs and approaching 40 I/O lines (though I’m only seeing 37 actual edge connections in total on that board) -  what more could you want.

Do you know more? If so – spill the beans!!! Unlike some posts I’ve seen this is not a random image – it was supplied to me by Espressif themselves for your entertainment! Oh – here’s a link with some useful info…  also a contribution by reader Rudi here -






imageI thought I’d pen a general line as I’ve been quiet the past few days. Depressing news about France! We’re back in the UK after our summer in the sun – and nothing works – we’ve replaced the fridge, the microwave, you name it. I have managed to get some tech running, my test Raspberry Pi with Nextion display is up and running and checking the temperature downstairs – which is markedly different to what the room thermostat says – a difference I can only put down to the thermostat being on the same wall as the heating system.

As I left Spain, the WIFI issues were pretty much a thing of the past and one tiny issue I had with my Draytek router, inability to setup local DNS, was resolved this week by a kind technician at Draytek who kindly remoted into the router and brought it bang up to date – well beyond the updates I could find on the website and had I known this would be successful I would have bought another 2830 router from them for the UK. Rather handy to be able to access ESP devices by name internally. All of this is moot as the power went off over there yesterday and I’ve someone looking in on Monday to reset the fuse (some folk have all the luck, don’t they).

Time I would have normally spent on development has been spent getting TVs etc to work. Still some way to go but I want to fairly quickly get internal and external ESP temperature and humidity sensing up and running so that at least I can start graphing heat loss in the place. We use electric heat here so making the best use of heating is a priority for the winter.

No new news on Orange PI – no new versions of Debian for it that I’m aware of. No new news on Espressif’s latest product, I hope to have something new.  I’ve a PHOTON on the way to play with, Kamil Baczkowicz has confirmed that there’s a minor issue between the current Java and MQTT-SPY – older Java versions work fine and a new one will be out in January. I have MQTT.fx working but right now it has a long way to go to compete with MQTT-SPY – worth a look though.

Guy Molinari has sent me a sample of his ESP-12 LCD board which uses that little 160*240 colour LCD display I referred to in an earlier post. I’ll write something up when I actually have a desk with a soldering iron on it (workshop has yet to be built in our new home and it needs a concrete base first – all of which will take time).

Finally an “ESPresso Lite” is on it’s way to me to have a play with – more on that in a couple of weeks or so.

Update 26/11/2015: Kamil has just confirmed a workaround fixing this minor issue in the otherwise excellent MQTT-SPY – 0.1.3 beta build 24 works a TREAT. Still my favourite MQTT client test tool. – and I finally updated my last PC to Windows 10. Ahhhhh….


ESP32 Coming Soon

So many of us have been happily using in the inexpensive ESP8266 chips for some time now for IOT applications, home control etc and long may that continue. They do have SOME issues – for example they are short of RAM memory to the point that all except critical subroutines have to be stored in FLASH and pulled out when needed. The somewhat slows things down as the 80Mhz processor (160Mhz at a pinch) has to pull stuff out of the external serial FLASH to use it. In practice the ESP8266 is still very fast but this is just one step that would be nice to avoid. Lack of IO lines also is a little painful as so many of the available lines are dual purpose – GPIO0 for example cannot be held low on powerup as it is used to put the processor into programming mode. We get around these issues but wouldn’t it be nice if we didn’t have to.

By the look of it, the upcoming ESP32 will have more RAM (400KB) and more IO (close to 40 !!!) IPV6, a little more expensive – we’re hoping not MUCH more as initially Espressif were saying it would not be more expensive! Bluetooth will be supported, there’s a dual processor (two powerful Tensilica L108 processors), better security, faster WIFI (the WIFI will have it’s own processor hence no more worrying about delays – that’ll be a relief) – and low power. QFN packaging.

All sounds very exciting and thanks to Espressif and readers in here for bringing this to my attention.