SteelSeries and Node-Red

tmp768EYou should read the previous blog entry before this one – as the principles are the same as are some of the details such as the location of your /myjs folder for Node-Red – so read the other article first. This guage IMHO is the best yet!

To run the example on the right here you should get the SteelSeries library. 2 minified JS files is all you need.

See flow below… you will need the following incoming variables – all done for you in the example but of course you’ll want to customise…

msg.value   // the value of the pointer – in this case 0-100

msg.threshold // the value of the red threshold indicator

msg.userLed  // if true the green user LED will be flashing. You can turn this off if you don’t need it. I’ll use it to indicate a dehumidifier is running.

If the value is less than the threshold, the red LED will flash. This can be inverted in the code. If msg.userLed is true the green LED will be flashing.

I’ve ALSO added as you can see separate ODOMETER (msg.odo - you could have LCD instead) and a trending UP/DOWN/STEADY/OFF  indicator and demo controls – discovering what is available on this gauge is half the battle!!

Everything is configurable, I’ve brought out what I think is useful – the rest is buried in steelseries.js which comes with the package – there is no documentation as such. All you need to store in your myjs library is steelseries-min.js and tween-min.js – but is it worth it? SURE IS  - this is a wonderful device… I can’t wait to get one on a nice large display on the wall.

I’m thinking general use to show temperature, odometer could show humidity, green user LED for dehumidifier on, RED light for heating on and the trending indicator to show maybe whether the heat is on the way up or down – though that much should be obvious from whether the heating is on or not… maybe a use I’ve not thought of yet. Or not – you can turn it off if you want. Wonderful.

flow

Prerequisites: Far too often in blogs like this we “assume” that everyone is keeping up – if not – may I suggest a quick look at this page I put up specifically to give a little background – which might help explain this article.

Looking for help: If anyone knows how to get rid of that chrome frame - DO let me know. frameVisible=false makes it hide but does not expand the gauge to fill in the space -in other words you are still left with an invisible frame - the only article I can find suggests this should not be the case - but it is. Given a small 3*3 frame size I'm after all the resolution I can get).

Here is my code for the example above (also available here):

[{"id":"8d862a4b.c1d588","type":"ui_template","z":"c552e8d2.712b48","group":"1e03a2b2.83a61d","name":"rgraph","order":1,"width":"6","height":"6","format":"<script src=\"/myjs/tween-min.js\"></script>\n<script src=\"/myjs/steelseries-min.js\"></script>\n<script>\nvar radial4;\n    (function(scope){ \n        scope.$watch('msg', function(msg) {\n           if (typeof(msg.value) != \"undefined\") radial4.setValueAnimated(msg.value);\n           if (typeof(msg.threshold) != \"undefined\") radial4.setThreshold(msg.threshold);\n           if (typeof(msg.odo) != \"undefined\")radial4.setOdoValue(msg.odo);  \n           if (typeof(msg.userLed) != \"undefined\") radial4.setUserLedOnOff(msg.userLed);  \n           if (typeof(msg.trend) != \"undefined\")\n            {\n                if (msg.trend==1)     radial4.setTrend(steelseries.TrendState.UP);\n                if (msg.trend==0)     radial4.setTrend(steelseries.TrendState.STEADY);\n                if (msg.trend==-1)    radial4.setTrend(steelseries.TrendState.DOWN);\n                if (msg.trend==-2)    radial4.setTrend(steelseries.TrendState.OFF);\n            }\n        });\n    })(scope);\n\n    var sections = [steelseries.Section(0, 25, 'rgba(0, 0, 220, 0.3)'),\n                        steelseries.Section(25, 50, 'rgba(0, 220, 0, 0.3)'),\n                        steelseries.Section(50, 75, 'rgba(220, 220, 0, 0.3)') ],\n\n            // Define one area\n    areas = [steelseries.Section(75, 100, 'rgba(220, 0, 0, 0.3)')],\n\n    radial4 = new steelseries.Radial('canvasRadial4', {\n            gaugeType: steelseries.GaugeType.TYPE4,\n            size: 292,\n            section: sections,\n            area: areas,\n            titleString: \"Heating\",\n            unitString: \"Degrees C\",\n            threshold: 50,\n            thresholdRising: false,\n            userLedVisible: true,\n            useOdometer: true,\n            lcdVisible: true,\n            trendVisible: true\n        });\n                        \n    radial4.setFrameDesign(steelseries.FrameDesign.BLACK_METAL);\n    radial4.setValueAnimated(0);\n    radial4.setThreshold(50);\n    radial4.blinkUserLed(0);\n    radial4.setOdoValue(0);\n\n\n</script>\n\n<canvas id=\"canvasRadial4\" width=\"401\" height=\"401\"></canvas>\n","storeOutMessages":true,"fwdInMessages":false,"x":490,"y":920,"wires":[[]]},{"id":"94d08897.6b6f78","type":"inject","z":"c552e8d2.712b48","name":"Set needle to 88","topic":"","payload":"88","payloadType":"num","repeat":"","crontab":"","once":false,"x":140,"y":700,"wires":[["a72af19d.e17e2"]]},{"id":"f5301eaa.f021d","type":"inject","z":"c552e8d2.712b48","name":"Set needle to 33","topic":"","payload":"33","payloadType":"num","repeat":"","crontab":"","once":false,"x":140,"y":740,"wires":[["a72af19d.e17e2"]]},{"id":"a72af19d.e17e2","type":"function","z":"c552e8d2.712b48","name":"","func":"msg.value=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":720,"wires":[["8d862a4b.c1d588"]]},{"id":"cb9d2598.de4918","type":"inject","z":"c552e8d2.712b48","name":"Set threshhold to 60","topic":"","payload":"60","payloadType":"num","repeat":"","crontab":"","once":false,"x":150,"y":780,"wires":[["d1f505b0.62c9f8"]]},{"id":"b50f3ae1.7cbdd8","type":"inject","z":"c552e8d2.712b48","name":"Set threshold to 30","topic":"","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"x":150,"y":820,"wires":[["d1f505b0.62c9f8"]]},{"id":"d1f505b0.62c9f8","type":"function","z":"c552e8d2.712b48","name":"","func":"msg.threshold=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":800,"wires":[["8d862a4b.c1d588"]]},{"id":"cd9b1fe2.9c989","type":"inject","z":"c552e8d2.712b48","name":"Set user LED ON","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"x":140,"y":861,"wires":[["199bc0e7.607eff"]]},{"id":"59205954.a730c8","type":"inject","z":"c552e8d2.712b48","name":"Setuser LED OFF","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"x":150,"y":901,"wires":[["199bc0e7.607eff"]]},{"id":"199bc0e7.607eff","type":"function","z":"c552e8d2.712b48","name":"","func":"msg.userLed=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":881,"wires":[["8d862a4b.c1d588"]]},{"id":"f13cc85.7df0038","type":"comment","z":"c552e8d2.712b48","name":"Example use of Steelseries Gauge","info":"","x":180,"y":660,"wires":[]},{"id":"ffa9ff04.4fc7f","type":"inject","z":"c552e8d2.712b48","name":"Trend UP","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":120,"y":940,"wires":[["2320de53.8b2e42"]]},{"id":"3c6f1b6f.e42924","type":"inject","z":"c552e8d2.712b48","name":"Steady","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":980,"wires":[["2320de53.8b2e42"]]},{"id":"2320de53.8b2e42","type":"function","z":"c552e8d2.712b48","name":"","func":"msg.trend=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":960,"wires":[["8d862a4b.c1d588"]]},{"id":"e0daa005.96fd5","type":"inject","z":"c552e8d2.712b48","name":"Down","topic":"","payload":"-1","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":1020,"wires":[["2320de53.8b2e42"]]},{"id":"893a4668.be5a78","type":"inject","z":"c552e8d2.712b48","name":"Off","topic":"","payload":"-2","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":1060,"wires":[["2320de53.8b2e42"]]},{"id":"a222fdf0.4934d","type":"inject","z":"c552e8d2.712b48","name":"ODO 50","topic":"","payload":"50","payloadType":"num","repeat":"","crontab":"","once":false,"x":120,"y":1100,"wires":[["f7bee9bf.d05478"]]},{"id":"7a3e24c1.17e7dc","type":"inject","z":"c552e8d2.712b48","name":"ODO 78.6","topic":"","payload":"78.6","payloadType":"num","repeat":"","crontab":"","once":false,"x":120,"y":1140,"wires":[["f7bee9bf.d05478"]]},{"id":"f7bee9bf.d05478","type":"function","z":"c552e8d2.712b48","name":"","func":"msg.odo=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":1120,"wires":[["8d862a4b.c1d588"]]},{"id":"1e03a2b2.83a61d","type":"ui_group","z":"","name":"testy","tab":"f9bab960.c839b8","disp":true,"width":"6"},{"id":"f9bab960.c839b8","type":"ui_tab","z":"","name":"testy","icon":"dashboard"}]
Facebooktwittergoogle_pluspinterestlinkedin

RGraph with Node-Red

RGraph GaugeHaving gone from spending countless hours staring at HTML5 CANVAS, I’m now at the “meh” stage as it starts to dawn on my how it works.

And so it was that I stumbled on RGraph – or put another way, Christmas for widget-lovers.

If you’ve been following these blog entries you’ll know that Node-Red has TEMPLATES in the UI – and that you can put your own stuff into the templates and that recently the fog has lifted on getting variables in and out of the templates.

In recent blogs I’ve been constantly improving a thermostat control page and that took me off looking for a gauge with two pointers – one to show temperature, the other to show humidity.

And that’s when I stumbled upon RGraph. If you read this – and understand it – you will open the doors to a boatload of gauges, thermometers, charts and graphs so tuck in:

First things first, if you’ve already played with Node-Red in here you will likely have made a /myjs folder (home/pi/.node-red/public/myjs or similar – defined in your Node-Red settings.js file) to put various Javascript files in. Well, add this lot in a sub-folder called RGraph – you can call it freddy if you like but I thought it reasonable to use the name the way they use it. I grabbed the latest stable version from here. Inside there is a folder called RGraph – and inside that is a folder called libraries – I grabbed the contents of that folder and put it inside my /public/RGraph folder. It may be there is a use for other stuff in there – but for now that’s all I’ve taken.

So – then I dropped in a template – made it 6*6 and inside that template I put this lot – code shown below.

Now, if you don’t like my colours – change them. You can change just about anything including the size but you may need to adjust the font size if you do that. Experiment!

To change the two pointers – which I’ve chosen to call temperature and humidity – you might use them for petrol and oil – or whatever….I simply pass MSG as is common in Node-Red – but not msg.template – instead msg.temperature and msg.humidity – you can call them whatever you like.

The point of this is not to demonstrate my crap taste in colours – once you follow what I’ve done here – that entire, massive library of CANVAS-related gauges and charts is yours for the taking!  You can make the gauges interactive – but as I had two, not one pointers in this example, I skipped that. Details are in the extensive RGraph documentation.  Copy me and drop them an encouraging lines to say MORE IOT PLEASE!!

Oh and if you don’t like animation – where I say “grow” say “draw”.

(As an aside, I got this working today as well - https://www.codeproject.com/Articles/304874/HTML-Canvas-Aqua-Gauge)  very pretty but doesn’t scale well.

Prerequisites: Far too often in blogs like this we “assume” that everyone is keeping up – if not – may I suggest a quick look at this page I put up specifically to give a little background – which might help explain this article.

<script src="/myjs/RGraph/RGraph.common.core.js" ></script>
<script src="/myjs/RGraph/RGraph.gauge.js" ></script>

<script language="javascript" type="text/javascript">

           (function(scope){ 
                scope.$watch('msg', function(msg) {
                   gauge3.value=[msg.temperature,msg.humidity];
                   gauge3.grow();
                });
            })(scope);
            
            var gauge3 = new RGraph.Gauge({
                id: 'cvs',
                min: 0,
                max: 100,
                value: [23,60],
                options: {
                    titleTop: 'Temperature',
                    titleTopSize: '16',
                    titleTopFont: 'Impact',
                    titleTopColor: '#ff8888',
                    titleTopPos: 0.25,
                    titleBottom: 'Humidity',
                    titleBottomSize: '14',
                    titleBottomFont: 'Impact',
                    titleBottomColor: '#8888ff',
                    titleBottomPos: 0.3,
                    backgroundColor: 'black',
                    backgroundGradient: true,
                    centerpinColor: '#666',
                    needleSize: [null, 50],
                    needleColors: ['Gradient(transparent:yellow:orange:#ff8888:#ff8888)', 
                                    'Gradient(transparent:cyan:green:blue:blue)'],
                    textColor: 'white',
                    tickmarksBigColor: 'white',
                    tickmarksMediumColor: 'white',
                    tickmarksSmallColor: 'white',
                    borderWidth: 1,
                    borderOuter: '#666',
                    borderInner: '#3333',
                    colorsRanges: [
                                    [0,10,'rgba(0,0,255,0.6)'], 
                                    [10,20,'rgba(0,128,255,0.6)'], 
                                    [20,30,'rgba(0,255,255,0.6)'], 
                                    [30,40,'rgba(0,255,128,0.6)'], 
                                    [40,50,'rgba(0,255,0,0.6)'], 
                                    [50,60,'rgba(128,255,0,0.6)'], 
                                    [60,70,'rgba(255,255,0,0.6)'], 
                                    [70,80,'rgba(255,128,0,0.6)'],                                                                                                                                                 
                                    [80,90,'rgba(255,64,0,0.6)'],   
                                    [90,100,'rgba(255,0,0,1']
                                  ],
                    textAccessible: true
                }
            });
            gauge3.grow();

    </script>

    <canvas id="cvs" width="300" height="300">[No canvas support]</canvas>
 
Facebooktwittergoogle_pluspinterestlinkedin

A Thermostat Weekend

tmp3C7AAs I make changes and I don’t want to bore readers – I’m adding sections at the top of this article and moving earlier versions of the stat down the page. If you are new to this you might want to start at the bottom at the point in this blog entry marked “The Old Ways”.

The Newer Ways: You will read below about last weekend’s work on the thermostat control – here is the link to the current code which now also handles a de-humidifier (not on a timed basis) and a heating using indicators built into the gauge (my thanks to the author for his help). The image on the left depicts the latest version.

Mobile Thermostat panel by Peter ScargillThe New Ways: This is about a DIY Thermostat in Node-Red – if you want to read about how I got to this point, start at “The Old Ways” then come back up here. If not, read on. Here's a short video. So – you want a thermostat using Node-Red Dashboard (remember you can set all of that up on a variety of hardware alternatives using the script – which turns your little SBC into a potentially powerful central control system for IOT). Here it is.  You should be familiar with Node-Red, Node-Red dashboards and flows. If you need to know more about home control you could read all about it in the Home Control 2016 blog (quickly before I come up with a reason to change that to 2017). Lots of links in there to code for Esp8266s etc.

I’m assuming you have sensors and a relay board to control the heating and all you need is the pretty bit with glue in the middle, understand basic heating and are ready to go.

Here it is on the left – two days of solid graft. With this magic screen you can set up an entire week’s heating, controllable at hourly intervals – in a minute if that. Each hour can be poked with finger or mouse, adjusted and at the touch of a button replicated to the next hour. Similarly a whole day’s settings can be instantly replicated to the next day etc. You have control of the automatic temperature, with manual override as well as frost and stat settings and all on one colourful screen.

And if you don’t like it – it’s all there in source in Node-Red – what could be easier.  I must’ve made a dozen variations as you’ll see in “The Old Ways” before coming to this – what’s really exciting is that some of the control and display elements of Node-Red Dashboard are getting easier as I go along – at first I seemed to get no-where, now, the sky seems like the limit.

So – each of those coloured elements represents one of the 24 hours of the day – simply select by touch (the black bar will light up purple) an move left or right using the bottom arrows. The COPY button next to it will replicate an hour in the next one if you have selected an hour – or will copy a whole day if you’ve selected DAY. You can select frost and away settings and adjust temperatures there. On the top of the display is your actual temperature – and settings to adjust the SET temperature – and away from hours (>) to days (>>).  A is for automatic! When you have the settings the way you want them – use the disk icon to save or use the cancel icon to revert back to what you had before you started. That’s it – nothing else.  The data (a very small amount) is stored in your /home/pi directory but of course you can change that.

And here’s the flow you’ll be looking at – complete with lots of test buttons.

flow for the thermostat

This is slightly different to the code I’ve put up as I’m now monitoring actual temperature (the purple MQTT node top right – in the demo code I have kept the demo buttons).

The left side is entirely test material, storing values from your temperature and humidity sensors (the latter is not used as I ran out of room to display – maybe this week I’ll re-think the sizes slightly. I’m also pondering expanding the hour-day idea to hour-day-zone as I have two heating systems here but that will be later and I’ll leave this code intact).

Note: You’ll see some icons here – I’ve not distributed then as I’m not 100% sure of their copyright status – if you look around and look at an earlier blog talking about icons and .png files – there are no shortages of decent transparent .png icons for you to use – there are also a bunch of them built into Angular.

Temperature display from the new thermostatAll seems to work – in Chrome on the PC and on my HTC phone the displays are identical. Now – if anyone would care to ponder improvements – maybe find enough room in that right corner to get some more info…. do write in with ideas and code.

HOLD THE PHONE: I think I’m in love… check this beauty out on the right – found it HERE and modified the colours, text and size – a true work of art - quick modification in a browser and I changed parameters to make it do temperature (originally speed) change colour – etc…  I have it working in a simple local web page but sadly when I put it in a template right now – I get a white screen… I’m at a bit of a loss as to why.. if anyone wants to step in here….. it is so lovely it would be a shame to miss.

And finally: The original gauge here had a grey display with decimal points. I needed to get rid of those as I’m dealing in integers. I contacted the author Mykhailo Stadnyk

http://tech.scargill.net/yourls/gauges

At the end of that – two new parameters – valueInt:2 and valueDec:0 gave me what I wanted – a simple integer degrees printout.

If you are using my flows – and creating directories etc, always remember that Linux and Javascript are case-sensitive – don’t go making directories/files  in upper-case and addressing them in lower-case.

Oh – LEDS -  I just found this – lovely CSS LEDs  - I need to figure out how to add one into the canvas.. I’ve also asked hr writer of that gauge if he’d consider adding in an optional LED indicator for me (boiler active).

The Old Ways: Here is where this all started.

As it happens, a few days ago, reader Antonio pointed me to a little ESP8266 Thermostat – well, some code for it anyway, using one of those little 120*180 displays.

ESP8266 stat gave me ideasI’m not that partial to Arduino development but I grabbed the code and stuck it on my hardware. Some great ideas there – but the implementation using a rotary encoder left something to be desired – and the code doesn’t support MQTT – and minus temperatures messed the display up. Oh and it seems to be partly in Italian and partly in English. Oh and a good but not especially long-lasting sensor is sitting right next to warm electronics and a warm display.

Don’t get me wrong, a STERLING effort and no doubt it will go on to be very good – but it wasn’t quite what I was looking for. It certainly fired me up.

As you all by now know I’m an MQTT/Node-Red/Mobile phone kind of guy and so armed with my new knowledge of Node-Red Desktop I sat down with coffee on Friday morning and started to put together some new thermostat code (as if I needed more). One of the things I really liked about the ESP code was the timing page you see above. I have 5 time zones per day which can be any temperature – different at the weekend – but not without it’s issues – what if the weekend is not your “special” time for example – and it needs lots of controls.

This on the other hand was simple. I got to thinking – but if it was on a touch screen you would not have all that selecting nonsense and what about replicating settings for every day and….

And so it was that I sat down with a gallon of coffee and did what I always do – plough in with the code long before I’ve put a plan together. Sometimes it works, sometimes it doesn’t. Hey, I’m a one-man team!

Templates on Node-Red: Well, this time it did and I’m chuffed, but before getting into this – a quick lesson on using TEMPLATES in Node-Red Desktop.

Templates are easy – pretty much you can make a web page in a template – you can even have includes and JQuery comes with the deal.  The problem I’ve always had in the past is getting stuff in and out of the template – the examples given really don’t help and I spent HOURS trying to get to grips with this.

Scargill's very first Node-Red thermostatWhen we were messing with buttons (see other blog entries) I got a lot of help from folk, most of it I understood, getting variables into the Template I most definitely did not – but it worked and now the light is coming on.  Remember the good old days of ASP programming and other server-side interpreted coding – you had this code on the server which was NOT in the same space as the code in the web page. Well, this is similar.

The likes of msg.payload sits in Node-red along with global variables, context variables  etc. They do NOT reside in run-time Javascript on the web page and that had me going in circles for ages. Well, there is a way around it, digging through the code we ended up with for the buttons I extracted this and modified it a little…

(function(scope){
scope.$watch('msg', function(msg) {
// do stuff in here with msg… which includes any part of msg, even arrays etc.
});
})(scope);

So here we are on the web page – in a script tag – and we drop this in. I know – what the HELL is scope (yes I know what variable scope is). I can’t tell you in detail but I can tell you it works perfectly!  As soon as you inject the normal Node-Red msg (entire) object into the template – where that // comment is above, you can use the lot inside that function, calling javascript functions etc. Note that in typical examples elsewhere – inside that function you’d see the word data – and I’d previously then used “data.payload” etc. – however, keeping the name the same (msg) makes it easier.

Along with the ability to fire out information back to Node-Red with this and similar for buttons..

ng-click="send({payload: 'hello world'})"

The first attempt: With that realisation I started on my new little thermostat. The most COMPLICATED page is that of settings – and the project above that I really liked - got me started as gives you 24 settings every day of the week. FANTASTIC – but I had to make it easy. Now, it is REALLY easy. You can set up programs for the entire week in a minute.

Over on the right – you see my FIRST interpretation of this – yes, it works – I just don’t have a relay fastened up yet to DO something.

Ok –  the colours were not that subtle – don’t be awkward – I only started on Friday morning after a fear-filled, anaesthetic-devoid double-crown fitting at the dentists via a 90+ mile round trip. – yes, I was brave though it nearly reduced me to tears – so bear that in mind before criticising my colour taste  - I’ve change it as you’ll see later. The buttons are simply Angular buttons with png images inserted.

So – you can touch/click on any of the timings – or temperature, or day and using the up and down buttons (they’ll end up as left and right arrows) you can change the temperature from one of the presets for that time or the time slot you are playing with or the day. The black line under the relevant item will turn purple (for now).

Scargill's very first Node-Red thermostat flow

If you want to replicate the setting on subsequent hours, press/touch the copy button as often as you need (auto-increment). If you want to replicate the LOT, click on the DAY and then on the copy button and you’ll start whizzing through the days (auto-increment), coping the entire 24-hour schedule across – you can then tweak bits later. When you are happy you’ve not messed anything up – press the save button.

Now this lot is simply stored in an array – 24*7 bytes plus 4 bytes for the temperatures – so as an array, stored on SD it takes up almost no room – by using a 2-level array you could EASILY expand this into different ZONEs – so as well as a DAY field you’d have a ZONE field and a copy operation would copy the whole lot to the next zone –  etc. Seriously this is a DODDLE to set up.

Finally a cancel button…which simply restores the array from SD – that function is also called at power up to get the values in the first place. I could probably do with a timeout on saving to avoid the (admittedly small) write to SD on every change. Still – not something you’d do a lot of.

So now we have a non-volatile global array with all the info in (I jammed the temperature settings on to the end of the array) – a separate page will show the temperature with a nice pretty dial, let you change manually up and down that for a given time – what, 4 hours before reverting to auto? and of course you’d want to show the humidity and pressure – very important they are all super accurate so I’m thinking a single BME280 would do the lot for you!!!

And that’s it – the output of “process heat” is simply the required heat value, sent out every minute. I picked a minute – could be 5 minutes – if you are working with, say, an oil boiler you really don’t want to be changing things rapidly. You can use this value to display in another page as the “set” temperature and to compare with the REAL temperature to decide what to do with, say, a relay.  Options might include a manual override – which should time out after a couple of hours maybe – and maybe a longer-term override in case you want shopping or are away for a couple of days in which case you might want to go to the lowest setting (offset zero in the global array) for some period. Normally for manual override you’d simply ADD your override figure to the automatic figure – i.e. 2 degrees WARMER or COOLER. My next job will be to do a nice job of the main stat display page.

The main page will no doubt also feature the local weather forecast – again from a previous article. One could even add a complete week’s predictions with icons.

More on this in near future – here is the current FLOW for this (no support and it WILL change in time) so you can just drop it in into Node-Red. Aren’t you glad you adopted the latter!

Scargill's very first Node-Red thermostatAuto-learning

To do auto-learning I think I’d change this – instead of 4 fixed temperatures I’d allow arbitrary temperature between, say 14c and 26c for every time slot (could do that now)…

Now, given THAT you could maintain a separate array – and every time someone makes a manual change – this would added to the second array (initially zero in all values).

After, say 4 weeks, you could divide the array down by, say, 4 (so that X degrees updated on the same hour for all 4 weeks would show up as one change) – and merely ADD that to the main array – clearing the second array. That way the system would have learned from the last 4 weeks changes but be ready to adapt to another 4 weeks changes etc. That’s one way – without getting too silly about it can you think of a more USEFUL way of adapting?

Thermostat – The Return of the Stat: Well, it had to happen – once I started writing about this – I started thinking how DAFT that 4-temperature limit is – and so  - well, I changed it a bit…   a lot, actually.

The panels now gives full control for every hour of the week but because of the copy system, it still takes only a moment to set the entire week up and it did occur to me that it would be a doddle to extend this to a ZONE system with umpteen zones, even.

I’ve also spent ages working on colours so as you can see – as you adjust the temperatures, the colour changes per degree and it’s quite pretty.  And there is status help.

I’ve added in frost and away settings as you’ll need those for the front panel controls (up, down, set away, set frost).

I have to say, it looks beautiful on my screen. I’ve stripped out a lot of  CSS and put classes in to make the code at least partly readable. There’s a timeout on all the message that appear when you press buttons – should be 5 seconds but right now they vary a little – any Javascript experts - feel free to take a look at the function – but it all works well enough.

Here’s the second flow – this supersedes my first attempt.  Oh you’ll need to find some images – and change links accordingly. On my Pi2 I have a directory /home/pi/.node-red/public/myicons with a ton of folders in there with png images in them – well you have to make use of all that space.  You’ll need to find your own – there are many out there – make sure they are transparent. But then – if you’re working with Node-Red and Dashboard, it really is worth setting yourself up with a good selection of icons and images anyway.

Oh – the data… in “Process controls” you’ll see that we’re looking at an array of 168 bytes plus 2 bytes to store frost and away temperatures – that’s it. See later articles as this has all been improved.

Facebooktwittergoogle_pluspinterestlinkedin

The Pine 64

Pine 64Just a quicky this morning as I’m busy working on a LED for the thermostat control (thanks to some help from the author – I’m quite excited)  as well as bench-testing some NanoPi 64 and M3 units.

So what you see here is the Pine 64 – which, like the FriendlyArm NanoPi64 uses a quad-core 64-bit CPU. This particular board has 1GB RAM (max 2GB)and is missing the Bluetooth/WIFI module ( the pins on the right side).

I’m having trouble with this one – that is, seeing the point of it.  As the photo depicts it is BIG – chopped up you could easily fit three Orange Pi Zeros into the same space and at least 2 M3 boards (the ones behind).

So to be fair, it DOES have a beta (if you like using beta software) Android 7 available – I’ve installed it, it works but is not stunningly fast – no-where near as fast as a typical mobile phone for example) – and not too many board manufacturers can claim that (this release of Android won’t even start up on the NanoPi A64). So if a modern Android is your thing then, well, I guess you’ll find the board useful. There is also a WiringOP for it (GPIO) but I understand that is somewhat incomplete.

If Android is not your thing and you want to do some control stuff, I cannot think of any good reason to go for this rather than something like the much cheaper Orange Pi Zero or perhaps the M1 or M2.

Well, I said it would be a quicky. Oh and the chip gets hot – it needs a heatsink and there are no mounting holes around the processor to fit one.

So – the board with 1GB RAM is only $19 – that’s good right?  But then if you want the Bluetooth and WIFI that comes WITH several other boards, that’s another $10. Add shipping to the UK and you are now looking at $40. With the current atrocious conversion rate you could buy a Raspberry Pi 3 for that. Go for the 2GB version and you’ll looking at $50+

I’m thinking at the roughly $50 price range – perhaps the Odroid C2 wipes the floor with this? What do you think?

So – what did I miss? Why would one want one of these? Someone enlighten me… there have to be some plus points?

Right –back to fitting a LED to my thermometer gauge.

Facebooktwittergoogle_pluspinterestlinkedin

FriendlyArm NanoPi A64

NanoPi A64Don’t you love reviews that tell you all about a new product, print out all the specs then leave you to discover the horrors all on your own because they didn’t ACTUALLY test the thing? Well, this isn’t one of those reviews. But I will give you the spec. Even if this particular board doesn’t get your interest, you might learn some things just as I did in the process of doing the review.

What is it ? The FriendlyArm NanoPi A64 is as you might expect a 64 bit SBC. It looks lovely, has 4 serial ports (you can only really use two as one is for debug, the other for Bluetooth), Gigabit Ethernet, WIFI and more – here’s a list. OH and it is cheap at (in US dollars) $25 plus post.

Important specs:

  • Allwinner A64 quad-core Cortex A53
  • GPU Mali400MP2
  • 1GB DDR3 Ram
  • Gigabit Ethernet
  • WIFI + Audio + IR + USBx2
  • 5v @ 2A

So on the surface of it a fast 64 bit processor – what more could you want – and it is small. You can buy an optional heatsink with fan – but there are no special pins to attach the fan to, unlike other products by the same company. No matter, it does not get warm enough to need the fan in my experience.

I could give you a lot of other technical information which most people would not understand or have time to read – so instead I will cut straight to the point.

Operating Systems: If you check, operating systems for this includes Ubuntu Core and Ubuntu MATE.  No Debian, no Android… so to some extent that defeats the object of having the decent graphics chip as you’re less likely to use it as a media centre than if you had Android. Well, I am anyway. I was disappointed not to see Debian but then that’s me. So I started off trying out the full Ubuntu Mate.

The download took an age and I have pointed out to FriendlyArm that they should take a look at how they make their file available – 8 hours to download an image is not very funny.  This would not normally bother me as I tend to look first at the Armbian and DietPi sites – but they have nothing for this board. You might think that an operating system tailored for other A64 systems like the PINE would be good – but no – won’t even boot.

So Ubuntu Mate came up fine first time – and I set off running my script – which didn’t work – NPN would not install. It turns out that ONE reason for this was not as you might expect, lack of support for 64 bit systems (though that could be an issue) but the fact that this was Ubuntu 15.10 – which is ancient.

With help from Mr Shark we set about upgrading this to 16.04 Xenial. Well, that took nearly a DAY and was definitely NOT fun. At the end of it, we had 16.04 running – but the Ubuntu equivalent of the APP store was empty. I installed Chromium without it, clicked on the shortcut and… nothing – it simply would not run.

I tried my script and MOSTLY everything worked. A couple of tweaks and all was well, but I was not happy about the Chromium issue. If that was bust, what else was bust?  I put the SD to one side and downloaded the much smaller Ubuntu CORE.

After downloading software for these boards you must issue a couple of resizing options – I’ve already suggested to FriendlyArm that this should be part of their start-up script – you don’t have to mess with this with the Raspberry Pi and could put off beginners. Same again – 15.10 version – oh, dear. Anyway…

I started the resize operation…

sudo umount /dev/sdx?
sudo parted /dev/sdx unit % resizepart 2 100 unit MB print
sudo resize2fs -f /dev/sdx2

No sudo.  What!!?!?!?!

I went off and grabbed SUDO. I started again.

No parted.

I grabbed that, ran the instructions and resized the board.

This time the upgrade was no so successful with lots of errors appearing – now I KNOW there are Linux fanatics out there dying to say “but that’s part of the fun”.  No, it ISN’T part of the fun. Writing code is part of the fun, not messing with something that should have been sorted.  It would be like buying a car and the engine is broken and the salesmen says “well, repairs are all part of the journey”.

Determined not to be put off, I went back to the original SD and decided to remove the entire desktop environment as it was not needed anyway. Well, I can tell you that most of the information out there on doing this is SHITE. No matter how many commands I ran – and how many confirmations I got that Mate desktop was no longer there, when I rebooted, up came the graphical environment.  Eventually, with help from Anthony, I got rid of the lot.  I ran my script and – lovely – all working.

I came to back this up using WinDiskManager and “sorry – the image is bigger than the disk” – apparently not all 16GB disks are created equal.

The backup: Having put all this work into getting a board up and running I was not about to change it failing due to an SD issue. It was at this point that I had my first attempt to do a live backup – hey – what did I have to lose. I’ll cut a long story short here as I got the sector numbers wrong in the first place…

dd if=/dev/mmcblk0 of=/dev/sda bs=1M count=15000 status=progress

So dd is a very well known Linux program if you’re into Linux – I’d heard of it but that’s it – so this was my first attempt. I had to get the image backed up onto my SD that would work, without going out and buying a larger SD just to see most of it going to waste. Someday I will write a script to go through my installations and rename all the commands. How about “backup”. But I digress.

So – IF means input file, OF means output file, 1M is the buffer size – in short if you miss that of it takes longer – and status=progress is relatively new and lets you see a moving count while copying instead of wondering if it was working or dead.

This, of course, is highly discouraged by the community –  attempting a backup while the system is running is asking for the death penalty or worse and for good reason! As for the count – not only was it incorrect, it was a GUESS – I figured I needed to copy enough to cater for all working areas of the SD – but somewhat less than the actual size or I’d be no better of and the system would gripe about not enough room as does WinDiskManager.

For good measure I also added another command – just because I’d seen this used in the FriendlyArm literature after resizing a disk…. resize2fs /dev/sda2

Well, it was a bit of a long shot – I took out the original SD (mmcblk0) and put the new SD (which had been sitting in a USB holder and hence appeared as SDA  - and put the new SD in. Applied power and….

Success: Well, I was expecting nothing so as not to be disappointed – to my surprise – up came the prompt. I checked all of my programs and bingo – everything works.  I followed advice from Anthony who was being kept up to date and dumped an empty file called “forcefsck” into the outer directory (i.e. just created an empty file with Nano (the editor)). Rebooted – no error messages – job’s done!

WiFi: The NEXT step having satisfied myself that the board works and realising I could steal my M3 case as the sizes are the same, was to get WIFI working. After above I was not that confident. I read up about the command “nmcli”.  This stubbornly refused to work until I realised I was actually typing “nmclie” every time… at which point a quick scan of the networks immediately showed up my local WIFI access point. I stumbled on this item, detailing usage.

Even with one coffee and even though listing the WIFI was easy enough, actually getting a connection proved to be a challenge. Anyway, after reading this item…http://askubuntu.com/questions/461825/connect-to-wifi-from-command-line/461831#461831 I managed to get the WIFI working by putting the relevant login information into a new file /etc/wpa_supplicant.conf and trying out the commands. To cut a long story short I soon realised I had a WIFI connection, disconnected the Ethernet connection, rebooted and lo – WIFI. All seemed like a lot of hard work BUT what WAS noticeable was the speed. Where the likes of the Orange Pi have given me unreliable connections where you could SEE in using the terminal that the WIFI was not right, this seemed to go like a rocket.  I tried an apt-get update/upgrade… seemed as fast as the Ethernet version.

Benchmarks: I could not, originally,  test my Raspberry Pi due to some missing dependency when loading SYSBENCH. But I did look here…  and in particular the following tests:

sysbench --num-threads=1 --test=cpu --cpu-max-prime=20000 --validate run

sysbench --num-threads=4 --test=cpu --cpu-max-prime=20000 --validate run

well, someone apparently produced results of 768 seconds for the RPi2 on 1 thread and for the RPI3, 192 seconds for 4 threads – fair enough…

Finally, I managed to get my RPI2 updated to grab Sysbench and do the same test – 202 seconds for 4 threads… but here's the thing....  the A64 using the identical test -  4 threads -  8 seconds. I did say it looked FAST but really?

I have another Pi2 sitting doing nothing – zilch on the bench – I installed the same Sysbench and ran the same test again on the Pi2 and on the A64 – 8 seconds for the A64, 123 seconds for the Pi2.

Conclusion – the A64 on a simple CPU test, ABSOLUTELY and utterly WIPES THE FLOOR with the Raspberry Pi units.

Eventually: So – am I happy? Yes - I have a rather fast board to play with.  I contacted FriendlyArm to find out the status of their version of the GPIO control software to see if it is available for this board.  Erm, no.  That is going to make it a little difficult for Node-Red to control ports.

So would I recommend this to others?  If you’re comfortable with what you have read here and hopefully find my efforts a bit on the amateur side then yes, it looks like a really good board and it is certainly well-made and I DID get everything to work in the end (and I am by no means a Linux expert). If you struggled with this blog – I suggest looking elsewhere or wait for WAY more support to appear. GPIO could be fun getting to work.

Some of these other-board manufacturers do a cracking job – many of these boards are well made, well priced and generally very professional, but I’m sorry, all those claims for I2c, SPi, GPIO etc. are MEANINGLESS to most of use unless backed up – at the least this board needs an up to date version of Debian or Ubuntu complete with GPIO support and examples and right now that is not on offer. I know how I2c works, I know how to use it. I neither know nor, in any ware, care AT ALL how it is implemented in the operating system of how to implement it myself. Life is too short.

But give it time, if you’ve read my other reviews I’m usually quiet supportive. If you want more info – simply look up NanoPi A4, there is a ton of info on their WIKI.

Follow-up and WIFI: Two days later and I’m still messing with these boards – I have Ubuntu pretty much the way I want is and DD continues to do the job for backing up – so I have two of them, identical, sitting side by side. I used this link to get colourful terminal commands (why on earth in the 21st century are we still using boring black and white for Linux terminals) and I I have both machines accessible by name (FriendlyARM1 and FriendlyARM2) on WIFI and now the final touch –  I was pondering a cron job to make sure they recover from duff wifi but on test, disconnecting the WIFI – the terminals go dead, reconnecting the WIFI – in both cases they recovered automatically. I tried this several times – a shame some other operating systems and boards don’t fare so well!

Facebooktwittergoogle_pluspinterestlinkedin

Some Background

Far too often in blogs like this we “assume” that everyone is following along, so for the sake of boring regular readers…. the background to much of what you will see in this blog, revolves around my home control project which started off using an Atmega1284 chip as a controller and Arduino and wireless as end-points, mutating over time into it’s current state where I use any Raspberry-Pi “compatible” board to run Node-Red and talk to ESP8266-based end-points by the MQTT protocol – most of the programming being in C and NodeJS as appropriate - and a need to understand how best to make use of available widgets for general home control, in the now widely-used Node-Red (thanks partly to it’s adoption by Raspberry Pi).

I’ve followed the fantastic Node-Red since the beginning as it seemed like a good contender for home control even before the original “ui” – a community addition, eventually absorbed into the main Node-Red project to become “desktop”.  To find out more about Node-Red and Node-Red Dashboard you can join the discussion group over at Google+

Within the desktop you have a “node” called “template” which can display simple web pages inside a window in the desktop and can accept inputs and send information from its output – a near-perfect “black box” if you like. The problem is understanding just exactly what you can and cannot do inside the template, how to display items inside the template and making sure such items scale appropriately.

This is part of the journey that some of us are on – and I’ve written several articles on this now in the blog here. I hope you find them useful.

Within Node-Red there is a file called settings.js (usually on a Pi or a machine you’ve set up with a Pi user, this would be located at /home/pi/.node-red/settings.js) and you can set directories for your own javascript and css. As Node-Red already has such directories I’ve chosen to standardize on mjs, mycss,myimages, myicons etc.. using this as the base:

httpStatic: '/home/pi/.node-red/public',

Javascript can then be accessed as /myjs/xxxx.js  etc

As one would normally use an 8GB or larger SD for such projects (smaller are often as expensive and sometimes hard to get) there is usually no shortage of space to store libraries of images, routines, css etc…  jQuery is already available inside the desktop without including it.

A good direction to go in (so it would seem) is to use widgets based on HTML5 Canvas. Keep an eye out for new widgets based on this and feel free to send us links to anything new and exciting.

Facebooktwittergoogle_pluspinterestlinkedin

A Fantastic Day

Scargill's ThermostatIt’s been a good day today.

Let me clarify that – a good day considering I’m in the Northeast of England, wishing I was in the south of Spain and currently freezing to death.

I got up far too early with ideas in my head about the Thermostat – to cut a long story short, I had some ideas about introducing status colours into the top part of the display to show when the stat is off automatic or in away mode – that went fabulously well as you can see on the right – the status colours show up if you go off automatic – making it much more obvious.  Preliminary Node-Red flow here - see previous blog about requirements. I have now updated the original Thermostat blog entry here.

In the meantime I had an email back from the fellow who wrote the CANVAS dial, I’d used the JavaScript control because I simply did not understand how to interact with the canvas inside a Node-Red Dashboard template. Suffice it to say I do now and I’ve some more upgrades in the background.  Exciting stuff and opens up a world of opportunities.

Incidentally – once again, yesterday set a record for views on the blog – so thanks to all the new readers in here – I trust you’re finding this interesting.

Meanwhile a boatload of post turned up for me including a mountain of ONION2 peripherals which I’ll blog as soon as I get a minute – and the new FriendlyArm A64 board. I’ve been working with Antonio (MrShark) on this on and off as the operating system that came with it was ancient. A long conversation for another time, suffice it to say that right now we have Xenial and my script running on it but a few mods are going to be needed to accommodate this powerful 64-bit SBC.

I ALSO got some tiny DC/DC convertors I’ve been waiting for. I’d originally planned to make up a 24 volt solar system for Spain and of course all my stuff runs on 5v or 12v – slightly less of a worry now I’m going down the 12v route (I have a very nice 12v 500w full sine wave invertor sitting in front of me) but these boards are CUTE – size of my thumb-end and take up to 30v in with variable output. Cheap, too.  https://www.aliexpress.com/item/20-pcs-Ultra-Small-Size-DC-DC-Step-Down-Power-Supply-Module-3A-Adjustable-Step-Down/32262311443.html?spm=2114.13010608.0.0.4iRhaN

DC-DC ConvertorsNow, they CLAIM 3amps, I don’t believe it but they were so cheap if they do 2amps I’ll be happy – however it just so happens I have a 1R resistor – so,  I may just test one to destruction – the worst that can happen is a smell of burning plastic on test. Just before giving up for the night - I set the output to 3v, input 30v supply and banged a 1r 10w resistor on the output - which rose slightly to 3.2v (hence 3.2 amps) and within 20 second the resistor was quite warm and the pcb I would say hot... but no very hot. I could see 2 amps coming out, yes....

As always some great comments in the various blog areas  - I need a system to star rate comments and make them available in a “most useful” list order… a lot of great info from some great people hidden away.

That and some really pretty microUSB THICK leads from Ebay and home-made soup for lunch, not a bad day at all. More tomorrow –I have high hopes for the FriendlyArm board – and it is cheap, too!

Facebooktwittergoogle_pluspinterestlinkedin

New Day, New Dial

Scargill's thermostatWHAT a day I’ve had – messing around with a supposed DIY Alexa that isn’t… and getting to grips with dials. I wasted a lot of time on this (sorry Dave) before finally grasping the solution.

Here is the LATEST short video (Jan-10-2016)

So – in the last blog entry we took a look at the NEW Thermostat – this article looks at an even newer GAUGE - top left corner of the stat on the right – instead of a simple node-red-dashboard level node to show the temperature I have a pretty new gauge. All working as well! Indeed it is so useful I’ve decided to separate this out as I’m sure many of you will have a use for one or more of these.  Don’t get hung up on it being a thermometer – you can use it for anything – humidity, speed – whatever – completely programmable.

Here is the link to the gauge code. Pretty impressive stuff – there are examples over there – but the trick is, importing them into Node-Red-Dashboard. So – there is a library – under downloads – all in one.  Grab that .JS file and in my case I put it in a directory called /home/pi/.node-red/public/myjs -  that’s where I keep my .js files and Node-Red is aware of this. I’ve covered this before.

Armed with that file – you need a Node-Red-Dashboard TEMPLATE. In this case I set the template size at 3x3.  According I adjusted a couple of settings in this gauge to 160 * 160. pretty much you need the JAVASCRIPT source code for the dial – you get that from the site – and you need a <canvas> block. I’ve also added in a little chunk from earlier code to capture input to the node – that is used to alter the dial. And that is pretty much it.  What I would LIKE to do is dynamically adjust the size of the dial to fit whatever node size you use but I’m not yet succeeded with that.

Anyway – here’s the code for the dial you see here – to be inserted into the template note node to replace the existing gauge – and don’t forget to load in that .js file and make the template 3x3.

<script type="text/javascript" src="/myjs/gauge.min.js"></script>
<script>

   (function(scope){
        scope.$watch('msg', function(msg) {
           gauge.value=msg.payload;
        });
 
    })(scope);
var gauge = new RadialGauge({
    renderTo: 'canvas-id',
    width: 160,
    height: 160,
    units: "Degrees C",
    title: "Thermometer",
    minValue: 10,
    maxValue: 30,
    majorTicks: [
        '10',
        '15',
        '20',
        '25',
        '30'
    ],
    minorTicks: 5,
    strokeTicks: true,
   highlights  : [
        { from : 10,  to : 15, color : '#8888ff' },
        { from : 15, to : 20, color :  '#88ff88' },
        { from : 20, to : 25, color :  '#ffff00' },
        { from : 25, to : 30, color :  '#ff8888' }
    ],

    colorPlate: "#fff",
    borderShadowWidth: 0,
    borders: true,
    needleType: "arrow",
    needleWidth: 2,
    fontTitleSize: 42,
    needleCircleSize: 14,
    needleCircleOuter: true,
    needleCircleInner: false,
    animationDuration: 500,
    animationRule: "linear"
}).draw();

gauge.value = 18;

</script>
<canvas id="canvas-id">
    
</canvas>

ToDo – reduce the grey box from a float to an integer with 2 digits and get a 7-segment font into that grey box.

I’ve updated the original Thermostat page here..

Facebooktwittergoogle_pluspinterestlinkedin

A Christmas Script

tmp81FFOver the weekend and beyond, reader Antonio Fragola (Mr Shark) and I have been working on a couple of things together (no we’re not in the same country – Skype). Regular reader will know about the script (original blog material now ditched though the old script is still on BitBucket) that a couple of us originally developed to put Node-Red and several other packages onto the Raspberry Pi for home control purposes.

Well, that original script mutated to run on several different boards and my one big gripe has been the amount of interaction once the script starts.  THIS one is simple – and after reading some comments about how good Xenial (Ubuntu) is – we’ve also made the script compatible with this. So Raspbian, DietPi (Debian) and the Armbian versions of Debian and Xenial (Ubuntu).

Before I begin – no, we’re not a support shop – you may or may not end up having to tweak things for your system but please don’t write in to say “I tried this on a Mac and it doesn’t work”).

The level of interaction is now zero thanks to a new menu-driven approach and many improvements including using a VM (virtual machine) to test the whole thing at accelerated speeds. We’ve also put in some extras.

What is this about?

What we have here is an explanation of how to get Xenial running in a VM – the purpose of this is merely as a base to test the new script mentioned below which will install somewhat more than the original script (designed originally for Raspberry Pi but now working on several Debian-based devices and now Xenial) – namely:

  • Node-Red at port 1880 and lots of useful NODES
  • Mosquitto with Websockets
  • NODEJS/NPM
  • Webmin at port 10000
  • Apache at port 80
  • HA-Bridge at port 82 (suitable for Amazon Alexa)
  • SQLite and PHPLiteAdmin
  • MC File manager and editor
  • Lots more – see the menu screen

Typically this setup would be used as the basis of a nerve-centre to control and monitor home control gadgets such as the ESP8266 units we discuss in this blog, Sonoff controllers and much more. Armed with this software, controlling the home is easy – and more importantly can be done YOUR WAY.

The Virtual Machine

Let’s take a look at what we did – you can of course duplicate all of this as you go along. We used the excellent VMware of VirtualBox on Windows PCs. This explanation covers VMware.

So – first things first – as I’ve done a video of the Virtualbox installation complete with sample use of Node-Red, here we’ll discuss the VMWARE version.  Both of these were done as test mechanisms before using the script on real devices such as the Orange Pi Zero, Raspberry Pi, Odroid and other devices discussed at length in the blog.

We loaded up a copy of VMware (I used VirtualBox but the procedure is similar – VMware player is free of you can use the full commercial workstation) and made sure it works. That much is up to you. There is a wizard for creating new virtual machines -  we chose a CUSTOM machine. Steps from that point on were:

NEXT - NEXT – “I will install the operating system later” – NEXT
Linux / Ubuntu 64-bit – NEXT – d:\test  - NEXT
Number of processors – 1  - number of cores – 1 – NEXT
Memory for this machine – 1024MB – NEXT
Use Bridged Connection - NEXT
I/O Controller type LSI Logic - NEXT
Disk Type SCSI - NEXT
Create a new virtual Disk - NEXT
12GB (I used 16GB – 8GB would have done) – Store virtual disk as a single file - NEXT
At this point we gave the file a name – in our case d:\test\Ubuntu 640bit.vmdk -  NEXT – FINISH

Under settings – hardware – CD/DVD we ticked “Use ISO image file” and selected the file we loaded from the Ubuntu website – “Ubuntu-16.04.1-server-amd64.iso” – OK.

At this point you’ll note reference to AMD64 – that had me as well but it works a treat on INTEL hardware.

Start off the VM – you get asked which language to use (ENGLISH) and various options will come up – the first being “Install Ubuntu Server” – that’s the one.

Once again you’ll get a language question – English. Location – in my case “United Kingdom” – if you don’t fit into the rules use “Other”.

Time Zone in my case – EUROPE  and then country. Locale – in my case United Kingdom.

Hostname – we went with the default “Ubuntu” – but call it whatever you want.

At this point you get asked to create a user – it is important you make a user “pi”. Enter password also (though the new script will create user PI if it does not exist).

tmp6049Home encryption – we said no. When asked if the time zone was correct we said yes.

Partitioning – “use entire disk” (remember this is a virtual disk – not your real disk). You are then asked to confirm erasing disk – go with that. You then get asked to confirm AGAIN. YES.

HTTP Proxy just leave blank – CONTINUE.

Install security updates automatically.

Add OpenSSH server and CONTINUE (important for remote access)

Install GRUB bootloader – YES.

Installation is complete – CONTINUE. Let it run.

And voilà – one working copy of Ubuntu. You have a pi user – at this point you’ll want to give ROOT user a password (sudo passwd root).

You need ROOT user for the next step.

No matter what machine you are using – you need a “pi” user and to make life simple – and compatible with that of the original Raspberry Pi user, a little command line work is needed. The rest is handled in the script.

So as ROOT user…

adduser --quiet --disabled-password --shell /bin/bash --home /home/pi --gecos "User" pi echo "pi:password" | chpasswd usermod pi -g sudo echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pi chmod 0440 /etc/sudoers.d/pi

The FIRST and SECOND lines are not needed if you followed the instructions above as you already a “pi” user.

tmpB7DFSo now we have a pi user able to do SUDO commands.

The BASH Script

This part is about running the script and assumes a “pi” user with SUDO capability.

Create a file called script.sh in the pi directory and populate it from the script. https://bitbucket.org/snippets/scargill/94yxL

Ensure it has the right permissions.

and that is that. as PI user, in the /home/pi directory you should now have this script. DO NOT run this as ROOT user.

At this point BACK EVERYTHING UP to avoid disappointment – no, REALLY.

Execute as:

./script.sh

You will see a menu which will vary slightly depending on which system you are using – you won’t be asked about GPIO on a Raspberry Pi for example.

tmpE673

For the VM we left everything as you see here and tabbed to OK.

At this point you will be asked for a USER and ADMIN names (which can be user and admin if you like) and corresponding passwords. From there on – everything should happen with no user interaction.

After maybe 15 minutes – or an hour – depending on your system – you’ll see an invite to REBOOT – so REBOOT. When the board/VM boots up you will find hopefully a working system. Node-Red runs at port 1880, Webmin at port 10000 (Webmin needs Pi or ROOT username and pass until we figure out how to add in the ADMIN user).

You should have Apache at port 80  HA-BRIDGE (if installed) will run at port 82 – It seems that Amazon Echo is quite happy with this but the Google product wants port 80!

Node-Red should include MQTT which will need admin username and password as will Node-Red itself. USER name and password is used by Node-Red Dashboard.

There is also the excellent MC – a file manager and editor.

MC and MC EDIT

I hope this brief introduction sets you off in the right direction and of course no doubt there will be discussing in the notes below.

Update Dec 29: Early start this morning - just for the sake of it I’ve just taken the Ubuntu desktop image, installed it on a laptop (a very old laptop) and ran the script – perfect – everything installed. My thanks to Mr Shark for filling in the blanks in my Linux knowledge.

Update 05 Jan 2017: At the time of writing I'm having issues with PIXEL in VirtualBox and DEBIAN on VirtualBox in terms of Apache not loading.. I'm sure we'll sort that - meantime some useful links.   Debian  may not some with SUDO depending on which installation - here's a fix link that worked for me in my VirtualBox image.. If SSH setup won't allow remote access using passwords, here's a link that helped me.  Pixel of course will run in Virtualbox but by default it runs of a virtual DVD which is about as much use as an ashtray on a motorbike as nothing gets saved. Once running however it is a breeze to move over to the Virtual hard disk - you'll find that part way down the comments in this link.  So right now I have VirtualBox running Xenial, Pixel and Debian and the only issues I have are with Pixel and Debian - Apache - watch this space.  I’ve also improved the input for user and admin.

Important: Whatever you are using should have the SUDO command built in – it may not be obvious but Debian often does NOT have this installed by default – sort this FIRST. You should also make sure you have Pi user with SUDO group privilage – PI already has this of course and you may have added a user Pi – if not..

wget https://bitbucket.org/api/2.0/snippets/scargill/E5rG7/master/files/makepi
su -c "bash makepi"

Or, Here’s a useful link – takes seconds and is easy…  basically – as root you can do - apt-get install –y sudo….. and you should make sure that your PI user is part of the sudo group.

Facebooktwittergoogle_pluspinterestlinkedin

RGB LED Animation

LED AnimationI was over enjoying a NYE drink at Aidan’s place at the weekend and we were chatting about gadgets, as you do and he’s made a little 3d printed enclosure that looks like a round home fire alarm box.. in the middle is a movement sensor (IR) and some slots all around. He was demonstrating it and said that he’d put a string of RGB LEDs on the board for status use and I said how nice it would be to give it some Echo-style animation.

That went off on a tangent and we ended up with some fancy animation using my ESP8266 code (Home control 2016). The software to do this has been around for a while – but not really used other than in my flashing Christmas candle referred to in an earlier blog.. in that code you can refer to a string of RGB lights up to 300 of them and do things like -  make the first 10 LEDs RED and pause for a second, then make the second 20 LEDs GREEN and wait for 5 seconds, clear the lot wait 1 second.  That will then continue to do that forever in a loop.

What has always been missing however is proper loops an loops within loops. Well, I fixed that tonight.

Using the normal topic/payload structure I’ve been testing on serial.

Here’s an example I have running in front of me in which I have a strip of 12 serial RGB LEDs.  4 come on in blue, then they go off, then the last 8 alternate between 4 greens and 4 reds, then 4 reds and 4 greens, several times before clearing and starting all over again.  As you can see there’s a loop in the middle of that.

{rgbstop}
{rgbstart:12,12}
{rgbadd:1,0,4,0,0,255,1000}
{rgbadd:1,0,4,0,0,0,10}
{rgbadd:2,8}
{rgbadd:1,4,4,0,255,0,10}
{rgbadd:1,8,4,255,0,0,90}
{rgbadd:1,4,4,255,0,0,10}
{rgbadd:1,8,4,0,255,0,90}
{rgbadd:3}
{rgbadd:1,0,12,0,0,0,1000}

This is now INCOMPATIBLE with earlier code so if you have something already running you’ll need to add a new first parameter (1) to keep compatibility.

The first command stops anything already running. The second sets up 12 LEDs on GPIO12 (count is the second parameter).

An example of a simple light up is the third instruction – code 1, from LED 0, light 4 LEDs in BLUE (0,0,255) for 1000ms.

Then go onto clear those LEDS and wait 10ms.

The new stuff comes in line 5 – command (2) – the loop. That says – here’s a loop (2) which will run 8 times.  More light changes after that then command (3) – end of loop.  Finally I clear all 12 lights and wait a second until starting all over again. That’s it – you can do loops within loops of course.

There is also a command 4 which means END – you’d only use that if you wanted to perform a series of loops and then stop permanently. That has no parameters.

Assuming you’ve used the latter and have a sequence which does whatever and then stops – it might be nice to store this in FLASH and recall it when needed. There are four non-volatile buffers available to store this information.

{rgbstore:X} where X is 0-3

You can play back any of these as below, again assuming in this case GPIO12 and 12 LEDs. Set X to be 0-3

{rgbrecall:X}
{rgbstart:12,12}

The above will play back a stored sequence immediately.

The code is in the usual place and available via the OTA – don’t forget the minor incompatibility. So this applies to version 1.7.5 of the software and onwards.

Facebooktwittergoogle_pluspinterestlinkedin