Category Archives: Raspberry Pi

Visual Interfaces for IOT

Hollyberry BlynkSo much happening right now – the new Raspberry Pi 3 once again sets the bar with improved performance, Bluetooth and WIFI as standard. With up to 10x the speed of the original Pi we can do even more serious work with these devices.

Please note before proceeding – apparently the Blynk team plan to charge for the use of this app – it is not clear if this means using their server, using a local server or both? And they claim that new widgets will be included in a monthly deal – but WHAT new widgets and in what timescales? – as the Blynk app moves from free to paid I think they will find people want more definition of what is included and when. A one-off fee is one thing – an on-going payment is altogether something else.  http://community.blynk.cc/t/blynk-will-introduce-paid-subscription-in-q1-2016/3177

The ESP8266s are looking (depending on which software you use) to be very reliable to – so that is both the central control and peripheral activity side of things more or less in place.

Where we are still falling down IMHO is the visual interface side – that is – remote control by phone. I’m interested only in Android but I’m sure the same applies to IOS.

At the turn of the year it was looking like a neck and neck race between a small number of systems, node-red-contrib-ui for those inclined to doing a spot of programming and Blynk for those who are more concerned with the visuals.  I’ve looked at several other packages but to be honest either the visuals were just pretty poor or the technology not too well thought out etc.

We’re not there yet.  To my mind the one with the most hope was, until recently node-red-contrib-ui but since January there has been little or no sign of the author and no further developments that I am aware of (though I did hear a rumour that it might become a permanent part of Node-Red – let’s hope this spurs major new development) – this is a great shame as there was a heavy conversation going on with big improvements almost there – and then it all stopped. This is not new – I was convinced at one point that NETIO would be the brave future but development on that seemed to stop some time ago despite being commercial.

That leaves us with Blynk and a few others. Blynk is almost there. It works with the concept of a central server which knows the states of various devices, accepts updates and relays that to the APP. I pushed hard on this to make sure that regardless of whether the App was on or off, the state would be stored and the App would reflect changes when brought back to life. This was considered an edge request by the designers but they implemented it anyway and between that, improvements to the local version of the (small Java) server (which can run on a Raspberry Pi) and some sterling volunteer third party work to bring websocket-based communication back to Node-Red, the App is looking like a clear leader – but not perfect yet.

Blynk[4]I recently contacted Blynk and was assured that at some point they will fix the current issue – that being – they expected people to use buttons for ON and OFF scenarios.  I’d not twigged to this issue until recently when I finally started putting together a set of Blynk controls for my various gadgets.

One of the items I use a lot in my Node-Red applications is my own BIGTIMER (node-red-contrib-bigtimer) and that can set, say a light, to come on and off at set times during the day – for example coming on at lighting up time and off at midnight.  But like all timers – one must have an override facility – and so it is with bigtimer – I can inject text “on”, “off” and “auto” into the input to manually override the timer or send it back to auto.

Well as you can imagine – that is simple to implement with 3 buttons – but having them say “ON” or “OFF” just does not apply – similarly for heating control you might have “up” and “down” buttons.

Blynk say they will not only implement variable text in the buttons but also icon graphics… well, can I put a request in now – if these are to be fixed icons – we need a full set of remote control icons – ie stop, pause, start, ff, rw etc.   For text the best option would be freeform…. or NOTHING – text in momentary buttons just doesn’t make sense to me. A change of colour when being pressed is good and they’ve implemented that.

It would be nice if they had a smaller button as well – and the RGB control is just WAY too big – but looking at the alternatives – Blynk are to my mind still ahead of most.

I’ve looked at several alternatives – but right now most just not cutting the mustard. Either too complicated to setup, too limiting, unreliable or just not finished – and that happens a lot. There is just one out there that might just blow Blynk out of the water and you’ll see my videos and this blog commenting in the future – the app is called Imperihome and thanks to a small number of us working together, there is now good support via Node-Red for this App which is available for both IOS and Android – on the surface it blows even Blynk out of the water. Time will tell.

Facebooktwitterpinterestlinkedin

Raspberry Pi 3 Spoiler

While waiting for my new Raspberry Pi 3 board to arrive so I can blog about it – I thought I’d jot down some thoughts following a conversation with a pal of mine in Canada.

Today, a new Raspbian release came out supporting the 64-bit Raspberry Pi 3.  Hopefully it will be completely backwards compatible – the first thing I’ll be doing is trying out my script and I’ll report back if there are any issues.

The new board has both Bluetooth and WIFI – and of course the thing here is that they are not using any of the 4 USB ports – which means you could be using a Bluetooth keyboard and mouse – and STILL have 4 USB ports available – that pretty much blows away most of the competition – just a shame none of those ports are USB3.

The new NOOBS installer, should you go down that route – now has Windows 10 if that’s your thing. I saw a preview today and it looks ok – apparently both released and insider preview versions are available.

The new 64-bit Arm A8  Raspberry Pi 3 looks once again to have set the bar – it could be that many will be looking at their newly acquired alternatives and pondering putting them in the bin.

Until the postman arrives tomorrow…

Facebooktwitterpinterestlinkedin

Cheap Raspberry Pi

Now before you say anything – they don’t even know I’m writing this!!  Remember when I was in Chicago a while back (well, you’ll only remember if you’re a regular reader)… I bought a Pi Zero and a Raspberry Pi dirt cheap at somewhere called MicroCenter in Chicago.

Well they’re at it again.

http://www.microcenter.com/single_product_results.aspx?sku=586644&utm_source=EMAIL&utm_medium=eNews%26%2332%3BSpecial%26%2332%3BEd%26%2332%3B20162017&utm_content=5134390482&utm_campaign=E3400

So my question to British dealers is – when are you going to get your fingers out and offer us Brits deals like this – that’s £21 for a Raspberry Pi 2  all in…

I didn’t think so. PC World £29.99, Gearbest £27.28, Amazon £29.99 –

Facebooktwitterpinterestlinkedin

Pi Zero Wi-Fi Automatic Reconnect

WIFISometimes I wonder about the thinking processes involved in Debian setup.

Why for example would you NOT want the Wi-Fi to reconnect on failure? What is the point? Yet, that does seem to be the default scenario, particularly odd when it comes to the Pi Zero – which has no option BUT to use WIFI.

I generally attach Raspberry Pi devices to the Internet via a hardwired Ethernet as connectivity is very important to me – not much point in having a super-duper setup miles away only to discover you can no longer talk to it, right?

Yet that is EXACTLY the scenario people will no doubt stumble onto when getting their new spiffy Pi Zero – I’m not going to say low cost because by the time you realise you need a USB hub and WIFI adaptor the price suddenly shoots up towards the cost of competing devices.

However, having had my Pi Zero sitting on the shelf for some time and having now received more than one WIFI dongle (including one with a decent external aerial) I thought I’d give it a go. The little number you see here on the right was £2.59 from Hong Kong and is in keeping with the low cost of the Pi Zero. I also spent £5.59 in the UK on a cheap powered USB hub because article after article suggested that running the WIFI without a hub was not a good idea (since verified and further backs up my doubts about the benefit of having a Pi Zero in the first place).

USB HubSo I took an old-fashioned Pi B and set that up with Wi-Fi (without the hub) – copied the FLASH from its rather large original SD to a micro SD and plugged it into the Pi Zero. Plugged in the cheap USB powered adaptor  – plugged the WIFI dongle into that and applied power.

Worked a treat. Lovely. Tried without the hub, no joy. But of course this is when people normally stop only to discover often days or weeks later that this is NOT a good enough solution.  I did note that very occasionally the Pi Zero would reset – the cause of this was a very long, thin USB power lead – funny that this never had been a problem with the Pi2 – but shortening the lead very definitely solved the problem.

So with everything working, To test reliability, I simply pulled the Wi-Fi dongle out – and put it back in. The Wi-Fi was DEAD. After 5 minutes still no connection.  So I rebooted the Pi and back came the connection. The next test was to pull the power to the router (does anyone REALLY live in a place where none of this EVER goes wrong?). Router back on – waited 5 minutes and… sure enough – absolutely NO Wi-Fi.

I started to scour the web – BOY are there some convoluted solutions out there – one might suggest  some were written by sadists. Come on guys – this is a tool, not life itself – something SIMPLE is needed.

And so it was I stumbled onto this page.

http://raspberrypi.stackexchange.com/questions/4120/how-to-automatically-reconnect-wifi

Here’s the important bit – no new files.  I was talking to the Pi via winSCP and of course as Pi user you don’t have permission to wipe your nose so I made a slight mod to the Pi connection – in winSCP, under advanced, SFTP I put “sudo /usr/lib/sftp-server” into the SFTP SERVER panel – and reconnected – this gave me elevated control to actually let me edit files without needing a degree in Linux using one of the many awful command line editors therein.  

As per the link above..

In /etc/network/interfaces I put:

allow-hotplug wlan0

iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

I saved that and rebooted – all was ok. I pulled the WIFI dongle out – winSCP griped. I plugged it back in, 1 minute later, winSCP reconnected automatically. I turned off the router – winSCP griped. I turn the router back on – just over a minute later, winSCP reconnected automatically.

Now why isn’t that the default setting?

For my next trick – in Debian Jessie and with the graphical interface set up, I tried swapping routers – I have 3 access points as my home has lots of thick walls.  I swapped from one to the other and was asked for a password. Ok, fair enough. But then when swapping back to the original, I was asked for the password again. WHAT?? I’d already given it the password, why would it want it again?

Well it turns out that all is ok as the graphical interface had actually saved both settings in /etc/wpa_supplicant/wpa_supplicant.conf

I’ve obviously altered my two SSIDs and passwords.  I guess you could put as many of these as you like in here manually.

network={
    ssid=”aaaaaaaa”
    psk=”xxxxxxxxxxxxxxxxxxxx”
    key_mgmt=WPA-PSK
}

network={
    ssid=”aaaaaaaa”
    psk=”xxxxxxxxxxxxxxxxxxx”
    key_mgmt=WPA-PSK
}

Lovely.  It really is worth asking however, is it really worth the saving of having a Zero when it needs a USB lead and hub for it to be of any use, not needed with a P2 which is also faster.. or one of the alternatives out there. There is also no 3.5mm jack for audio on the Pi Zero.

Still at least I can now use this for something…

IanChilton on Twitter just sent me this link – which I have to say on the surface of it is pretty damned interesting for the Pi Zero – any thoughts on this? The price is stunning and it would seem to be JUST what the Pi Zero needs? Does not seem to come with a power adaptor – but it does have a little hole for one in the back!

http://www.aliexpress.com/item/Hot-marking-Micro-USB-to-Network-LAN-Ethernet-RJ45-Adapter-with-3-Port-USB-2-0/32544477817.html?spm=2114.30010308.3.2.YZfEDZ&ws_ab_test=searchweb201556_3,searchweb201644_3_505_506_503_504_301_502_10001_10002_10016_10005_10006_10003_10004,searchweb201560_3,searchweb1451318400_-1,searchweb1451318411_6450&btsid=7667f665-95f8-487d-9525-af3aa4c3a948

So.. do we actually NEED to use WiFi in the ZERO or is this a viable and practical alternative?

By the way if you see that 4 port USB hub I photographed above on Ebay – avoid it  – we were sitting watching TV tonight when the little plug-in-the-wall power supply that came with it – blew up!!

Facebooktwitterpinterestlinkedin

Pi Zero and the USB Problem

The £5 Raspberry Pi Zero has great potential as a cheap gadget but it has one major problem – lack of USB. So it has no ETHERNET – your ONLY option is WIFI – but will the WIFI work and how the HELL are you supposed to figure that out when you only have ONE USB socket. You can have mouse, or keyboard but not both.

IF you happen to have a USB hub lying around you’re all set – but if not, here’s a GREAT idea from a pal of mine…   if you happen to have an original Raspberry Pi (ie NOT the Pi2) – plug the WIFI into that, set everything up on that – then transfer the SD and the WIFI over to the Pi Zero.

SIMPLES – I really don’t understand why I didn’t think of that first – well done David. I just happen to have one old PI lying around and I was looking to giving it a job! Node-Red on a Pi Zero? Keep an eye out for further news.

Facebooktwitterpinterestlinkedin

Raspberry Pi Volume in Node Red

Over the course of my many experiments with the Raspberry Pi and similar I have had constant problems with volume – I remember wasting ages with the Orange Pi – no WAY could I get sound to come out of the analog output.

Things are a bit better with the Raspberry Pi if you’re using the graphical desktop otherwise you have to get to grips with AMIXER.

And so it was that I’ve been trying to get to grips with volume control in Node-Red.

The command to control the analog output(3.5mm jack assuming you have nothing connected to the HDMI output) is simple enough..

amixer cset numid=1 – 100%

Two problems with this – 50% is almost silent.. and that % sign isn’t ideal.

So a quick SUBNODE…

Volume Control on Raspberry Pi

The content of that function (yellow) was entirely experimental

msg.payload/=3;
if (msg.payload>0) msg.payload+=66;
msg.payload+=”%”;
return msg;

Basically unless the volume is 0, I shove it right up into the 66+ region. I then add % onto the end and fire that into an EXEC node containing the following:

tmpF123

Note the space at the end of the command… so that appending the incoming message will produce our desired volume control levels with only a number 0-100 input.

And here’s my test.

Volume control on Raspberry Pi - Peter Scargill

At the top – a quick speech test (I’ve described Ivona speech previously in the blog)

And a range of test values – you can use these mid-speech. Works a treat.

So now when powering up Node-Red I can ensure a fixed volume and have scope to have different levels for different applications – a low level for general speech or sounds – and a high level for, say, alarms.

Simples.

Facebooktwitterpinterestlinkedin

Raspberry Pi Zero

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

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

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

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

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

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

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

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

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

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

Let’s take a look shall we, at the bargains available in the UK right now. http://cpc.farnell.com/raspberrypizero?&ICID=I-Rpizero  – a mere £10.54 + VAT which comes to £12.65 – or a mere NINETEEN DOLLARS. Oh yes, you get a couple of cables with that – you know, the ones you could pick up for a couple of quid from Ebay.

Pi Hut http://thepihut.com/products/raspberry-pi-zero offer the basic Pi Zero at £4 which is a little more like it – but it is all irrelevant as they are out of stock.

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

For around £6 you could buy the MagPi magazine and get a Pi Zero for nothing!! Except you can’t  as they are out of stock. http://swag.raspberrypi.org/collections/magpi/

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

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

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

Facebooktwitterpinterestlinkedin

Some thoughts on Node Red variables

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

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

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

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

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

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

context.global.stat_inside_temperature

etc..

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

A global object containing everything to do with my stat.

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

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

context.global.stat=stat;

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

context.global.stat.display_temperature;

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

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

var stat=context.global.stat

Hence

stat.display_temperature;

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

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

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

msg.payload=JSON.stringify(context.global.stat);

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

context.global.stat=JSON.parse(msg.payload);

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

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

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

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

tmp7866

Facebooktwitterpinterestlinkedin

Talking Raspberry

Updated 21/DEC/2015

This entry is now DEAD. Google have changed the goalposts and removed the API access for their language translation and text to speech system so that the base program behind this work – a program called Normit – is no dead in the water. I’m doing an update blog without the Google service.

This could be a good day, my WIFI problems have disappeared (for now anyway) all on their own and I’ve given up on the Orange Pi PC until someone comes up with a solution for the missing sound ( had some other minor issues – life’s too short). I have had a couple of successes recently – one of them being…  getting the Raspberry Pi 2 to SPEAK. Specifically giving Node-Red the power of speech.

If you’re not using Node-red – or rather if you don’t have NodeJS on your Pi, then this won’t be of much interest! (I did get Node-Red running on the Orange Pi but no sound) – if you are, read on as this is a winner.

So first things first – this is is an example of what I started running on my Raspberry Pi 2… this particular bunch or injects just sit on the Node-Red desktop and can be accessed at the press of a button. The purpose of this, for someone living in Spain but not having a clue what to say to anyone ringing me up in Spanish to inform me of a delivery, is to give me a starting point at talking to them.

Spanish

So I press one of the buttons on the left – and the Pi talks in clear Spanish through the speaker. My next application is more serious – it tells me when my ESP8266 boards have logged in by extracting their ID names from the incoming MQTT response (parser – trivial) and blasting out the text as speech. I was having WIFI issues for a while and it helped to know when the units were in trouble and continuously logging back in.English

In this instance the responses play back in English. So how do we get from a non-talking Raspberry Pi to this?

First things first you need to go look for normit (something like npn install normit –g) and get that running on the Pi at the command line.  What this neat little package does is to take some text and send it off to Google translate, get an mpeg back and play that. You’ll also want mpg123 which I believe is apt-get install mpg123  (you may need to use sudo if you are not root).

So the test is this..

normit en en “hello there”

That will visually respond with the phrase “hello there” onscreen visually. To change that to Spanish:

normit en es “hello there”

and you’ll get the Spanish version.

If you’ve installed mpg123 correctly and your sound is working…

normit en en “Hello there” –t  will play the sound back through the speaker – there’s a slight delay depending on the length of the sentence which should I believe be no longer than 100 characters.

That in itself is quite useful.

in Node-Red there is a function called EXEC (under advanced – and thanks to the Node-Red guys for helping me out with that one).  It will run command line stuff (you can see what’s coming next, can’t you…)

Grab the EXEC node and fill in as follows:

exec

So now if you pass a message such as en en ‘hello there’ –t  in your msg.payload to this node via, say an inject node – you’ll get speech. EASY!!  And thanks to the Node-Red guys for pointing this out to me. Don’t try “spawn” mode and don’t worry it won’t hold up Node-Red – I can prove that by sending 2 messages quickly – it will play two at once (I’ve a fix for that lower down). Ignore the outputs of the EXEC node, you don’t need them.

So that in itself is ok, but you might want to take that a little further to make actual use more flexible and easier. I did. I also have a package called moment on my Pi which make nice time and date formatting.

So in my case the next step was to add a function to this..

image

The contents of the function are as follows – you might fancy something different.

var moment=context.global.moment;
var lang=’en en “‘;
var timeadd=””;
var dateadd=””;
if (msg.topic.indexOf(“time”)!=-1)
  timeadd=’Time:, ‘ + moment().format(“h:mm a “)+ ‘.’;

if (msg.topic.indexOf(“spanish”)!=-1)
  lang=’en es “‘;

if (msg.topic.indexOf(“date”)!=-1)
  dateadd= ‘Date:, ‘ + moment().format(“dddd,,, MMMM Do YYYY”)+ ‘.’;

msg.payload= lang + dateadd + timeadd + msg.payload + ‘” -t’;
return msg;

So now, in the simplest case the input to that function might simply be…. hello world. The function adds on the technical bits and quotes.

Would it not be nice to package that up – seems like that’s what I’ve done, doesn’t it.   Create a SUBFLOW in Node-Red and dump those two items (the function and the exec  node) in there. Edit the name of the subflow to “speech” and add an input to that function. This really is a lot easier done than discussed. I thought it was going to be mega-hard but it’s not. Think of it as a visual macro.

subflow

 

Lo and behold you have a drop-in box you can use for speech in English or Spanish (or, clearly any language you like).

my speech subflow

Heading back to my Spanish example here’s one of the input INJECT boxes I showed you at the top…

inject

I’ve put the text I want to say in the payload (one sentence please, for some reason Google doesn’t like a full stop in the middle of something – you could of course without too much effort fix that – split the text up and fire out one after another – getting the delay between the parts right could be fun though) – and used the topic to add in options such as “spanish” “time” and “date” – I’m sure you’ll think of others – if you come up with winners do write in.

So now, from a simple command line tool we have a great drop-in for Node-Red projects to get verbal feedback.  And the sound, though with a strong American accent – really is very good.

Add in speech recognition and a little logic and you have your own Hal-9000 – except you could miss out the bit about not letting people back into the spaceship.

The only issue with this is that as this stands, there is no way to stop the unit from sending messages simultaneously – fine for my Spanish stuff, not so good for multiple simultaneous logins of my little ESP8266 boards.  Now, we can’t EASILY tell if a process is finished, but we can schedule messages, so that messages could be put in a queue and that queue checked, say, once every 3 or 4 seconds. If your messages are not ultra-time-critical, then you could use that solution.

Here’s a variation of my flow…

queue

Note the difference. In this version, an inject node is used to send a blank message every 3 seconds. If a message comes in – it is put in a queue, if a blank message comes in the queue is checked – and speech sent out if there is anything there, using the wonderfully elegant combination of arr.pushj and arr.shift – see the code. The only exception being if the message is urgent in which case it is sent immediately.

The code:

if (typeof context.arr == “undefined” || !(context.arr instanceof Array)) {
        context.arr = [];
}
    if (msg.payload!==””)
{
    var moment=context.global.moment;
    var lang=’en en “‘;
    var timeadd=””;
    var dateadd=””;
    if (msg.topic.indexOf(“time”)!=-1)
      timeadd=’Time:, ‘ + moment().format(“h:mm a “)+ ‘.’;
   
    if (msg.topic.indexOf(“spanish”)!=-1)
      lang=’en es “‘;
   
    if (msg.topic.indexOf(“date”)!=-1)
      dateadd= ‘Date:, ‘ + moment().format(“dddd,,, MMMM Do YYYY”)+ ‘.’;
   
    msg.payload= lang + dateadd + timeadd + msg.payload + ‘” -t’;
    // append new value to the array OR play it now if urgent
    if (msg.topic.indexOf(“urgent”)!=-1)
        return msg;
    else
        context.arr.push(msg.payload);

}
else
{
    if (context.arr.length)
    {
        msg.payload=context.arr.shift();
        return msg;
    }
}

And just set the inject node to repeat every 3 seconds (well, that works for me) and send a blank message OR add into the topic the word URGENT and it goes out straight away. SIMPLES!!!

And if you think THAT’s good – check out THIS version that ALSO handles .mp3 files!!!  Simply put a file path, say /usr/audio/alert02.mp3 into the subject line – (option of “urgent”  still remains) and you can add your own favourite star trek BEEPS!

Here’s what it looks like…

mpeg handling

If you need beeps….. http://www.trekcore.com/audio/

And here’s the code – I’ve also added an ALERT option to play back both .mp3 and the voice file (not I’ve embedded a specific file in there as I’m out of fields – I may write a node for all of this yet):

var frompush=0;
if (typeof context.arr == “undefined” || !(context.arr instanceof Array)) context.arr = [];
if (msg.payload==””) if (context.arr.length) { frompush=1; msg=context.arr.shift();  }

if (msg.payload!==””)
    {
    // if not urgent just push but not recursively
    if ((msg.topic.indexOf(“urgent”)==-1) && (frompush==0)) { context.arr.push(msg); return; }

    if (msg.payload.indexOf(“.mp3”)!=-1) return [null,msg];
    if (msg.topic.indexOf(“alert”)!=-1)
    {
    var msg2 = {
                payload : “”,
                topic : “”
                };
        msg2.topic=msg.topic;
        msg2.payload=’/usr/audio/alert02.mp3′;
        node.send([null,msg2]);
    }
    var moment=context.global.moment;
    var lang=’en en \”;
    var timeadd=””;
    var dateadd=””;
    if (msg.topic.indexOf(“time”)!=-1)
      timeadd= moment().format(“h:mm a “)+ ‘, ‘;
   
    if (msg.topic.indexOf(“spanish”)!=-1)
      lang=’en es \”;
   
    if (msg.topic.indexOf(“date”)!=-1)
      dateadd= moment().format(“dddd, MMMM Do YYYY”)+ ‘, ‘;
   
    msg.payload= lang + dateadd + timeadd + msg.payload + ‘\’ -t’;
    return [msg,null];
    }


And all of that was fine – until I started to experiment with multiple message – at which point it all went to hell. For reasons I’m not yet sure of – sending an entire object to an array and pushing and shifting doesn’t work that well. I made a slight change shown in red below and fixed the problem.

var frompush=0;
if (typeof context.arr == “undefined” || !(context.arr instanceof Array)) context.arr = [];
if (msg.payload==””) if (context.arr.length) { frompush=1; msg.topic=context.arr.shift();  msg.payload=context.arr.shift();  }

if (msg.payload!==””)
    {
    // if not urgent just push but not recursively
    if ((msg.topic.indexOf(“urgent”)==-1) && (frompush==0)) { context.arr.push(msg.topic); context.arr.push(msg.payload); return; }

    if (msg.payload.indexOf(“.mp3”)!=-1) return [null,msg];
    if (msg.topic.indexOf(“alert”)!=-1)
    {
    var msg2 = {
                payload : “”,
                topic : “”
                };
        msg2.topic=msg.topic;
        msg2.payload=’/usr/audio/alert02.mp3′;
        node.send([null,msg2]);
    }
    var moment=context.global.moment;
    var lang=’en en \”;
    var timeadd=””;
    var dateadd=””;
    if (msg.topic.indexOf(“time”)!=-1)
      timeadd= moment().format(“h:mm a “)+ ‘, ‘;
   
    if (msg.topic.indexOf(“spanish”)!=-1)
      lang=’en es \”;
   
    if (msg.topic.indexOf(“date”)!=-1)
      dateadd= moment().format(“dddd, MMMM Do YYYY”)+ ‘, ‘;
   
    msg.payload= lang + dateadd + timeadd + msg.payload + ‘\’ -t’;
    return [msg,null];
    }

Now, if someone comes up with a way to detect the end of speech instead of using a timer – I’d be most grateful for the code – a fixed timer is, ok, but not ideal. Another possibility is to look at the number of characters in the string and arrange a time delay based on that – as clearly longer sentences take longer to speak – and it would be good to fire off a sentence before the previous one is finished – as it takes time to download the mpg file.

 

Facebooktwitterpinterestlinkedin

Node-Red Madness

As of right now – this is page one of my node-red setup – today I managed to get text to speech running on the Raspberry Pi (not on the Orange Pi as that’s not having sound at all) and note at the bottom right – my latest additions ready for Spanish delivery phone calls…. This does not include the reporting page (to Grovestreams), initialisation, websockets stuff etc….that adds at least the same again. I can see this just growing and growing.  I now get verbal feedback when boards log in – much better than checking flashing lights..

image

Facebooktwitterpinterestlinkedin

Raspberry Pi Monster Script Part 3

I’ve updated the script – gotten rid of MYSQL – too many questions about SD life – and I have to say, SQLITE3 – though slightly different takes mininal modification of SQL assuming you’re doing things like logging of data and relatively straight-forward queries – it really is worthwhile. Apart from admin there are no passwords as it is not meant for massive, multi-user environment on a big server – it is meant for jobs just like this. The file is a simple file that can be moved about and it works well.  Even my PHP queries took only minutes to change to work with SQLITE3 and recent PHP versions support it directly so no need for extra libraries.

I’ve also taken out RabbitMQ in favour of Mosquitto as I needed websockets compatible with THINGSTUD.IO and RabbitMQ wasn’t having it – so after a lot of messing around I finally got websockets and Mosquitto running together and compatible.

Finally I have added support for speech – SERIAL and GPIO – all of it works. I’ll put Node-Red examples on the blog as time goes on.

“The Script” – has since been updated considerably and you should refer to this article

Facebooktwitterpinterestlinkedin

Raspberry Pi Processor Monitoring Widget

Raspberry Pi CPU Monitor

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

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

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

Yoiu might want to search for rCPU and Smoothie Charts.

Facebooktwitterpinterestlinkedin