Category Archives: Debian

Android Phone as Server

Why am I showing you a picture of a cracked-screen phone?

Linux on Android PhoneWell because this particular phone is a bust Oukitel K10000, the phone with the world’s longest-lasting battery and an excellent workhorse. My friend Aidan gave me this (rather than chucking it away) some time ago and it has been sitting doing nothing. All that is wrong with it is a cracked (and exceedingly dangerous on the fingers) screen. I’ll bet I’m not the only one with such a phone lying around wasting space.

Well, as of yesterday, it is a Debian server with all my usual stuff going on quietly in the background – with the screen normally off – running freezing cold and hopefully being super reliable.

This is an experiment only – beware – if your phone or tablet dies it is your problem….  oh and your Android phone/tablet needs to be ROOTED. 

Imagine turning your old, dust-covered phone into a sleek, battery backed-up server with unfeasibly long backup time, immunity to any mains spikes, a silent, fast Debian base for all the stuff in my script – which includes Node-Red, Apache/PHP, SQLITE (+ PHPLiteAdmin), MQTT, MC, Ha-Bridge and more!  If you’ve been following this blog you’ll know about the script.

So this article applies to ROOTED Android phones and we’ve only tested around Android 5.0 onwards.  In my case I rooted the phone with KingRoot (note, NOT the one in the PlayStore which is a con – avoid it - but the one at kingroot.net ) – please note that rooting phones is beyond the scope of this article and if you are not confortable with this you should not do it. There are a lot of links out there on the subject and many of them are fraudulent.

tmpCD52There is an APP in the Play Store called Linux Deploy. It is also on GitHub. Beware that this is essentially undocumented unless you are Russian – so please don’t ask how you can use your phone’s GPS or Sound from Debian – not a clue!

You should have a modern-ish WiFi enabled (or hardwired if you like) Android phone or tablet with at least 16GB of internal FLASH (which should give you 10GB working space).   If you only have 8GB that will leave you only 2GB which - really – isn’t enough.

Getting Debian 8 on the phone:  After ensuring your phone/tablet is rooted, Install the App.

Linux on Android PhoneIn the app, on the top LEFT menu – find  REPOSITORIES and select Debian 8 for ARM.

On the bottom right is a drop down – you should go in there and select INSTALLATION TYPE – directory (OR FILE with a reasonable file size limit – say 5GB – the 2GB default will NOT work). Change the user to “pi” with suitable password in the same menu. TICK for allowing initialisation – and use of SSH server. Also where you see INIT SYSTEM change that to sysv. 

Then TOP RIGHT menu  - INSTALL – that might take some time – top right again CONFIGURE – then bottom menu START – and you should have a working Linux you can get into with for example WINSCP for that “pi” user. The IP address is clearly shown in the App.

I suggest not going further until you are comfortable with the above – took me several attempts because I didn’t follow the above exactly (well, and Antonio and I were learning at the same time).

Running the script: Via WinSCP or similar, put the script into the pi directory – changing permissions as normal - run the script – and ensure PHONE is selected – it isn’t by default. Come back after lunch. The script will no doubt suggest a reboot. Instead, hit the STOP button on the bottom of the phone screen – wait for it complete, hit the START button – wait – and you should now have everything in the script running!

Now – I’m using this to run my script – but I’m thinking you COULD use it to serve files etc. – I’ve not tried this but I’m guessing it would be easy to access an SD card…. and make that a folder…. hmmm.

Anyway, it is now the day after I installed all this – the phone is sitting there “off” and unlike my FriendlyArm board with it’s whirling fan, is sitting silently and freezing cold yet ran the script much faster than any of my SBCs – around 40 minutes.

K10000 running Debian 8No guarantees as there just isn’t enough info about Linux Deploy out there (unless you find/translate some) – but it does seem to work well now that we’ve made sufficient alterations to the script to take this particular setup into account. A fun project, to be sure. Now, I know this is a not a fair comparison and tomorrow we might come back and say … no good (for whatever reason).. but at £107 for that particular phone… compare – how much would it costs for a Raspberry Pi 3, uninterruptable power supply able to keep the phone going for something like a couple of days with no power, a high-def touch screen, a solid case for the whole thing.. indeed ,it might be possible to use a cheap tablet…  I was looking on Ebay – 16GB Android tablet – perfectly working except for missing buttons and cracked digitiser – around £10

One thing to note – I’ve turned rsyslog messages off – it was spitting out all sorts of unwanted helpful messages when you changed brilliance on the phone or disconnected the USB etc –REALLY annoying.. If you feel you need logging on -

sudo service rsyslog start

That will stay on until the next stop-start…

Node-Red running on a K10000 phoneSuch a shame it isn’t clear how to access some of the peripherals like audio. But who knows – someone reading this article may already have solved such challenges.

Please note: the pretty colours on the right do not come as standard. Click images to see larger versions.

This is really starting to look GOOD!!!!

Revelation: I’ve now taken on-board ideas from others and thanks for that – both people in here and on Google+ – most of the other solutions are longwinded and need other packaged  so up to now Linux Deploy – I’m now installing on my old Nexus 7 2012 UTTERLY SUCCESSFULLY (though not the fastest kid on the block) ( after rooting it with the Nexus toolkit ) - using Linux Deploy (which is completely self-contained and offers full root access – is looking the best). The ONLY thing you can’t do is use the Android peripherals – because of lack of UK info but this morning I figured it all out. 

We’ve also tested this one OnePlus One (model BACON) and a Xiaomi Redmi 3 model IDO). The K10000 has now been up for several days.

Ok, bear with me – you have Node-Red on Linux – and MQTT. So, you run Tasker on the phone (in the Android section) with MQTT – and now you have access to and control of all of the Android facilities that TASKER can handle (i.e. just about the lot) from within the Debian environment. Doddle.. now all I need is some time!!

Facebooktwittergoogle_pluspinterestlinkedin

The Orange Pi Zero

Those of you who read my stuff will know that I’ve never been impressed by the Orange Pi boards – the utter lack of communication from the company really is stunning and initially the boards used to get very hot – but then came Armbian and all that changed – third party support and lots of info.  With that in mind I’ve been looking forward to getting an Orange Pi Zero.

Orange Pi Zero

This is not a high end board but it REALLY is cheap so I had to see it working. Well, I’ve started and up to now I’m not stunningly impressed.  But whether it is the BOARD or the SOFTWARE I’m not yet sure. I installed DIET PI – which has worked so well elsewhere and in this case you really are counting on the operating system working from day one because there is no video output. I loaded up the DietPi software and there is a text file on the SD you can go in and setup WIFI etc. This board has both Ethernet and WIFI but I wanted to go in at the deep end. Well, I failed – no-where on the network could we find the board despite setting it up correctly. Ultimately I chickened out and plugged in an Ethernet lead (there’s a long story of broken leads here but we’ll put that to one side).

The board connected up no problem – I went into the setup and set up the WIFI – it found my access point and connected. I changed IP address – voila.  Rebooted – no sign of WIFI (sigh).  I had several attempts at this with a clean SD each time and for now I’ve given up.

My script loaded without apparent issue, on the Ethernet connection.  The thing is – I see these cheap boards as upmarket ESP8266s, i.e. peripherals for dotting around the house – and so the WIFI absolutely must work.

If you’ve read some recent posts I’ve been playing with a VM version of Debian that loads my script up in 18 minutes – well, the Orange Pi Zero isn’t quite like that – it’s nearly done now and at 1 hr 20 minutes – not stunningly fast but no worse than a Raspberry Pi 2.

Now bear in mind when I did a review of the WIFI only FriendlyArm NanoPi Air I commented how much faster the eMMC was – well of course you don’t have that option here. This is a nice, cheap board, cheaper than the Air but I would not want to swap.

Well, the script all worked, no problem – nice little board but the WIFI just would not work reliably – WIFI  is necessary so that it can be used as a place-anywhere peripheral – I remain convinced the better bet is the FriendlyArm product UNLESS you’re planning to use hardwired.

And that started off a WHOLE conversation in here which led to trying XENIAL (Armbian version). After some messing around as the very latest version did not have WIFI installed AT ALL by the look of it.

I also noted that the domain name was not accessible from Windows – as it would have been on a Debian system (Samba) – a line has now been added to the script to ensure that HOSTS is read first.

PHPSYSINFO needed a slight mod – that was provided by Mr Shark and that is backward compatible.

As things stand – I cannot recommend this board for anyone wanting to use it with WIFI.  If you are daft enough to go to the ATTROCIOUS Orange Pi site – you’ll find links for the software – November is the latest at the time of writing and it is irrelevant because there are two links – a BAIDU link in Chinese – and a Google Drive link which AS USUAL is utterly DEAD. So you can go and get DietPI – I could not get the WIFI to work reliably – or grab the latest Armbian – and I could not get the WIFI to work at ALL.  In both cases I’ve now written back to their forums with requests for help and logs in the case of Armbian. Time will tell.

Meanwhile – GPIO for these boards has taken a turn for the better with node-red-contrib-opi-gpio – direct control over GPIO pins from Node-Red – not anything fancy mind you, just input and output – the package is set up for the Orange Pi, not the ZERO so I found some pin differences but if you refer to the actual port bit PA0 etc then this works a treat. That’s a great step forward. Follow the instructions here to install including the additional setup.

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

GPIO Orange Pi Zero Node-Red

I've also been messing with I2c on this board - you'll see a July 2017 blog entry on I2c - and that works a treat - actually there are TWO I2c channels on this board and they both work a treat.

Facebooktwittergoogle_pluspinterestlinkedin

Alexa Enlightenment

Last updated November 16, 2016: In a recent blog entry I told you how we’d been playing with Amazon Echo (Alexa) and got it working. Well, nearly. It turns out that what SEEMS obvious in the system is not all it seems - but read on as we've had success.

What is Alexa?

Actually the device is called an Amazon Echo – or for the cheap version and Amazon Dot. It is a box requiring power and WIFI that you can talk to and which will control things. It can automatically discover certain (and often expensive) commercial devices, it can play music, it can answer questions, set diary appointments, make shopping lists – all by voice. And with a little effort can talk to Node-Red to open up a whole new world of DIY possibilities.

Listening for specific words

For example in the Amazon setup pages, you can define variables that will only accept a certain amount of options – so for example – you might say “Alexa, tell computer to turn kitchen lights on” where “lights” could be, say, light, lights or heater.

And that’s fine – but you can’t TRUST that. the word “flights” works equally well and Amazon makes it clear in their documentation that you must do your own tests – any similar valid word in the dictionary could have been accepted (which seems utter madness to me but there you go). Indeed when we tested this – we found all sorts of irregularities – there is no way to say “accept ONLY these words”. And, if you say something that is not at all acceptable, the system will wait to time out – and that takes several seconds – which would annoy the hell out of the spouse. So – if you’re going to have to do your own checks anyway, we reasoned you may as well just try to get the basic words out of the units into Node-Red and “do your own thing”. To be clear then, the Amazon unit is no-where near perfect at word recognition and you have to consider that when designing a solution. I wonder if Google will be better.

Wemo Emulator

A slight diversion here: If ALL you want to do is turn things on and off with Alexa and Node-Red – you COULD just ignore the rest of this article and go grab node-red-contrib-wemo-emulator or read other posts here describing my modifications to FAUXMO.

tmpDE0A

No – REALLY – drop it in – give it a name – like Orange – and define topics and payloads (which might go off to, say, MQTT or may be used to trigger direct port control on a Raspberry Pi or similar) for each of the two commands ON and OFF. Tell your Alexa to go looking for devices – it will find orange – and THAT IS IT – no HTTPS, no NOTHING. It really doesn’t get any easier.  But only ON and OFF which is a bit restrictive - and for heaven's sake don't use the word "shed".

How about controlling your TV. Well, the Anymote Smart controller for Android will talk to Alexa and then hence control stuff by infra-red  – except I can’t get it to talk to Alexa. I’ve written off to the guys at Anymote and will report back. But that takes care of all sorts of Infra-Red stuff as long as you leave your phone on!  Not ideal really.

The Bigger Picture

And now – back to the bigger picture!

Before Alexa, all Aidan and I wanted was something that would listen to requests and then fire speech out so we could handle it ourselves in Node-Red – and that is exactly what we have now achieved. Some will shrink in horror at this having already done it another way – but it looks to us like a great general way forward provided you’re happy with writing your own simple,  high level code to handle a sentence like “kitchen lights on” which could be as simple as a string comparison.

tmp4405

What we’ve done here – is to simple make Alexa collect up to 15 words (arbitrary number) after “ask computer to” – where “computer” is whatever word you want to be (the “skill”) and put them in an array, that function above, called “Alexa” does all of this and strips out words like “eh” “and”, “please” etc. – and you can add more exclusions.  If you forget to actually say anything – the second output of the Alexa function handles it all for you automatically.

So in USER FUNCTION – you get an array – msg.word – with up to 15 lower case words – with the rubbish stripped out. You also get msg.combined, a simple string with everything in one string. If your requirements are simple – the latter might be the way to go.

If you merely want to have Alexa repeat the salient points of what you said so that “Alexa tell the computer to turn the lights on” – the output will be “you said: lights on”

[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]

msg.payload = "You said. " + msg.combined;
return msg;

[/pcsh]

Alexa tell the computer to turn the lights on”

So above, Alexa reads the words in purple and passes on the rest. The simple Node-Red Alexa function strips out the words in red – and passes on the remainder in both an array of words and a simple string.

So clearly you might want that USER function to have outputs for MQTT and EMAIL and whatever other stuff to control your kit – that, of course, is easy and up to you. If you have 2 outputs from the function (set the number of outputs at the bottom) you can write to both at once – or separately by returning an array of messages -  or just one and a null etc. When you send a null – nothing goes out.

Now – I don’t want to go TOO heavily into this because simply string comparisons is probably not the way to go for any kind of sizeable setup… but here is something I’ve used as a test and it absolutely works a treat.

tmp27C1

The code in the user function (note the extra output) is trivial to say the least.

[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]

var msg2 = {};
switch (msg.combined)
{
    case "office lights on" : 
            msg2.topic="mains3/toesp"; 
            msg2.payload="{out12:1}"; 
            node.send([null,msg2]);
            msg.payload="The office lights are now active";
            break;
    case "office lights off" : 
            msg2.topic="mains3/toesp"; 
            msg2.payload="{out12:0}"; 
            node.send([null,msg2]);
            msg.payload="The office lights are now off";
            break;
    case "thank you" : msg.payload="No problem, to be sure."; break;
    default : msg.payload="You said: " + msg.combined;break;
}
return [msg,null];

[/pcsh]

In the example above, I have the function react to “Alexa tell the computer to turn office lights on” by sending an ON command via MQTT to one of my ESP8266 boards. Off has a similar effect, different parameter. The final command it just a bit of fun.

Really – so to get all of this fun, you have to set up your SSL (which I found incredibly painful but in retrospect it was dead easy – another of life’s hurdles out of the way) so that Amazon’s servers can talk to a secure connection (your Raspberry Pi or whatever you are using – FriendlyArm Neo or similar would be just as good running Debian), you need to update some stuff into Amazon’s site – and from there on you never touch the Amazon site again –which is of course the point really -  you only have to concern yourself with your USER FUNCTION in the cosy and quick-to-alter Node-Red environment. What you do with that is up to you.  In my case I’ll add another output to go to MQTT and whatever comes in is processed and maybe does something – any message in msg.payload (you HAVE to send something back) is spoken by Alexa when you’re done. It really doesn’t get a lot easier.

In a really trivial case you might, with TWO outputs,  (the first should be used to return a message;

say

[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]

if (msg.combined==”lights on”)
{
msg.payload=”Ok, light is on”; node.send([msg,null]);
msg.topic=”kitchen/toesp”; msg.payload=”{out0:1}”; node.send([null,msg]);
}

[/pcsh]

Ok, I know, create another object and send them both out at once – I’m trying to keep this simple.

But of course, in reality, you’ll be likely to do FAR more than this and hence having the separate words in an array is useful.

So - on Amazon - you need an intent!

[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]

{
  "intents": [
    {
      "intent":"inputIntent",
      "slots": 
        [
          {"name": "wa", "type": "LITERAL"},
          {"name": "wb", "type": "LITERAL"},
          {"name": "wc", "type": "LITERAL"},
          {"name": "wd", "type": "LITERAL"},
          {"name": "we", "type": "LITERAL"},
          {"name": "wf", "type": "LITERAL"},
          {"name": "wg", "type": "LITERAL"},
          {"name": "wh", "type": "LITERAL"},
          {"name": "wi", "type": "LITERAL"},
          {"name": "wj", "type": "LITERAL"},
          {"name": "wk", "type": "LITERAL"},
          {"name": "wl", "type": "LITERAL"},
          {"name": "wm", "type": "LITERAL"},
          {"name": "wn", "type": "LITERAL"},
          {"name": "wo", "type": "LITERAL"}
        ]
    }    
  ]
}

[/pcsh]

and a "sample utterance"

[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]

inputIntent  {LITERAL|wa} {LITERAL|wb} {LITERAL|wc} {LITERAL|wd} {LITERAL|we} {LITERAL|wf} {LITERAL|wg} {LITERAL|wh} {LITERAL|wi} {LITERAL|wj} {LITERAL|wk} {LITERAL|wl} {LITERAL|wm} {LITERAL|wn} {LITERAL|wo}

[/pcsh]

All we’re doing here is telling Amazon, for the “intent” “computer” – to collect up words and fire them off. And that's it for the Amazon end apart from the usual details they need about you and the https address of your website (the node-red exposed point).

As for Node-Red itself - the example above:

We have an http node which has nothing more than POST and “/echo” as the URL - then our ALEXA function contains the following - it may well be far from perfect but for now it works.

[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]

var doStuff = {payload: msg.payload.length};

switch (msg.payload.request.type)
    {
    case "IntentRequest":
    if (msg.payload.request.intent.name   === "inputIntent")
        {
        var word = [];
        
        word[0] = msg.payload.request.intent.slots.wa.value;
        word[1] = msg.payload.request.intent.slots.wb.value;
        word[2] = msg.payload.request.intent.slots.wc.value;
        word[3] = msg.payload.request.intent.slots.wd.value;
        word[4] = msg.payload.request.intent.slots.we.value;
        word[5] = msg.payload.request.intent.slots.wf.value;
        word[6] = msg.payload.request.intent.slots.wg.value;
        word[7] = msg.payload.request.intent.slots.wh.value;
        word[8] = msg.payload.request.intent.slots.wi.value;
        word[9] = msg.payload.request.intent.slots.wj.value;
        word[10] = msg.payload.request.intent.slots.wk.value;
        word[11] = msg.payload.request.intent.slots.wl.value;
        word[12] = msg.payload.request.intent.slots.wm.value;
        word[13] = msg.payload.request.intent.slots.wn.value;
        word[14] = msg.payload.request.intent.slots.wo.value;
        
        var thisone =0, processed = 0, total = word.length;
        
        for (;;)
            {
            var nxt = "";
        
            switch (word[thisone])
                {
                case "cancel" :
                        msg.payload = "";
                        return [null, msg];
                        break;
                case undefined:
                case "the":    
                case "to":
                case "thanks":
                case "thank":
                case "and":
                case "turn":
                case "a":
                case "please":
                case "you":
                case "er":
                case "erm":
                word.splice(thisone,1);
                break;
                
                default:
                ++thisone;
                break;
                }
                
            if (++processed >= total)
                break;
            }
            
        msg.topic = "";
        msg.payload = "OK";
        doStuff.word = word;
        msg.word = word;
        msg.combined="";
        for (a = 0; a < word.length; a++)
            {
            msg.combined += word[a] + " ";    
            }
        }
    return [msg, null];

    case "LaunchRequest":
    msg.payload = "You need help";
    return [null, msg];
    
    case "SessionEndedRequest":
    msg.payload = "Session Ended";
    return [null, msg];
    
        
    default:    
    msg.payload = "Unrecognised Intent";
    return [null, msg];
    }

[/pcsh]

Note I've added a check for the word "cancel" which simply returns nothing, immediately. This is a vital addition as sometimes you just talk gibberish and want to get out of it!

The format response function looks like this…

tmp9E6A

The other blocks don’t have anything in them – other than the user function in which you can make use of msg.combined and msg.word.  When you are done be sure to send the message out – payload containing text of your choice – as Amazon does need a return value even if your text is blank.

So:

Set up an Amazon account – get PRIME if you want their music – if you’re rich get a Spotify account as the Amazon music selection is naff.

Get HTTPS so the end point of your Node-Red page (no real page exists) in my case http://whatever.com/url

That domain or subdomain needs to point to your building – and your router should redirect port 443 (ssl) traffic to port 1880 on your PI or whatever you are using. Why 443 - isn't that a pain for routers which have SSL management and VPN - yes it is - you have to move those to another port. WHY Amazon absolutely insist on port 443 for SSL I don't know - because any port will work but they won't accept them - please by all means do take it up with them.

If you have passwords set up on your Node-Red and your Node-Red UI (which I do) you’ll have to pass them in the  Amazon website string – and I recommend you do this as clearly you don’t want any old Tom, Dick or Harry logging into your Node-Red

Once they are set up is a matter of going to the Amazon developer site with your account – the Alexa tab, setting up s skill including letting it know about your URL – filling in the bits above – and soon thereafter your DOT or ECHO or whatever you are using should be sending text over to you – to do whatever you want with.

Clearly, this will develop – splitting text up into words like this is useless for email addresses – so “Alexa tell the computer to send an email to pete@scargill.org” is simply not going to work – and as for “Aidan” – it makes a complete mess of that Smile

For reference – we made up some notes from our efforts to get an SSL certificate – if you have proven, better ways that cost less and don’t involve re-signing on every now and then as some freebies do – and which you know Amazon will accept as genuine – by all means give us blow by blow info. If you have a better, more complete, simpler description – please do let us know.

From our notes on setting up SSL – https – which may or may not be useful…

You need a trusted certificate to work with Alexa if you want it to talk to your Node-Red setup. Aidan has emailed the Amazon developer guys and eventually got a reply to say they had an issue with self-generated certificates, now resolved - sadly my router setup appears ot have an issue with them and so I can't test this (the router setup in Spain simply WILL not pass through port 443 to an internal unit).

With Node-Red typically you would have separate username and password for external access - this can be re-used with https: and the https: url can bypass the username and password requirement which means you can continue to use UI (dashboard externally).

Obtain SSL from – in our case, https://www.ssls.com

So, the procedure is to pay your money and then use openssl to generate a certificate request (.csr) file.

openssl req -out my.domain.name.csr -new -newkey rsa:2048 -nodes -keyout my.domain.name.key

Enter all the details that are asked for, but when it comes to the ‘Common Name (e.g.server FQDN or YOUR name)’ bit, you must put in the domain name of your server (without the ‘www’ as you get that anyway), so enter ‘my.domain.name’ into the ‘common name’ section and you will be verified for my.domain.name and www.my.domain.name

Before you start the above process, make sure that you can access your Pi (or whatever) externally using your domain name to avoid unnecessary delays.

When you have your .csr, then edit it and cut and paste the full certificate request into the ssls.com request box when it asks for a certificate request.

It will then generate a small text file for you to place in the www/html root of your Pi. Make sure that you can access it externally by cutting and pasting the file name into a web browser, such as http://my.domain.name/AB5678DEF.txt (or whatever the file name is). When you enter that into a browser, you should see the contents of the file appear.

When you’re happy that works, then click continue on ssls.com and it will verify your website and generate your certificate and bundle which you can then get by clicking ‘download’ to get a zip file.

Store this all safely (including the private key file  that you generated with the .csr file) – i.e. make a backup!

You can use a subdomain - so that if you use www.fred.com for something else you can have https://mysub.fred.com for Alexa and Node-Red (verified – I am using a “things” subdomain without issue while my basic root www address is going elsewhere).

Using advanced DNS or similar function with your provider, point mysub.fred.com to your site. In your router, take 443 and point to the 1880 port of your node-red Pi.

We checked and you definitely can’t use anything other than port 443.

Temporarily route port 80 (website in our case) to Pi - as you'll be asked to dump a file in the root folder for verification..... once complete this can be restored to whatever you were using it for in the first place.

Some files need to go into a folder i.e. /home/pi/ssl (our choice) and your info set up in node-red settings.js needs to know where they are...

Need to setup certificate in settings.js (https://... And uncomment ‘fs=’ …etc.

NOTE: I’ve just had to move the lot from one Pi to another – because I messed up the installation of the Pi and had no ports to play with. I can confirm – ALL that is needed is to move the certificate files (in any old directory) to the new Pi and make changes to the Node-Red settings file – uncommenting FS and adding two lines for the certificates - that’s it – all up and running – this is no-where near as complicated as I initially thought it would be.

Also, if your certificate isn’t from a root CA then you need to copy your base certificate into the certificate chain, mainly because node-red doesn’t give you any option to use a certificate bundle file. i.e. edit your .crt file, copy the contents and paste to the top of the ‘my.domain.name.ca-bundle’ file -  this will add your certificate to the chain file.

Use SSL CHECKER  https://www.sslchecker.com/sslchecker  to check validity

Make sure that the certificate is verified all the way up to the issuing root Certificate Authority or Amazon will reject it

When all working - put your port 80 to where it was. After everything works - reboot your router to be sure.

And if I have not said it before – Amazon’s music library is SHITE!

Facebooktwittergoogle_pluspinterestlinkedin

Banana Pi M2

banana pi m2 Updated December 13, 2016:  Technically referred to as the BP1-M2+  I received this Banana Pi board in the post this morning. It is SMALL – that is, the same width but just a tad wider than the FriendlyArm M1 and M2.

But there the similarity ends. Firstly this little thing has EMMC, microSD, Bluetooth, WIFI, Wired Ethernet, 2 USB sockets (a tad limiting), 1GHZ Arm quad-core processor, 1GB Ram, 8GB EMMC (which to me is too small but I’m sure people will find it useful – and as for backup… I’d rather use microSD), and it claims to run Android 4.4 smoothly – hence my comment about the EMMC – what use is 8GB for Android??!?!?

The Android version is a little old for me so I thought I’d try the recently updated Raspbian. The blurb SAYS the GPIO is compatible with Raspberry Pi (really? Does it run the Raspberry Pi modules for Node-Red? If so I’ll be impressed).

The downloads and docs are all here  https://bananapi.gitbooks.io/bpi-m2-/content/en/ which is a big improvement on some others – Orange Pi with hopelessly out-dated images – others with non-working Google Drive images etc.. I got the image no problem for Debian and as I received no documentation with the board, I was grateful for the online version.

I DID notice no audio output other than that on HDMI – which is a bit of a bummer – I like to see a 3.5mm jack for audio. Sadly the manual refers to plugging in a 3.5mm jack for audio – but there is definitely no 3.5mm jack socket on the board.

There is also an IR receiver. I’ve yet to see one of these boards run it out of the box but there IS a reference to this in the manual! https://bananapi.gitbooks.io/bpi-m2-/content/en/bpim2+irinterface.html – would be awfully handy if this worked in Android for remote controlling stuff.

At this point I just about had the image downloaded and things were going downhill a little.

At the end of the instructions, sure it was obvious you could be now running your operating system – but from WHERE was unclear. I didn’t want to load it into EMMC.

I was encouraged to see WIRINGPI available - https://bananapi.gitbooks.io/bpi-m2-/content/en/bpim2+wiringpi.html but it was not clear if this was a special – if it WAS a special I found myself wondering why they claimed above that the board was PI-image compatible??

THIS page - http://www.banana-pi.org/m2plus-download.html on copying images – got my interest – up to now in all the boards I’ve tested, the Raspberry Pi is the ONLY board that has a simple to use copy/backup facility that will make duplicate images even on different size SDs!! This would prove to be no good.

SO – first things first… claims about being Raspberry Pi compatible – MYTH (like all the rest) if it were compatible it would run the RPI ROMS and it does NOT – I just tested it – result – nothing.

But on the other hand for the FIRST TIME their package they describe as “Raspbian booted first time – and had an “expand file system” which after a reboot opened up the operating system to the full size of the SD (others – ARE YOU READING THIS!!!). Marvellous.

Not only that but their “Raspbian” which features the Raspberry Pi logo and looks really like a Pi – apart from the monitor overhang which made closing programs difficult - has the latest file backup system that ONLY (as far as I know) the Pi has had up to now – would it work? I took the Raspberry Pi image disk that was supposed to work with the Banana Pi – now defunct as it does not – and used that as the backup.

I booted up “Raspbian” as supplied on the Banana Pi site - and ensured the WIFI worked – it DID (however it only found one access point which compares badly to other systems which find even my neighbour’s access point). It said I had a connection – but a poor one – no more than 12ft away from the access point!!! 2ft away my PC streams movies on that connection!

I plugged in the USB with my microSD in the BP1-M2+ and ran the graphical backup program. All looked well as it found the USB3 drive and started partitioning. “preparing partitions” it said. After what seemed like a similar time to the Raspberry Pi, maybe a pit longer, the software went off to start copying the two partitions, just like the Pi. If I were honest it SEEMED a little slower than the Pi2 but there are so many factors to take in here. It copied partition one and then…

“Could not mount partition” – I have NEVER seen that in a Pi2 or 3 before (and I make live backups all the time)  so I took the chip out and formatted it on a PC – and re-inserted…Once again – “preparing partitions”… I’m sure it took longer than normal… (and remember when I do this normally it is on a system doing all SORTS of jobs with all SORTS of software. This is a simple empty system).

Partition one started to copy – 60%… 70%… 90%… slow.   Not in the same league as Pi3… it stuck at 100% for AGES – I was convinced it was going to fall over… and…

“Could not mount partition”. I tried this three times in total with different SD holders – same result.  Having failed to get anywhere I took the same chip in the same container, put it back into a Raspberry Pi 2 and initiated a backup. This worked PERFECTLY.

I’m sorry guys – this is NOT Raspberry Pi compatible – STOP CLAIMING COMPATIBILITY. the RPI backup program WORKS. This does NOT.

At this point I noted, having received a heatsink with no glue and having written back to ask if it was necessary, that the main ARM chip was running hot enough to cook an egg. Fortunately I found a little heatsink I had lying around and that improved matters.

I wondered if it was worthwhile doing the usual apt-get update/upgrade – and checked to ensure I had a WIFI signal. Sure enough my WIFI was connected – but I could not browse the web or do anything Internet-related. I got that IP address which means – no.   I even tried putting the address in manually – no.

As I was looking at the WIFI – I noted the volume control top right was on mute. I clicked on the slider to adjust it – nothing – would not come out of mute.

With no audio and no WIFI I thought I’d go off on a tangent and try the recommended ARMBIAN. Aside from (again) overscan on my monitor (which works perfectly with a Pi and various other boards) Armbian came up – with a very nice screen and packed full of utilities (but no SD backup). Once again the WIFI would not have it. I plugged in Ethernet and decided to give the video a try – I opened up Firefox – and went to the BBC iPlayer.  Sorry – HTML5 content will not work – you need the FLASH player – and we all know what getting that running is like.

At this point I was ready to give up… but there was one thing left to try.

Android – a particularly old Android 4.x but I figured it might be worth a try. I followed the instructions which unlike any other board I’ve tried did not include blowing an image with Win32DiskManager but instead a piece of converted Chinese software. I tried several times and failed but eventually got a complete, verified image. Put it into the M2, the Banana Pi info came up and then… blank. The instructions said wait a while the first time – I waited 15 minutes – still blank.

Such a promising start, it looked like an RPI, acted like an RPI but… I have to say, disappointed.

I left this for a while – and having given up totally on using this board for any graphical interface due to the fact  thaty there were SO many issues, I thought I’d have a go with Armbian Debian server, the text-only version which has worked well on the FriendlyArm Neon. After a couple of false starts probably due to using a slow SD, I convinced the M2+ to boot from an 8GB SD with Armbian. Aside from some overscan which made it very difficult to do the initial change of password as the text was somewhat off-screen, I managed to get past that stage and onto WinSCP to do the usual apt-get update and apt-get upgrade which worked a treat. I installed the server version of Jessie – so no graphical desktop but it would be easy to add in. I’m inclined to use larger SD cards if I’m installing a graphical interface but 8GB is more than enough for a command-line only setup even with all the extras I typically add including Node-Red, Mosquitto, SQLITE, PHPLiteAdmin, Webmin etc. by my script.

I ran my install script – see the home control project and although it seemed to run somewhat slower than usual, it did run (ignoring unused variable warnings which are irrelevant but keep popping up in part of the script – I do wish people would keep information to a minimum).

Ok, early days – but it does appear that everything works at least in this simple use of the board – I have yet to look at the hardware in depth – clearly the Raspberrry Pi GPIO stuff DOES NOT work – I installed WIRINGOP as this is after all an H3 board and sure enough – pin 40 – that’s GPIO21 – could be made to turn on and off by turning on and off GPIO number 25.

http://www.orzalabs.tech/2016/08/15/wiringpi-library-on-nanopi-m1/

And so after much trial and error…

  • Pin 3 GPIO2 =   gpio write 8 on
  • Pin 5 GPIO3 =   gpio write 9 on
  • Pin 7 GPIO4 =  gpio write 7 on
  • Pin 11 GPIO17 = could not figure out – default off
  • Pin 13 GPIO27 = gpio write 2 on
  • Pin 15 GPIO22 = gpio write 3 on
  • Pin 19 GPIO10 = gpio write 12 on
  • Pin 21 GPIO9 = gpio write 13  on
  • pin 23 GPIO11 = gpio write 14 on
  • pin 29 GPIO5 = gpio write 21 on
  • pin 31 GPIO6 = gpio write 22 on
  • pin 33 GPIO13 = gpio write 23 on
  • pin 35 GPIO19 = gpio write 24 on
  • pin 37 GPIO26 = could not figure out – default off
  • pin 8 GPIO14 =  gpio write 15 on
  • pin 10 GPIO15 =  gpio write 16 on
  • pin 12 GPIO18 =  could not figure out – default off
  • pin 16 GPIO23 =  could not figure out – default on
  • pin 18 GPIO24 =  gpio write 4 on
  • pin 22 GPIO25 =  gpio write 6 on
  • pin 24 GPIO8 =  gpio write 10 on
  • pin 26 GPIO7 =  gpio write 5 on
  • pin 32 GPIO12 =  could not figure out – default off
  • pin 36 GPIO16 =  could not figure out – default off
  • pin 38 GPIO20 =  could not figure out – default on
  • pin 40 GPIO21 = gpio write 25 on

When I say I could not figure out p particular pin – I mean it would don’t respond to simple gpio commands – I assume those pins have other functions like serial that is not clear on the banana pi diagram. STILL not a bad haul!! A quick Node-Red lookup table will sort these and the NEO out…

NOW – take a look at my updated M1 article which not only has the pins for THAT chip but also now has a solution for general pin control – for non-root users.. https://tech.scargill.net/cheapest-almost-complete-iot-solution/

December 13, 2016 I installed Armbian again after a long break - with my script it installed first time, no problem with everything working - and 4 UARTS appearing in Node-Red - at least 3 of which should be usable.

 

Facebooktwittergoogle_pluspinterestlinkedin

A Brighter Node Red

Just today  – an upgrade notice for Node-Red appeared in my in-box. Upgrade details are here.

What is Node-Red?  Details here – if you’re not using it or at least investigating it – you may be missing out.

Now, the support guys (Google groups here) are VERY clear about required versions of NPN etc. so I suggest you read that update page carefully.  Because I had 2 identical machines (NanoPi M1 as it happens) I thought I’d go for broke. Don’t copy me unless you have a reliable, easy to get to backup – it may well go wrong (mine didn’t) and you’ll be on your own for not precisely following the instructions.

sudo npm cache clean
sudo npm update -g --unsafe-perm node-red

I had already installed the latest (previous Node-Red – maybe a couple of weeks old) – not the default Raspberry Pi version but a manually installed version – along with NPM and the latest NODE and that is NOT what they recommend. I turned Node-Red off (node-red-stop) and used the above commands as PI user (I know, not on a Raspberry Pi but to make my life easy I always make a PI user who belongs to all the PI groups including SUDO)  - I then turned Node-Red on (node-red-start).

Voila. It worked first time.  0.14.0

Now – so what’s special – well, one of my issues with Node-Red has been initialisation of variables – sometimes a global variable can get used before it has been defined!!

The team told me a while ago that the LEFT-MOST tab gets run first – of course that’s no good if your inits are not in the left most tab (I have a tab called “init”). Well now it is because you can SLIDE the tab order about with the mouse – how neat is that!

The DEBUG panel now lets you see message from all over – or just the current tab – which is nice and there are some new nodes and other improvements – I’ll let you read all about them here. The big one that stands out is the LINK node. I HATE making large tabs that are really complicated – but to split them up involves passing messages between tabs – and until now that had to be done the hard way – by global variables (not ideal as you have to poll them) or MQTT or similar. Well now there is a node for THAT as well.

Then I spotted a bug – the exec function would no longer take numbers as arguments – only strings (which is what you’d expect but it had always accepted numbers).  I reported this early evening. Meanwhile someone reported an issue with MQTT…  so the guys amazingly quickly fixed all this.

sudo npm cache clean
sudo npm update -g --unsafe-perm node-red

Erm, no – this time no messages, just accepted my commands but no update.  It was a bit late to expect answers out of anyone… so KNOWING I HAD A BACKUP and stopping Node-Red first then restarting afterwards…

sudo npm cache clean
sudo npm install -g --unsafe-perm node-red

Worked a TREAT – I’m now sitting on version 0.14.3 with all my flows intact. The exec issue has gone away and here we are the next morning, after a few more checks I’ll progress with updating my other installations.

The team are to be congratulated on the work they’ve done on this tool – it costs us nothing but opens up entirely new possibilities to both beginners and seasoned programmers.  Very different image of IBM to the one I had when I was a kid (huge buildings, everyone talking in abbreviations, obscenely expensive leased servers) – at least that’s what I remember  - probably wrong Smile

Marvellous.

Facebooktwittergoogle_pluspinterestlinkedin