Monthly Archives: April 2015

ReadyNas Duo Power Up Revitalised

ReadyNas Duo

I have had a NetGear ReadyNas Duo lying around for longer than I care to imagine… not because it is slow (and it is). not because I have something better (I do) but because for some reason well beyond my understanding the designer, when putting it together never wondered “what happens if the power goes off”.

I’ll tell you what happens. It STAYS off!! I’ve had a couple of attempts over time on Google trying to find a software solution – there isn’t one. They’ve not updated the software for this original model for some time now and when asked they said it was a “hardware limitation” (which goes back to my comment about the  designer).

So, I read that one guy had set up 2 555 timers – one to wait a couple of seconds – and another to press the ON button using a relay. I figured there must be a better way. That would work but it’s a tad messy.

I got the meter out this evening, took the side off the box  and started prodding. The switch wire is grounded when pressed and at 5v the rest of the time (but not, sadly when turned off!!). I poked around and eventually found a connection (the red wire) which had 5v on it when the unit was turned off but plugged in.  I needed that, a ground (green) and the pin of the switch that is grounded when pressed (the yellow wire).

It just so happened that I had some DIGISTUMPS lying around but all you’re really talking about here is an Atmel85 – the little 8 pin job with internal xtal etc.  I loaded up the Arduino IDE and made the simplest program possible:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 0 as an output.


void loop() {

There you go – you don’t get any simpler than that. For 3 seconds after power-up, pin 0 is tristate – i.e. not there. For 2 seconds the pin becomes an output, set LOW (that’s done in init but doesn’t take affect until the output is actually switched on) – and then it goes tristate again forever.

Spot of glue gun glue and double sided foam to hold the little board in place, side back on, power up and… success.

So now that quite useless piece of RAID storage junk is once again of use. I’m going to make it my backup server in Spain as we’re over there in a short while.

Hope that’s of use to someone.



So  - would you like to play with Node-Red for free without even running it on your own PC? Check out FRED for Node-Red on Google . You just don’t get any easier than this!

Also this morning I stumbled across KODING - an online environment for HTML, PHP, PYTHON etc.  I don’t have any great expertise at this yet but I did notice that you get a full VM for free or so it would seem, with full root access. If you want to mess around with Linux commands without messing up your PI – could this be a good start? Certainly on my Windows 8 PC it all looked good. Not tried it on the Android tablet yet.



Raspberry Pi Processor Monitoring Widget

Raspberry Pi CPU Monitor

Don’t you just love it when people produce really useful tools for free!! And so it was that I got up early this morning to get a little Arduino/ESP-01 research done and got side-tracked by Google+

And the result – this baby.  This is a tiny piece of software that runs on the Pi and is DEAD easy to install – and on an otherwise unused port, on any browser gives you a more or less real time graph of the 4 cores of the board in action, providing instant feedback as to the health of your Raspberry Pi and how much load it is under. Marvellous.

The funny thing is I was just wondering about the effects of putting my 2 Pis in cases in a cupboard and wondering how this might affect temperature – and here, thrown in for good measure, a means to check that, too!!

Yoiu might want to search for rCPU and Smoothie Charts.


The Oak by DigiStump

One of our readers has rightly pointed me to this new Kickstarter project – The Oak by Digistump ( which has a number of things going for it – potential approval, secure WIFI interfacing and programming and Arduino compatibility.

Indeed it is hard to fault this device other than when comparing with solutions from China, especially for the UK and the hobbyist, postage, VAT and other nasties might just take this away from the “low cost” arena. We’ll have to wait and see. It does however look like a winner…

Meanwhile now we have the SLIP interfacing from ESP-01 to Arduino I have some plans for this cheap combination – see the last blog on the subject….


In a Far Distance Galaxy

A long, long time ago in a far distant…well, world, when I was pretty much using Arduinos for everything, the ESP-01 came along and my friend and colleague Aidan made a little board to handle a relay, an LCD display and.. an ESP-01. At the time we had no use for it, just seemed like a good idea.

Arduino board with ESP-01Today thanks to the likes of Tuan for his work on MQTT and the guys responsible for getting the ESP environment working on Windows via Eclipse (not to mention Espressif themselves) it is very tempting to think that we no longer need Arduinos.

When I say Arduino I mean of course any board based on the Atmel chips. In this case we used a 1284 chip which is an Arduino on steroids but completely compatible. Way more pins, 16K RAM, 128K FLASH – lovely. But as with most Arduinos, getting them to talk to the Internet is disproportionately expensive in terms of available FLASH and real cost.

Well, it was. Thanks to Tuan once again, we now have a way to merge the two. When I was talking to him a LOT about the MQTT software (as I kept finding bugs) he mentioned briefly that he was working on a serial protocol called SLIP so that the ESP boards could communicate efficiently and reliably with the likes of Arduinos.

Well, this evening I decided to revisit this and went off to his Github site here. You may be familiar with his esp_mqtt software which is superb and which I use as the base of my various ESP-12 boards. Well, in that link you’ll find another project of his called espduino. I suggest you take a look.

In essence there are a couple of binary files you blow into an ESP01.  The ESP-01 talks to the Arduino via serial and in the case of lesser Arduinos, that means talking via SERIAL (the only serial port) while doing debugging via a software serial port. Well, the `280 and 2560 based boards have more than one serial port, so I’ve taken his Arduino code and swapped things around… Serial1 for the connection between Arduino and ESP-01 – and Serial for debugging.

So basically once you’ve dumped the binaries into the ESP-01, you connect serial1 from the Arduino (in his example Serial) to the ESP8266 serial – taking into account any level shifting – best to run everything off 3v3 then you don’t have to worry about it.

He shows a wire from the ESP (CH_PD) to D4 on the Arduino but then doesn’t use it so tie CH_PD high as usual.

Run Tuan’s library examples on the Arduino and I can tell you that they just run – they work without issue – I’ve had the board send thousands of messages off to MQTT-Spy. The minimum setup takes in total around 9k, that’s including MQTT -  this is WAY better than anything you could achieve with Arduino Ethernet boards which, as far as I’m concerned are now dead in the water.

In my case we had this little board with the option to add an ESP-01 – took me minutes to get it working – I’ve now imported my command parser from the ESP-12 projects (they’re not that dissimilar if you are using C)  and now I have a board that asks my PI for the time (it’s in the blog somewhere – MQTT request – all my boards know and maintain the time, updated from a Pi on power up and every day otherwise) and can turn a relay off using the same protocols I discussed here.  All I need now is a boatload of libraries and if-then-else blocks to pad the board out into something really useful.

So why add this extra level of complexity?  Well, I use serial LEDs and PWM based lighting and the ESP-12 does NOT do PWM well AT ALL. If you control serial LEDs and say they are slowly fading out – any PWM in use fluctuates slightly. In addition I have serial LEDs working almost perfectly on the ESP8266 but every now and then there’s a timing-related flicker – almost never but you know it is going to do it just as the lights are fading out as you are going to sleep.

The Arduino on the other hand does multi-output PWM flawlessly and there is the great FastLed library for the serial LEDs – not to mention the ability to store data in FLASH easily which means that LCD fonts are easy to implement… and there are many LCD display libraries out there. The combination then is a matter of sense – and let’s face it you can get a bog-standard Nano Arduino from China for under £2 and the ESP-01 for WELL under £2 so using both together is hardly going to break the bank.

So there it is… that’s my Sunday offering – already the board is getting the time and controlling a relay… it won’t be long before I turn it into a kitchen sink.


External Drive for Pi2

I’ve read many articles about serious use of the Raspberry Pi and I’m now convinced that there is very little chance of mounting a Pi in a cupboard with MSQL and other write-intense programs – and expecting it seriously to last for a year or 3 because of the limited writes you can do to SD memory – that includes the ones that have wear-levelling.

With that in mind I’ve just strapped a hard drive to the Pi2. You cannot (it would seem) BOOT off the hard drive but you can put your entire file system onto there.

There are many, many ways to do this but as is often the case, Adafruit have a simple way.

Make sure you back up your SD before starting any of this in case it all goes to pot.

So in total:

I found a lead that has 2 usb and one mini-usb plugs – so that you can plug the drive into a power AND into the Pi  - I did this because the Pi will not power a hard drive – just not quite enough juice available. I plugged everything in and made sure the drive was whirring.

I followed the instructions on the above line from just under half way down below “If you’re using a stock  Raspbian install”.  I grabbed their helper. As I tried to follow the next instruction it went off to the internet for an update but proceeded automatically from that point on.

This helper program not only formats the external drive – but also uploads all your material from the Pi onto the external driver AND changes the file that determined on boot where to get materials from.

The instructions said “this will take a long time” – it took around 5 minutes as I wrote this blog. At the end of it I noted “your new root drive is accessible under /mnt. In order to restart with this drive at /, please type: sudo reboot”.

With a slightly elevated heart rate, after all this really WAS too simple….  I followed the instructions.

Well, much to my HORROR – tests showed that although there was indeed a new drive, I was not using it. I found 2 www. directories (one on the SD, one on the drive) and modified the one attached to the hard drive.  a quick run of the default web page (in the process of installing webmin you end up with a LAMP installation and hence a web server)  showed that I was NOT running on the hard drive.

So – I went looking into /boot/cmdline.txt – which is the file that tells Pi where to use for the root directory. It had INDEED been updated from:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait


dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

All very nice but not what I wanted – it should be pointing to the external drive. Could it be a simple as changing that bold text to /sda1 ??

YES was the happy answer.. I updated the file and checked the web page and sure enough I was now looking at the updated version!!

And now, to back up that hard drive before I go any further!!

Or maybe a trip out with my good lady for a beer… (which is what actually happened…)


Web Sockets Web Page Part 3

For this to make sense you should look at Websockets Web Page Part 1 and Websockets Web Page Part 2 first.

In this final section I add styling to the page  and also change the code so that you can send a partial message  i.e. {“my_input”:”Hello”} without affecting other parts of the page.

So in order to demonstrate this latest version you’ll need to go make yourself a theme (actually only one file needed for this – the css file) and put it in a directory called themes under the page shown here.

You’ll also need to change the Node-Red to this…


You’ll see here that I have to two experimental injects… and also I pull out the incoming web socket data – process the SWITCH and send a command off to one of my boards via MQTT to turn a light on or off, so NOW our simply page as well as looking pretty, actually DOES something. It does not take too much of a stretch of the imagine to ponder how to replace those injects with status info from, say an input or an MQTT input etc..

Here’s what my new page looks like…

new page

The process commands box looks like this..


As you can see – I’m merely taking the input message – and parsing it – and I’m only interested in “my_switch”… I return in this case a message to turn my ESP8266-board relay output on or off.

Here is the code for the page – don’t forget to set the WS to your Node-Red websocket and don’t forget the theme data…

[github file="/scargill/various/blob/master/blog2.html"]

Note a link to a second page – as yet doing nothing but basically you can build a multi-page app all in one html file… check out Jquery Mobile site – or click the link in the page.


Web Sockets Web Page Part 2

For this to make sense, you really should read the original websockets item first (which has just been updated)– as this is a follow up.

So now, having made my first web sockets web page I started to wonder about the mechanics of getting information out of the page – and into it. That is – how could I make that slider move programmatically – could I simply send information into the web socket and have it change the page dynamically?

Well… yes. Here’s the modified test in Node Red…


So we have our two web socket nodes – input attached to output… anything coming in from the page would go back out. But could I inject changes?  As it happens the information I have going through is a simple block of JSON of the form:

{“my_input”:””, “my_slider”,””,”my_switch”,””}

That is, the input field and by one now slider and one flick switch on the page. Oh and an image just to test that too. So here is the page…

web page test

Just a little more ambitious than the first one (which is why you should look at the earlier blog first)…

So I have my WS in and out – and when a change occurs on the page – that JSON block will pass into “ws in” and out through “ws out”  - so it is entirely reasonable to experiment with injecting that info into the middle… see my 2 grey inject nodes which pass the following information..

The first “Inject ON” passes a string {"my_input":"Hello","my_slider":"40","my_switch":"on"}

The second “Inject OFF” passes {"my_input":"Goodbye","my_slider":"60","my_switch":"off"}

Here is the page itself – only marginally more complex than before..  and in addition I have a couple of images called light0.png and light1.png stored in an icons directory just below where this page is stored i.e. (var/www/app/index.html)

[github file="/scargill/various/blob/master/blog1.html"]

The main page is in the bottom half – you’ll see my_input, my_slider and my_switch – the latter made possible thanks to the inclusion of JQuery mobile. If you can run this – you’ll see that moving the slider or entering text into the text box has no effect until you press update, whereas clicking the switch has an immediate effect. Note that as the switch changes state, the image (which does not appear at first as I’ve not put a default in there – trivial) changes as well.  Once you’re happy playing with that – try pressing the two injector buttons in Node-Red – the page will instantly update itself. Look at the DEBUG window in Node-Red when doing any of this and you’ll  see the simple JQuery string being passed around.

And that should be enough to start someone who like me, until a couple of days ago had never played with web sockets, thinking about what kind of wonderful control pages they could make. If you make this available externally via your router – do put in some security – and that’s another matter.

MEANWHILE I’ve been having a look at Martin Harizanov’s stand-alone 3 relay ESP8266 board, taking advice from Espressif as to a small modification to their development board, finally getting my head around an external drive for the Raspberry Pi and more – but that will wait for another time.

And now Websockets Web Page Part 3


A Node-Red Websockets Web Page

Updated 26/04/2015

I’ve been after this ever since I discovered Node-Red.. and right up until this yesterday I was tearing my hair out – having settled for NETIO as my interface of choice and constantly being annoyed by the slow pace of progress with this interface.

So what is this all about? At the end of this, if you don’t know how already, you should be able to put together your own mobile friendly web page which will talk to Node-Red and from there to and from whatever other gadgets you wish.

So what is involved?

Well, you need Node-Red to listen to incoming websocket requests and to be able to respond… that and a web-browser for now is ALL you need. You do NOT need (though you could use) the whole web server structure).  In my case, Node-Red on a Raspberry Pi – that’s it.  The PURPOSE for me at least is to control stuff by MQTT but I’ll not cover that here as I’ve talked about it elsewhere and that too can be handled with ease in Node-Red.

So in my case this is running on my Raspberry Pi locally but it doesn’t have to be – that’s just what I’m using for testing. What you see here above are three standard node-red nodes.. a websocket input – a function (DIY info) node and a websocket output.

Aside from giving them meaningful (or otherwise) names the only thing you need on the websocket bits is the URL. Any URL within reason staring with /.  I used /myapp but something more meaningful would be better. This is NOT the address of your web page – this is the address of the websocket connection. Read on.

Simple WSWhen you hover over the Websocket input  in Node-Red editor,  there’s a mention in the INFO box about killing msg._session in the flow. That meant nothing to me until one of my readers set me straight.. but it’s very simple in the example above, any information coming in from say a browser will be sent back out (second block market “ws out” to th same browser.

That’s it. Anything coming in to the websocket input node goes out of the websocket output node to the same browser but not another browser looking at the same page.

node-red websocketsThis version however with the function in the middle with nothing more than…

return msg;

The information above kills the session info needed to lock down a given session so that in this scenario one browser may send a button press causing an action – and that will also be sent to any other browser looking in… as you can imagine a one-to-one chat window becomes… trivial.

So all we need now is a web page that will connect to this websocket  - one which can send information to Node Red and also receive information.

I wanted a simple test web page to have a field that I could fill in – and a submit button that would send information to the websocket without all that refresh stuff and which would return the information to the page. Clearly one can to things with that info as it passes through the middle orange function block if present (passed in msg.payload).

It is very convenient to have everything in Node-Red and it is perfectly sensible to have it serve up the web page AS WELL as handling web sockets….

node red sockets and web page

Note the addition of the bottom three boxes (see above, “kill session is not necessary unless you want to broadcast any changes to all browsers looking in – but you may want to use that block for something else – like handling traffic passing through from the web page and back to it).

For the web page itself, these are http, template and http response blocks respectively. The left most simply needs a URL – I’ve called it /testing  and a useful name - the rightmost needs nothing but a useful name.. the middle block contains a bog-standard webpage of your design – and within that the websocket connection.

Pretty basic but that’s the idea. No need to even construct a web page – the html and js can all sit in the block marked “html+js”.

My internal address is, unlike a normal web page, the pages you serve in here are on port 1880 by default so the internal address for this page would be


But herein lies the rub.. what if you want folders (css, images etc) – where would you put them?   I chose instead as I already had Apache web server running on the Pi to put my PAGE there instead. There is also the point that basic page security is easy to implement on Apache.

So – there are examples out there of a simple web page, there are other examples of mobile web pages – and even more of simplifying normal Javascript using JQuery (which is wonderful) and I guess all I’ve done here is merge all of this into a useable if trivial page for the purposes of demonstration. I could have complicated things by requiring loads of libraries, filling it up with images etc but I wanted to keep is simple and as you have to be online for this to work I figured I’d simply link to the popular CDNs.

So – I wanted a responsive design that would work well on the mobile phone and look nice, be expandable with ease – and that comes from the combination of JQuery and  JQuery mobile. In total we’re looking at no more than 4 lines of includes at the top of the web page to achieve all that.

As the web page and socket are on the same machine that simplifies the address link for the websocket – and so what you see in the code generates this page on first use. You are seeing this screenshot from a Google web browser but the phone image looks pretty similar without all that Google guff at the top.

web page[4]

Remember this is just for demonstration but I think you’ll agree it is quite clean. So what you’re looking at is default information in a web page. The page is connected to the websocket – just just does that – and it reconnects if you stop the socket for any reason and restart it. IT has a field that says “!empty!” – nothing special – just default text. .. and 0 – again just default text.  Notice the input box, the slider and the button.  I’ll put something in the input box and move the slider – which is just a test pretending I’m injecting temperature info. I decided for the purpose of this test to keep the traffic down and have the slider not return anything until you hi the button.

Test page view 2

and when I hit the Update button –

test page image 3

As you can see the info I sent out has gone through the websocket connection (and hence you can do something with it…. I made the individual form items into a JSON string (simple – see the code) and sent it off – it came back in – I used JSON.parse function to split them apart and JQUERY to dump the values back into the page.

There are of course a million ways to do this – mine is just one – but it looks nice and is very responsive. My thanks to the various bits of code, to the people who wrote the JQUERY libraries and the help I’ve had from the Node-Red guys for helping me get this far.

At this point of course, expansion is so easy… the code can be tested in an html visual editor – or just a local web page and NotePad++ and developed ad-infinitum. For sliders, buttons and a whole lot more – take a look at jQuery Mobile – the flip-switches look good too.

Colours? Try the jQuery Mobile theme site



I’ve not quite figured out how to add the colours in given that everything is running in a box…. but that’ll come soon enough.

Here is the code. By the time you read this it will likely have morphed into something altogether more elaborate so I figured I’d put it in here before I get carried away. I’ve deliberately expanded the vertical spacing to chop this into blocks for you. Go through it slowly – it really isn’t that hard. The links below show the latest JQuery Google CDNs but if you don’t like Google there are many others.


<title>Simple Display</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>

<script type="text/javascript">

var server = window.location.hostname;
var topics = {};
var wsUriC = "ws://"+server+":1880/myapp";
var ws;
function wsConnectC() {
ws = new WebSocket(wsUriC);
ws.onmessage = function(msg) {
var line = "";
var fromPage=JSON.parse(;
if (fromPage.part1!="") $("#part1").html(fromPage.part1); else $("#part1").html("!Empty!");
ws.onopen = function() {
ws.onclose = function() {
$("#status").html("not connected");
function sendMessage(){
// send message back to page in simple JSON format
// example {“part1”:”Hello”,”part2”:”50”}
var toPage='{"part1":"'+$("#txtMsg_1").val()+'","part2":"'+$("#slider_1").val()+'","part3":"3"}';
} // end sendMessage


<body onload="wsConnectC();" onunload="ws.disconnect;">
<div data-role="page" id="one">
<div data-role="header">
<h1>Websockets Test Page</h1>
<div role="main" class="ui-content">
<h1>Temperature Display</h1>
<div id="status">status unknown</div>
<input id="txtMsg_1" />
<div id="part1">!Empty!</div>
<div id="part2">0</div>
<label for="slider_1">Input slider:</label>
<input type="range" id="slider_1" value="60" min="0" max="100"  />
<input type="button" value="Update" onClick="sendMessage()" />


See next blog item– Websockets Web Page part 2


A guide to reviews

I’ve had a number of requests to do reviews on the blog recently… so if anyone is looking in with this in mind, please note I’m only happy to review items that are of interest to the readers here. A quick look around the blog should give you an idea of the kind of things my readers and I are into.  Much of the time we’re getting 1000 visitors a day here and I’d like to keep it that way with items they might find of use.



The Saturday Catch

While working on my Raspberry Pi image (with everything I need stored in an image so it it all goes to hell I can recover everything) I realised something I was missing on the Pi was a package manager. A graphical APT-GET for those who are not too keen on command lines. Well I came across this link.

Suffice it to say this is a not-too-exciting but graphical package manager – but the real catch for me as an unwilling-Linux-newbie was this…   I use Geany editor and half of the time I need root privileges because the default settings won’t let me save some files I’ve edited. I usually end up using SUDO GEANY at the terminal just to bring it up in the right mode.

Well, not any more. Half way down the link above are instructions for changing menu items such as Geany and in fact this package manager – to run as root (i.e. the highest level of privilege).

The only difference I made was this.. So for Geany

Find /usr/share/applications/geany.desktop (I’m guessing this applies to anything else)

and near the end you may find in the text of that file Exec=geany or similar. Well, just prefix it with sudo and save… Job done.


So now I have a graphical package manager, a remote graphical admin tool (webmin) – SCP for accessing files from the PC and UltraVNC to run the graphical environment remotely (sadly, when working with TightVNC it has problems with copy and paste to and from the PC – if anyone knows how to fix that do let me know)