Tag Archives: Node-Red

Raspberry Pi Zero WiFi

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

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

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

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

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

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

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

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

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

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

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

cd
git clone git://git.drogon.net/wiringPi
cd ~/wiringPi
./build

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

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

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

Things are looking up.

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

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

Facebooktwittergoogle_pluspinterestlinkedin

Node-RED Global Flow and Context

There’s a mouthful. This short article is about the various kinds of variables used in Node-Red and more importantly how to initialise them and how to view them.

So in Node-Red when you want to use variables – there are three basic types as well as local variables.

So for example – you’ve opened up a FUNCTION block and you want to use some variables. VAR is always a good start.

var fred=1;

A way to get a variable to PERSIST behind that simply function invocation to the next time around, use this;

context.set(“fred”,1);

If you’d like that var to be available to any other function in that flow (or page if you like) - use:

flow.set(“fred”,1);

and if you need a global variable that can be accessed anywhere within Node-Red including other flows  – I use them all the time for things like thermostat objects etc… use global.

global.set(“fred”,1);

Of course you can recall said variables as global.get(“fred”); etc. Don't use the old method (example global.context.fred) - there's a reason the Node-Red guys are steering us in this direction.

This is not meant as a course on programming – you can read all about this on the Node-Red site – just look up variables.

So three useful types of variable.

But there’s a problem. Node-Red runs asynchronously and in my first efforts I would have an INIT tab and initialise my global variables there. Once in a blue moon I would see a non-destructive failure with the logs showing that I’d tried to use a variable before it had been initialised (created, even).  So in a platform where everything is running asynchronously how do you ensure (without checking every single time you use it) that a variable has been initialised…. especially important for globals.

One way which I don’t really like is to ensure that the variable is initialised in the left most tab. as that runs first… ok… kind of….

Well it turns out “there’s a node for that”.  Node-Red-Contrib-Config does that – you can set up a variable – which could be a whole object – an no matter where you put this node – it will run BEFORE the main flows start up – I tested it, it works. My only niggle might be that the VALUE field needs to be expandable – a single line is not much use for large objects.

npm install node-red-contrib-config

So that’s one side of it.

The other side is – would it not be nice if you could have a tab to show you the current status, names and values of all of your global variables – and more. Well, now you can.

This needs a SLIGHT mod to Node-Red so if you’re new you might want to back stuff up.

In the directory you normally (hopefully locally) npm install stuff –

https://www.npmjs.com/package/node-red-contrib-contextbrowser

So the install is:

npm install node-red-contrib-contextbrowser

Stop Node-Red and in (in my case) and make a slight edit

nano /usr/lib/node_modules/node-red/red/runtime/nodes/context.js

This is the function you need to alter - very carefully add one line as I have in bold. That’s it – don’t make any other changes.….and this IS case-sensitive.

function createContext(id,seed) {
var data = seed || {};
var obj = seed || {};
obj.get = function get(key) {
return util.getMessageProperty(data,key);
};
obj.set = function set(key, value) {
util.setMessageProperty(data,key,value);
}
  obj.getKeys = function() { return Object.getOwnPropertyNames(data); }
return obj;
}

If you're something that does not show bold, the line starting "obj.getKeys" is the addition.

(NODE RED GUYS – any chance of making the above standard???)

Start up Node-Red (this works even if you use HTTPS and have password on Node-Red)

And lo – you should have a new tab on the right… click in the editor on a node or function you know has variables initialised…

and then use the refresh in that new tab..

My test..

tmp6E51

The contents of that orange function

tmpD029

 

And..

tmp65A3

As you can see, you must select the particular node or function with the mouse first – then hit the little refresh in the contextbrowser tab - you then see above freddy and the value in the tab – along with any others you’ve defined in that node or function. Ok it’s not quite debugging but better than nothing.

Now moving to the Global tab is another matter as I have several globals including some big objects – if they are very big – you might have to hit the little … indicator to expand them.

tmp3C87

So for me this is marvellous – I can now set up global vars with the confidence that they will be initialised properly at the start – and I can also get a nice overall view of the globals I’ve used – something I could not easily do before.


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

Facebooktwittergoogle_pluspinterestlinkedin

Size Matters… Neo AIR

tmp897DWhen it comes to size, this one is as good as any… the FriendlyArm Nano Pi Neo Air.

You’ve probably read my blog about the Nano Pi Neo, a device I can only describe as “cute” because of it’s really small size - but powerful non-the-less. Well, the AIR version takes things a stage further. No video, no USB (well, no connector anyway) and no Ethernet connector which makes it EXCEEDINGLY THIN.  But it DOES have Bluetooth and WIFI including a socket for an optional external antenna (it also has on-board antenna).

tmp39E7So – H3 Cortex A7 Quad-Core processor – which means that a variety of alternative operating systems to the default Ubuntu will work (just as well as I for one have no interest in Ubuntu). The board is 40mm square and the highest point on the board before you (optionally) fit the (provided) connectors, is the micro-USB connector, which could make for a MIGHTY small controller!

The Neo AIR comes complete with 8GB of on-board  eMMC loaded with Ubuntu. I really don’t see the point of this as it is so hard to fully make a copy as against just replicating SD cards. Aside from anything else – all these boards call themselves or refer to PI – and the PI comes with Debian – not Ubuntu!  However – reporting this for the record. Idling power (depending on operating system as little as 1 watt (i.e. 200ma at 5v). Headers for 3  USB 2.0 ports (but no connectors) 512MB RAM and finally a DVP camera interface. Connectors include UART, SPI, I2C, GPIO, IR, SPDIF and I2S (though actually making use of these will be down to software support!)

Here’s a handy pinout:

tmp4E0F

The whole thing weighs less that 10gms.  I’m thinking this could well make a minimal system for talking to Alexa DOT – perhaps with some IO all in one tiny box!!

tmp23CAA heatsink was provided but no box – but then again any box would probably be of a height to accommodate connectors and I’d really like to see this in a super thin box – or even on the back of a Nextion display.

I note that another blog has covered the use of the board with the Ubuntu operation system so I won’t get into that here.

Note the micro SD connector bottom left in this photo and the power connector/ OTG port top right. There is also a separate 4-way connector for serial debugging.

I tried to use one of my NEO SDs with DIETPI but the software worked – but without WIFI – I could not see a way to fix that and have written to the  DIETPI site in case their software can be updated. That would be good.

Meanwhile I’ve just tried the latest ARMBIAN – blew the SD – popped it in – it works – (serial monitor) – went into NMTUI (command line WIFI etc. etc.) – works a treat. How there is NO mention of Bluetooth in that setup but as I don’t need that right now I’m not too bothered. One of our readers has already commented “No Bluetooth” so I’m guessing that remains off the table for now. I could of course use FriendlyArm’s image but that means re-jigging my script with umpteen installs which probably would not work. Erm, no.

Right now I’m in the middle of running my script from the serial terminal. WinSCP works with an IP address (it would be so much better if Samba were installed from the start so that the domain name worked) and I have noticed that when bringing up a terminal, it is SLOW – I suspect that is down to the WIFI signal – I noted when using Armbian in the past that the WIFI was not that hot on other boards – using DIETPI on he NEO it was marvellous – but that’s not working for the AIR so far.

I did note earlier that the TIME was wrong on the unit (no doubt an issue with Armbian) as it said the last log-in was November 1st – it is November 7th and I’ve only just installed Armbian.

Accordingly my script has been sitting here in a loop complaining that “binding.gyp has a modification time 180293 in the future” and it looked like it was going to sit there and wait that long! As I write this I’ve used the DATE command and all came along nicely if slightly more slowly than normal. First time I’ve ever had that date issue.

And while all of this was going on – the board was only just warm, certainly not warm enough to warrant a heatsink.

HOWEVER – initial impressions – once my script was done.. WINSCP – slow as a DOG. Not remotely in the same league as a typical Raspberry Pi – or even the NEO - HOWEVER - According to TKAISER of Armbian this is because the board needs an external aerial – which begs the question – why didn’t that come with the board!! On close inspection there is no internal aerial… dohhh…..

Update Nov 08, 2016: Ok, aerials on the way – I’m using it with a GPS aerial which is hardly ideal and the WIFI seems solid enough. I hope the proper aerials are small!! I read elsewhere that the chip used is the Ampak AP6212 as used on  Raspberry Pi 3 and there’s a link to more info on that… https://github.com/seemoo-lab/bcm-rpi3 (https://github.com/seemoo-lab/bcm-rpi3). Still running cool enough to NOT need a heatsink.

Update Nov 11, 2016: While waiting for the aerials – and in another blog, TKaiser of Armbian just happened to mention they have a utility to copy an SD setup to eMMC.  It is part of the standard installation and is:

/usr/lib/nand-sata-install/nand-sata-install.sh

So I ran it in a terminal and after a while – it told me to reboot without the SD. I did that and LO – not only a working AIR but a much faster AIR. I took the SD, inserted it into the other board, booted up – repeated the operation – and lO – TWO working AIRS– a quick change of name of one of them and Bob’s your uncle! Well impressed!

Update Dec 20, 2016: Here's a thing. After not using the Neo for a little while, last night I decided to do an apt-get update/upgrade. The update failed due to inability to contact some sources. I tried 3 or 4 times - no joy. I decided that either the WIFI was in trouble or a source was offline and to leave it until this morning.  I got up this morning and the update was fine.. but when it came to the upgrade, I got a message to say the disk was full.  8GB of eMMC - i was sure I'd only used half of that.  Anyway I went off searching - and discovered several large LOG files - deleted the larger onces and now all is well - I've recovered over 2GB of log space. Hmm.

Facebooktwittergoogle_pluspinterestlinkedin

Toying with HA-BRIDGE

Thanks to readers in here I’m having a play with HA-Bridge to act as a device gateway between my home control (generally ESP8266) devices and Amazon Echo.

I’m only scratching the surface and haven’t gotten past “Alexa, turn X on”, “Alexa turn X off” and “Alexa set X to 30%”  but it’s a start and hopefully someone in here will fill in the blanks.

So, assuming you have an Amazon DOT or Echo (at £49 the DOT is the best toy I’ve bought for ages – just bought another one for the house – as this one is hiding in my office)…

The BEST way to control gadgets by voice up to now IMHO is using our own Node-Red software and an HTTPS certificate – but then – it’s not trivial as has been discussed elsewhere (unless you’ve done it before) to get the HTTPS and Amazon talking to each other.

So I played with simpler solutions (I like to try everything) but just recently decided to have a go at HA-Bridge – now – this IS EASY if you don’t go to the wrong repository etc…

First things first – Aidan was playing with this and he could not get anywhere as he had an old version of JAVA on his Raspberry Pi – he solved THAT problem as such. I found that I had to use root access for ALL of the code below.

    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
    sudo apt-get update
    sudo apt-get install oracle-java8-installer

So that's Java up to version 8. On a NEO AIR I got an error message when running “java –version” until I rebooted.

Now to install HA-Bridge - easy -  go to your PI directory on the Pi or similar - make a directory - called, say, "habridge" - and enter that directory. I grabbed the JAVA file directly in Windows and copied it across-  giving it execute permissions - not sure if that was necessary but I'm just repeating what I did.

All I did was grab the JAVA file from here.

So the general idea is that this Java file will run - and give you a web page in which you can create and run "devices" that the Dot or the Echo will recognise. But it will want to use Port 80 by default (normal web page port) and I of course have a web server there...  I tried running it - failed due to lack of permissions - so I ran it as ROOT - that failed due to the port being in use.

sudo java -jar -Dserver.port=82 ha-bridge-3.2.2.jar

I ran this - note the reference to port 82 - and lo - it works - ok - another matter getting it to run from power up but we’ll come to that.

Ok so THEN I discovered that my MQTT installation – Mosquitto did not include the client tools… so…

sudo apt-get install mosquitto mosquitto-clients -y

Off I went to a browser : 192.168.0.20:82

HA Bridge

Ok, here's the bit that floored me - this might save you a little work. I used MANUAL ADD to add these devices - here's one of them... these will respond to on, off and a value - and send MQTT messages accordingly. That's it - all you then have to do is tell Alexa to search for new devices - and use them.

So what we have here is only marginally better than the simple node-red node - i.e. we now have % lighting control - who is going to show us how to develop this to do temperature and other stuff!

HA Bridge

If you don't need user and password for your MQTT  (-P and –u) - don't use them.

The only thing that appears fairly useless is the middle item - intensity control - which could be used for lighting or heating. So "turn office television to 25" works - you get the value 25. "turn office television up" or "down" shifts the value by around 25% - and that's GREAT for lighting but no use for heating - I would want an actual value to set the heating to that value - but up and down to shift the temperature by - maybe 1 degree.

You can in fact say “turn X up by one”.

SO - easy voice control - create lots of devices... this whole operation other than blogging it took merely a few minutes and thanks to readers who pointed me in this direction.

This software does not seem able to control responses – you get “OK”  - how then would you ASK the thermometer to return it’s current value!?!?! Well, you can’t so there is still life in our HTTPS solution – but this is VERY easy to set up.

Having now followed the instructions here and here (see “writing a unit file in the latter link) made a “unit” startup file – I now have the whole thing running from power-up on the same Pi that runs Node-Red and Mosquitto.

Essentially here’s what I ran having created a UNIT file as per the first of those two links above.

sudo systemctl enable habridge.service

sudo systemctl  start habridge.service

That’s it – program runs – survives power cycle.

Here’s another explanation of how to do this! http://xbmcnut.blogspot.co.uk/2016/10/installing-ha-bridge-on-your-raspberry.html

So much to learn, so little time.

Facebooktwittergoogle_pluspinterestlinkedin

Instant Node-Red

Peter Oakes kindly made a video - you'll see it in my last post - on installing Node-Red using my script. Well, I was in the process of watching THAT when (as you do) I got side-tracked and discovered a really wonderful online tool for testing out Node-Red instantly - no installation - not even a sign-in!

Check out my new video here. Don't worry - its a short one 🙂

Facebooktwittergoogle_pluspinterestlinkedin