Quantcast
Channel: Scargill's Tech Blog
Viewing all 1386 articles
Browse latest View live

PHPSYSINFO on Raspberry Pi

$
0
0

Just to save anyone getting caught out with out of date information, if you want to install phpsysinfo on your Raspberry Pi 2 or 3 running Jessie… the picture below is self-explanatory – simple to install and some worthwhile info.  RPI-Monitor is another useful monitoring tool.

sudo apt-get update && sudo apt-get upgrade (if not done recently)

sudo apt-get install -y apache2 php5 libapache2-mod-php5 (if not already done)

sudo apt-get install -y phpsysinfo

sudo ln -s /usr/share/phpsysinfo /var/www/html

Then enter into your browser:

http://raspberrypi/phpsysinfo

and you get something like this rather nice display

phpsysinfo

facebooktwittergoogle_pluspinterestlinkedin

The Simple Serial Terminal revisited

$
0
0

My prototype ESP-03 board“Got up early one morning….”  well, actually it was one evening a couple of years ago, I was frantically struggling to use the Arduino serial monitor to test the then new ESP-01 modules and not getting very far, one line at a time, repeating the same typing mistakes over and over…  and I decided I needed something better. Windows programming was not something I’ve done for a while (as against web and App programming). The last time I wrote anything major outside of embedded C was back in the dark ages of VB6 and so I was expecting to fail completely with Visual Studio.  I managed to find some code to take data from the serial port, put it up on screen and vice-versa and the funny thing is it all started coming back to me. The project that was going to take me the drinking time of a cup of coffee took all night and I was so happy with it I stuck a copy on the web. I have to say version 0.1 looked pretty naff.

(This article was originally written in 2014 but I’ve updated it because I desperately needed a better serial terminal for what I’m doing now and as this was already 90% there I upgraded it to VS 2015 and added some extra features).

tmp987ABack to programming the pesky ESP8266 chips and once again I found myself getting more and more frustrated. I needed places to store short setup texts temporarily, I got annoyed when as happened one night, the power went off mid-stream and I lost all my temporary notes and… well, if you’ve worked on these chips, having to discover the bugs as you go along and repeating the same stuff with minor variations until you got there, you’ll know exactly how I feel. On top of that, the interpreter hates you sending stuff quickly and whenever I looked it up on the web I kept getting recommended to use some Linux program or other – sorry guys.. NO.

Fast forward a day or so where I realised just what an amazing little tool I’d put together with a few late nights behind me (and I mean LATE). Now, before I say any more, apologies to anyone on Windows XP – I can’t help here because the Microsoft environment really isn’t supporting XP any more – it’s not me, the code  just won’t work on XP. As for the Linux guys, well, you’ve probably got your own tools and they’ll be far better so I’m not worried about you so this is for Windows 7-10 – it was originally tested on 7 and I’m now using it on 10.

So specific needs when messing with these chips – and especially when using the Lua interpreter – you need to be able to send blocks of code to the chip over and over as your program evolves and you need to be able to store temporary solutions, lots of them. The Lua interpreter has a strange file system that means when creating a file you need to wrap your code in the most horrible mess which makes it almost unreadable – just what you don’t need when bugs creep in. You need delays between each line you send, maybe up to half a second as the interpreter does not like being sent serial data when it’s busy. You also need to be able to blow firmware onto the boards but I haven’t gotten that far yet and anyway there are some decent Windows tools out there to do just that.

And so here we are two years later – I have the tool I need to do the job and I realise I’ve done a pretty awful job of documentation. So above right you should see the editor. The most important bits are the two big windows – on the left is the area you type in – multi line – and on the right is the output from the serial line – i.e. what comes back from the chip. In the simplest case you set up the serial port you want, ensure it’s set to 9600 baud for Lua programming – I use 115k for everything else but I’ve also included 78k for studying ESP power up rubbish – which in fact is debug info at 78k, select “serial – open” and you’re all set (I’m assuming you have an FTDI or similar on your USB lead, talking to the serial on the ESP8266 device, I’m also assuming you fed 3v3 or 5v to the device as appropriate).

Whatever you type in the left window is non-volatile, i.e. it’ll still be there after you blow up your serial port and have to reboot the computer.

Disclaimer: if any of the above or the use of the terminal breaks your computer, it’s not my fault. I’m providing this freely just because I’ve no reason not to but without support.

The top panel

So let’s take a look at the top first. I have deliberately kept this as clean and simple looking as possible as you really just want to get on with coding and not worry about some pesky program – but there are some basics if you want to make good use of this. The file system is easy enough – you might want to store what’s in your left window – your latest all-singing routine or just a bunch of nonsense – that’s up to you hence file – save. Find a suitable directory to store your stuff – the dialog is bog-standard. For retrieval – you have two options, load and append. The former will overwrite what’s in the window, the latter will append to what’s there – so you can store a load of routines and build up something new the easy way.

tmpCE0DSerial is even simpler – open or close the port. When open you’ll find some controls don’t work – like changing the baud rate for example. When closed most of the bottom control panel is missing..

Notepad is interesting…yes, no less than 10 pretty coloured notepads (non-volatile) to store snippets in – nothing clever about these, you can just copy and paste to and from them in the normal way.

I normally have several projects going on and find it handy to have stuff lying around – this beats yellow sticky notes full of code any day. There’s a big CLOSE button at the bottom to get rid of these.

NotepadClear- well you can clear the notepads or your left or right windows – and help – well it’s a picture of me – the idea of writing a complete help system for this just filled me with horror.

So down at the BOTTOM of the screen… assuming you have the serial all turned on you can “Send Window” – i.e. send the contents of your left window off to the serial port – it will send it one line at a time with a delay between each line specified at the top right in milliseconds, defaulting to 400ms – but whatever works for you.

I’ve coloured the individual panels just to try to help for when you’re in a hurry – I tried to colour the tabs but Microsoft isn’t having any of it up to now.

If you select some text in the normal way in that left panel you can press the “Send Selected” button and only send the stuff that is highlighted – OR you can “copy” from just about anywhere and send whatever is in your clipboard… that’s awfully handy.

tmp153F

Then there are those notes.. N1 to 10 let you send the entire contents of any of those notepads out of the serial.  Finally there is a one-line window which you can send directly with the “Direct” button and that has autocomplete for some of the more useful commands.

To the right there are some presets, 9 in all – and in SETTINGS you can define their names and what gets sent out.  And that takes us to settings.

tmp14CE

Firstly you’ll see the 6 preset buttons – their titles and contents – note you DO have to press OK to save these – most things outside of this SETTINGS box just save automatically. Auto prefix and suffix I suggest you leave be unless you’re NOT messing with Lua and the “Auto prefix/Suffix” tickbox determines whether or not you use this – essentially if “File.open” is see starting at the LEFTMOST character in your input window, these prefix/suffix characters will be added to your line as they are being sent out until the system sees a “File.close” again starting in the leftmost column of your input window.

“Arduino DTR” – well that’s for those of you who want to use this terminal with your Arduinos (you may be working with the Espressif AT firmware for example)  – that’s the bit that resets them when you open the port. It just flicks the DTR line temporarily on open – nothing more. Autoclear – tick that and you’ll see the right window cleared every time you press the send button – just preference really. Lua comment removal is turned on by default (—) – you can turned if off – and “Retain blank lines” is new, just something for the future. Normally, most blank lines never make it to the right window.

And that is that, really – nothing much else to tell you about the program – I hope you find it useful – I have – and no doubt I’ll add more in time.

The two main windows have right-click functionality – clear, copy and paste.

Ok, here’s the dropbox link – not sure how long this will stay valid but you can always let me know if it disappears.

facebooktwittergoogle_pluspinterestlinkedin

Blowing the Home Control 2016 Code

$
0
0

Hackitt and BodgittThis is for the staggeringly few (that’s an assumption) people who’ve been trying out my software (or thinking of trying it out) on the ridiculously cheap (£1.40) but very reliable and comprehensive ESP12 and those who’ve gone ahead and gotten some boards we made – all referenced in earlier blogs.

Essentially the assumption here is that you have an ESP-12F-based board of some description and that GPIO0 is used as a programming button (held to ground to program etc) – and also as a setup button. All other I/O pins are available for one use or another including GPIO16 – take note of other blogs describing wiring and power unless you’re using something like a node-mcu board which just plugs into USB. The software works with my Node-Red software – again described in the home control – what’s new here is that OTA now works and you don’t need a development environment to program up the code – I’ve now tested ROMS which I developed on the unofficial Development Kit in Windows. The software will react to MQTT commands and also commands coming into the serial line at 115k baud (serial same as MQTT but no topic required).

tech.scargill.net - home controlToday I’ve been working with Richard Burton as I’ve been having problems with RBOOT – his software which allows for OTA when developing in C on the ESP8266.  To cut a long story short I told him about my problems – he looked at my software, he spoke to Espressif – he made changed to RBOOT – I replicated and tested – and the end result is RBOOT has an update which will allow it to work with the very latest Espressif SDK which happens to be what my home control 2016 software is working on.

With that working (including OTA from an external location) I thought I might try taking the ROMS and blowing a chip from them rather than from the editing system – that way others can benefit.

tmpF05BWell, I went to get the NODEMCU flasher which was always good – so after a couple of blind alleys – I got to this link..

As you can see, the RBOOT rom loads at 0x0000 and our current code runs at 0x2000. Unlike me, make sure BOTH ROMs are ticked on the left.. as the first one is so short it shows no sign of activity. I found I could flash at 46800 baud, you may or may not wish to play safe at 115k baud.

So – you blow the software, now what?

A reminder – what will this do?

  • Turn outputs on and off
  • Read inputs
  • Handle RGB Serial LEDs (up to 300 of them assuming you have enough 5v power)
  • Handle PWM 12v LEDs (assuming you have a 12v source and driver hardware such as Mosfets)
  • Act as a LED clock (and a nice one too) with 60 serial LEDs.
  • a TON of other things including handling DS18B20, DHT11, DHT22, talking to Nextion displays (see the Serial Nextion blog) and WAY more – all in the Home Control blog.

But first the unit needs to be setup. After programming and then resetting or power-cycling the ESP12 (suggest hooking a LED and resistor to GPIO13 and down to ground) – the light will start flashing – within a second or so – hold GPIO0 to ground for say 10 seconds and let go (DON’T press for the first 100ms of turning on – JUST after turning on or resetting will do – if you come in early it will go into programming mode – of course if you don’t program it, no harm done – just reset and try again).

NOW you can access the board with your mobile phone WIFI as “hack-Setup” and once connected use the phone browser to go to 192.168.4.1/wifi/wifi.tpl and you get that nice setup on the right above which needs at least one router SSID and password, two if you have them available (second is a backup) – the address of an MQTT broker and username and password and that’s really all that is essential to start off.

Once everything is up and running , the LED on GPIO13 should be flashing very briefly (i.e. off most of the time) – a future version will use an RGB LED to give more meaningful use (yellow power up, green working, orange working on it, red dead – throw in the bin etc).

You can now talk to the board via MQTT… or the serial port at 11500 baud (you could use my serial terminal.

If using the serial, fire {debug} at it – if using MQTT – then assuming you’ve given it the name “fred” then the same command would be – topic:  fred/toesp and the payload would be {out4;1} or {out4:0} to flick GPIO4 on or off (or if your board is mis-labelled as some are – GPIO5).   The Home Control blog entry goes into the rest of this in detail.

The rest is up to you.  I use this with my Node-Red software and I have a node for setting up the time and date on the boards…  it is called node-red-contrib-esplogin

Node-Red controls - Peter Scargill

That’s it for now… I’m quite chuffed the OTA now works. This of course is directly relevant to the Nextion WIFI Display project.

Oh you can get the two BIN files from:

www.scargill.net/rboot.bin

www.scargill.net/romx.bin

facebooktwittergoogle_pluspinterestlinkedin

PubNub versus MQTT

$
0
0

Today I’ve been playing with PubNub. This is a something-vaguely-like MQTT like service.   Now if you’ve read my articles you’ll know I’m not keen on public services for IOT – what happens if they go down? That’s your fridge on the blink… but this one looks interesting because they have backup servers on multiple continents. But let’s read on…

A simple example of the use of Pubnub is as follows:

I’m in Node-Red and I’ve added the Pubnub nodes. All they want off me are my credentials which I got when signing up for a free PubNub account.

tmp87A3

I put the two long numbers into one of the nodes – and that’s it. Sending a timestamp or simply “hello” payload to the lower PubNub node results in the message appearing instantly on the upper node and going out to debug on my screen. You don’t get any simpler.

So – how does the free option work? Well, you can connect 100 devices an send up to a million messages a month. Data is encrypted.  So how good is 1 million messages a month?  I probably send maybe 10 MQTT messages a second over my two setups – one in Spain one in the UK and so 10 * 60 * 60 * 24 * 31 = 26 million messages a month – so clearly were I to consider this as an alternative, the free account would be no good – and sadly the next step up is 5 million messages at $149 a month…. and then it gets really silly at $799 a month for 30 million messages… so clearly this is not going to replace unlimited MQTT messages on my own server for free.. However, for sending stuff back and forth at a more leisurely pace, say no more than one message every 3 seconds on average, it is free. Messages can be up to 32k in length but as that includes any encoding they suggest knocking that down by maybe 5k. To keep all messages in a single TCP packet for speed, consider keeping messages down to <1.5k.  Message length includes the name (topic).  Unlike MQTT topics you can’t use slashes. Prohibited characters in names include ,/\.*:

Oh and one BIG difference between MQTT and Pubnub is that in MQTT you can elect to simply listen for certain messages with wildcards – doesn’t work that way in PubNub… you get everything coming in for that particular key. Still – nice to know it is there.

I did kind of expect there would be a load of Android test applications to use PubNub in the way you use Pushbullet – but I’m not seeing anything at first glance. Am I missing something?

For more information go to https://www.pubnub.com – LOTS of SDKs including stuff for ESP8266.

facebooktwittergoogle_pluspinterestlinkedin

Pong Detection

$
0
0

These are good fun – FC-22 Harmful Gas Detector

tmpDE86I just received 2 of them – they run from 5v, using around 0.7 watts.  I just bought them on a whim as we were busy joking about cat poo. At the time our new cat Chloe (ragdoll) was having stomach problems and smelling like one’s worst nightmare. So as you do I sent off for these.

tmpE745So I plugged it into my NSCOPE this morning…. It has 4 connections – ground, +5v, analog out and digital out. There’s a tiny pot on the board and you can set the trigger level for the digital output – so that really doesn’t mean much – but the analog output is fascinating.

While the digital output sits at 5v by default, the analog output in my office generally sits at around 0.5v

As you do, I opened just about everything I could find in the office. It did not seem much bothered by an open flame, but it did NOT like acetone. My freezer spray seemed to have a slight effect but the best one was Evostik – I hardly had the top of and it was going mad – and took several seconds to settle down, picking the smell up in the air at about the same time as I was feeling dizzy (I had some floor foam tiles to stick on wood the other day and so for the first time in many years I bought a can of Evostik – I’d forgotten just how horrible that stuff is – it works a treat but the smell makes you feel  ill).

Apparently it also picks up propane, hydrogen and natural gas. I tried the nearest I had – butane from my blowtorch and sure enough – immediate reaction.  Oh – and Ronseal Stain Block – which contains acetone – picked that up immediately.

I could see one of these sitting permanently in my workshop. Around £1.20 from Ebay (for some reason DealExtreme want £4 for them and some guy in Britain, proudly displaying the British flag was trying to get £8 for the same thing!!)

At £1.20 is it worth NOT having one in your workshop/office!  I’ve not yet tested it on cat-poo – I guess I’ll have to wait for the opportunity.

facebooktwittergoogle_pluspinterestlinkedin

Duff lights

$
0
0

corn lightsAs everyone in here is into technology – and as that means you’re more than likely to buy LED lighting for your home, I thought I’d take this opportunity to issue a helpful warning – especially for those in 240v AC areas.

While I have generally had great success with modern LED lighting – there is a particular style of light I’d like to flag up here. See the photo – these are often referred to as CORN lights. They come in different sizes and from different suppliers, some Chinese, some home-grown – but from what I’ve seen they all look so similar that they must surely be made by possibly one manufacturer. I could be wrong.

I’ve purchased perhaps a couple of dozen of these over the past couple of years – and EVERY LAST ONE of them has ended up in the bin.  I thought at first I’d just had a bad batch and bought from a separate supplier…then I thought I must be using them in too enclosed an environment as we all know LEDs don’t like heat.

But no, this last one came out of an outside lamp – and right now it is cold in Britain – there is no way this overheated.  My suspicion is that the LEDs are not well matched and being wired in series, it only takes ONE dead LED to bring the whole lamp to a standstill. I assume they’ve done the power this way to save cost.

Either way these are not, as it were, worth a LIGHT. See the picture, you’ll note on a couple of the lights a little black dot in the middle – that is the beginning of the end.

They’re all gone now and I won’t be buying more. I hope that with this short write-up I’ll save others the hassle. They may well last a couple of weeks or a few months – but that in my experience is about it. Meanwhile the little GU-10 lights with three LEDS and proper power supplies I’ve had running 8 hours a day for well over 2 years now with not the slightest degradation – so it’s not LED as such  - it is just down to rubbish design. maybe if you’re on 220v you might get longevity out of these – I can’t say – but at 240-250v – avoid!

facebooktwittergoogle_pluspinterestlinkedin

WIFI Public and Private Access Point

$
0
0

OM2PMany moons ago when we first bought our place in Spain (6 days and counting) I bought something called an OM2P – a small white WIFI Access Point. I’m talking several years ago.

What I was after was private WIFI and public WIFI – something I could charge a nominal sum for. Now the reason for this is that at the time, there was very little in the way of WIFI access in the village of Galera (Granada area) and it was costing me a lot for a beamed Internet connection from a company called Iberbanda (we referred to this state owned company as “Iberbandits”).

I figured if I put the access point near the edge of the building, anyone wanting to use it could do so for a nominal sum and that would help pay for the connection.

Today we have high speed Internet over there and I put the unit in a cupboard 2 years ago.  Today I dragged it out wondering whether to throw it away or find a use for it (door-stop perhaps). A quick dusting and it looks as good as new. The unit is interesting as ALL setup is done via the web. You plug it into 12v and your Ethernet – it finds it’s own way to talk to the CLOUDTRAX servers and from there you can go off to a website and control everything.

Convinced they’d have gone bust by now I plugged the unit in and went off to the website.

Not only was my OM2P recognised but I was informed that an update was due – did I wish to go ahead. I agreed and 10 minutes later not only was my OM2P fully updated but also given a whole load of new features – the update is only a couple of months old.  So now this little white wonder can create up to FOUR SSIDs.  I’m not interested in the public side so I switched off the main one. That left three SSIDs to play with.  They can be set up to be just simple access points on the network OR totally isolated.

As it happens when we head off to Spain, our place becomes a holiday rental (www.hollyberry-cottage.co.uk) for the summer and I was struggling with the best way to isolate my various access points from visitors to the cottage. Not only can the SSIDs be made utterly isolated – they can also be bandwidth limited (that’s not working for me – I’ve reported it) and even optionally isolated from each other. If you wish you can make SSID1 accept tokens from credit cards etc and let the public have a little bit of your bandwidth (isolated).. or not.

Good investment.

facebooktwittergoogle_pluspinterestlinkedin

esp8266 Annual Awards

$
0
0

esp8266.comJust a note to say THANK YOU to everyone who voted for the Nextion Wifi Touch Display over at esp8266.com in their first annual competition.  I just found out this morning that we won second prize, beaten to the top only by the excellent esp8266 Basic Interpreter – a great tool which will help get beginners up and running with ESP8266 chips.

And this is not the end of this project as the board has proven to be quite useful so we have another iteration on the way soon with an RGB LED as the general indicator and spacing for mounting a DHT11/22 as well as the normal Dallas temperature chip – neatly merging the board into the home control 2016 project.

So once again thanks to those who took the time to vote – quite made my day.

Nextion WIFI Touch Display

facebooktwittergoogle_pluspinterestlinkedin

Track Broadband Outage in Node Red

$
0
0

connectionActually I could have given this a range of titles – as the following is useful in a range of situations. But first let me explain my problem:

The problem: I’ve been having broadband issues. The broadband cuts out for a few minutes without warning and then reconnects.  I just wasted a lot of time getting onto my router people (TP-Link – they are quite helpful) only to discover the same thing happens with the original rubbish Plusnet router (we’re using high speed fibre-to-cabinet broadband, around 70 meg or so – but it still looks like a normal phone line connection coming into the house so not TOO many modems support this – TP-Link does).

Of course Plusnet and BT say “nothing wrong here mate” and the problem really is intermittent – not had a failure in 2 days now but last week had several in one day. 

The solution: Well, not so much a solution but at least a means to easily monitor any future issues so I can act on them if things get out of hand. The answer for now is to log these events. I set up a routine to log failures by pinging Google every 30 seconds – of course it takes the modem 2 or 3 minutes to recover from a loss of connection so that log was getting large. By version 2 I was only logging CHANGE of state.

Node-Red SQL inject

Above is how I store the info in SQLITE. I use a PING node and the SQLITE node…  and here’s that function in the middle.

context.global.shot=context.global.shot|0;

if (msg.payload===false)
{
if (context.global.shot===0)
    {
        context.global.shot=1;
        msg.topic="insert into pings (ping) VALUES(" + 0 + ")";
        return msg;
    }
}
else
{
if (context.global.shot==1)
    {
        context.global.shot=0;
        msg.topic="insert into pings (ping) VALUES(" + 1 + ")";
        return msg;
    }
}

The actual table is in a database called IOT.DB and here’s the table.

CREATE TABLE 'pings' ('thetime' DATETIME PRIMARY KEY NOT NULL DEFAULT CURRENT_TIMESTAMP, 'ping' INTEGER)

So that’s simply storing away the date and time – and 0 for disconnect, 1 for reconnect.

To make that useful what I needed was for the computer – at one minute to midnight – to send me a report FOR THAT DAY but only if there was actually something to report. That I’ve done below.

image

The first (blue) node is simply a Node-Red inject that sends an empty message at one minute to midnight every night. The second is a function to build up a SQLITE query to get all the events for that day. The last one is an email node set up to send me emails on Gmail.

var now = new Date();
function pad(n) {
    return (n < 10) ? ("0" + n) : n;
}
var today=now.getFullYear() + "-"+pad((now.getMonth()+1))+"-"+ pad(now.getDate());

msg.topic="select * from pings where thetime >= Datetime('"+ today +" 00:00:00') and thetime <= Datetime('"+ today+" 23:59:59')";
return msg;

And finally having sent that off to the SQLITE node, I get an array back of the dates and states… which I send off to myself in email.

msg.topic="Hollyberry Connection Notice";
var a=msg.payload;
msg.payload="";

if (a.length!==0)
{
    for (var i in a)
    {
    msg.payload+="\r\n"+ ((a[i].ping !== 0) ? "Regained" : "Lost") +" connection " + a[i].thetime;
    }
return(msg);  
}

And that, hopefully will keep me informed of any issues with the broadband while we’re away enjoying the sun next week. Hope you find that useful – I’m sure there are many variations of this which might be useful for general monitoring.

Node-Red constantly surprises me with how simple it is to do just about anything I want.

Facebooktwittergoogle_pluspinterestlinkedin

Installing the Works

$
0
0

I’ve had a couple of guys on saying they have had issues installing Node-Red/SQLITE on new Pi2s – part of that I guess will be down to the fact that it is pre-installed on the latest Raspbian – and also in earlier scripts I an other probably installed freeboard – which seemed to work well until recently – when for reasons as yet beyond me it would be responsible for crashing Node-Red. I’ve just gotten rid of it.

So as I got up early this morning and before I start my packing for our migration to the sun for the summer, here is something hopefully useful.

Yesterday I did a clean install of everything on a Raspberry Pi 3 (but nothing I’ve done would not work on a Pi2).  This is what I call “the works” as it includes Webmin, Node-Red, a bunch of Nodes including my own, screen, some Raspberry Pi monitoring, Apache/PHP/SQLITE etc.

So – no guarantees but to start up you need a clean Pi with the latest Raspbian (not NOOBS) installed. I normally get that straight from the Raspberry Pi store but in this case I installed BERRYBOOT 2 (get the right one, not the one for the original Pi) and installed Raspbian that way (push of a button really).  I then did two things… I logged in as user Pi using WINSCP and I did the usual “sudo apt-get update” and then “sudo apt-get upgrade”.   I then changed the pi user to my own password “sudo passwd pi” and then just for ease I added the ability to use user “root” externally. That involves using that horrible “nano” editor to change “sudo nano /etc/ssh/sshd_config” and look for “PermitRootLogin” and change to “yes” – save and reboot. I then did “sudo passwd root” to change the root password.

So you may not do this but that’s what I did FIRST so you have the picture..

https://bitbucket.org/snippets/scargill/KyKnd

So that’s my script I used.  It’s not as neat as the older ones because for ease I brought stuff in that was originally in a separate file which was a bit messy. Now “there is only one”.  I copied that to /home/pi and added exec permissions to the owner – a doddle with winSCP – you just right click the file – properties and tick the 3rd box at the top.

in the /home/pi directory I then ran “./ra3.sh”  - note NOT as SUDO – just exactly as-is.

On the Pi 3 I think the whole thing took maybe 20 minutes – with some interaction – in all cases I accepted defaults or suggestions – occasionally entering a password of my choosing as required.

The board then reboots at the end.

That leaves a couple of things not done…. no security on Node-Red – that’s easy….inserting some material into the home/pi/.node-red/settings.js file… (if you are using winSCP make sure you have hidden files visible as that whole .node-red structure is hidden) -

Around line 150 which starts “functionGlobalContext” I put this in.

    functionGlobalContext: {
        os:require('os'),
        // bonescript:require('bonescript'),
        // jfive:require("johnny-five"),
        moment:require('moment'),
        fs:require('fs')
    },

    adminAuth: {
    type: "credentials",
    users: [{
       username: "admin",
        password: "$2a$08$sQ6R4vPSqvX0nthS7y2fQOHIey0game0OVvcccvcvcvcbvcbvcbvcbvc",
        permissions: "*"
    }]
},

  httpNodeAuth: {user:"user", pass:"$2a$08$fInbgDanmhpr.IGeeUE5..GVAhd.Bpwfcbvcbvcbvcbvcvbc"},

Those passwords are nonsense… you need to follow instructions here to generate them – EASY (now)…

Within the .node-red directory …

node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here

Now – you MAY have to “sudo npm install bcryptjs” for this to work – I did… I could have sworn it was in the script – but I had to do that…. and that returned the long encrypted password – you can probably use the same one for both of the above if you want – one is for node-red itself and the other for pages generated by say node-red-contrib-ui.

What else did I do.  Oh, I like my own 404 error messages (var/www/html) and so I used sudo nano again – you could log in as root to update a file..   in /etc/apache2/sites-enabled there should be a shortcut 000-default.conf – edit that file with nano so that the end of it looks like this

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
   
    ErrorDocument 404 /custom_404.html
     
    <Files "custom_404.html">
        <If "-z %{ENV:REDIRECT_STATUS}">
            RedirectMatch 404 ^/custom_404.html$
        </If>
    </Files>
   
    </VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

and in /var/www/html  I added a file called custom_404.html with my error message in it – I also changed the default index.html in that page to something useful.

Reboot of course and…. erm, that’s about it.

So if your address is 192.168.0.20 for example..

 

192.168.0.20:1880   - that’s Node-Red

192.168.0.20    - that’s your basic web page

192.168.0.20/phpliteadmin -  that’s your PHPLITE editor

192.168.0.20/phpsysinfo  - that’s your status page – very nice too

192.168.0.20:10000 -  that’s webmin

If for any reason you still end up with freeboard ….. “sudo npm remove node-red-contrib-freeboard” from the .node-red directory should do it.  If they fix it so it never crashes Node-Red please let me know.

If anyone spots something I’ve missed do let me know and please don’t say “I tried this on a different setup” or “I already had Raspbian installed” – this works with a clean Pi as described – I’ve not done any testing with any other system though it is pretty close to versions that might work in other scenarios.

Facebooktwittergoogle_pluspinterestlinkedin

Simple Serial Terminal lost blog

$
0
0

For reasons beyond me the original article on my serial terminal, originally put together when I was messing with LUA, has disappeared from the blog entirely – and so here’s a quickly updated version with Dropbox link.

Petes Serial Terminal

So above right you should see the editor. The most important bits are the two big windows – on the left is the area you type in – multi line – and on the right is the output from the serial line – i.e. what comes back from the chip. In the simplest case you set up the serial port you want, ensure it’s set to the right baud rate, select “serial – open” and you’re all set (I’m assuming you have an FTDI or similar on your USB lead, talking to the serial on the ESP8266 device. You can send all of that out the serial line – or just a selected area or indeed whatever is in your clipboard. Also you can define up to 10 pages of info (Notepads) and send that – in addition you have up to 9 presets – handy for initialisation sequences. Oh and you can save the left panel into a file if you want.

Whatever you type in the left window is non-volatile, i.e. it’ll still be there after you blow up your serial port and have to reboot the computer.

Disclaimer: if any of the above or the use of the terminal breaks your computer, it’s not my fault. I’m providing this freely just because I’ve no reason not to but without support. You just need the exe file for this… PetesSerialTerminal.EXE and note that Windows XP is not supported.

So let’s take a look at the top first. I have deliberately kept this as clean and simple looking as possible as you really just want to get on with coding and not worry about some pesky program – but there are some basics if you want to make good use of this. The file system is easy enough – you might want to store what’s in your left window – your latest all-singing routine or just a bunch of nonsense – that’s up to you hence file – save. Find a suitable directory to store your stuff – the dialog is bog-standard. For retrieval – you have two options, load and append. The former will overwrite what’s in the window, the latter will append to what’s there – so you can store a load of routines and build up something new the easy way.

Serial is even simpler – open or close the port. When open you’ll find some controls don’t work – like changing the baud rate for example.

Notepad is interesting…yes, no less than 10 pretty coloured notepads (non-volatile) to store snippets in – nothing clever about these, you can just copy and paste to and from them in the normal way.

notepadsI normally have several projects going on and find it handy to have stuff lying around – this beats yellow sticky notes full of code any day. There’s a big CLOSE button at the bottom to hide these.

Clear- well you can clear the notepads or your left or right windows – and help – well it’s a picture of me – the idea of writing a complete help system for this just filled me with horror.

So down at the BOTTOM of the screen… assuming you have the serial all turned on you can “Send Window” – i.e. send the contents of your left window off to the serial port – it will send it one line at a time with a delay between each line specified at the top right in milliseconds, defaulting to 400ms – but whatever works for you. 

I’ve coloured the individual panels just to try to help for when you’re in a hurry – I tried to colour the tabs but Microsoft isn’t having any of it up to now.

If you select some text in the normal way in that left panel you can press the “Send Selected” button and only send the stuff that is highlighted – OR you can “copy” from just about anywhere and send whatever is in your clipboard… that’s awfully handy. 

Then there are those notes.. N1 to 10 let you send the entire contents of any of those notepads.  Finally there is a one-line window which you can send directly with the “Direct” button.

To the right there are some presets, 9 in all – and in SETTINGS you can define their names and what gets sent out.  And that takes us to settings.

settingsFirstly you’ll see the 9 preset buttons – their titles and contents – note you DO have to press OK to save these in SETTINGS – most things outside of this SETTINGS box just save automatically. Auto prefix and suffix I suggest you leave be unless you’re NOT messing with Lua and the “Auto prefix/Suffix” tickbox determines whether or not you use this – essentially if “File.open” is see starting at the LEFTMOST character in your input window, these prefix/suffix characters will be added to your line as they are being sent out until the system sees a “File.close” again starting in the leftmost column of your input window.

“Arduino DTR” – well that’s for those of you who want to use this terminal with your Arduinos (you may be working with the Espressif AT firmware for example)  – that’s the bit that resets them when you open the port. It just flicks the DTR line temporarily on open – nothing more. Autoclear – tick that and you’ll see the right window cleared every time you press the send button – just preference really. Lua comment removal is turned on by default (—) – you can turned if off – and “Retain blank lines” is new, just something for the future. Normally, most blank lines never make it to the right window.

And that is that, really – nothing much else to tell you about the program – I hope you find it useful – I have – and no doubt I’ll add more in time.

Here’s the Dropbox link – https://www.dropbox.com/s/wsjb3ofnc5ng4js/PetesSerialTerminal.exe?dl=0

Facebooktwittergoogle_pluspinterestlinkedin

PWM Woes

$
0
0

 

Just in case anyone is having issues with the ESP8266 SDK and PWM. Problem now “solved” but you might find this interesting.

For many months now I’ve been using the PWM on the ESP8266 successfully, so much so that I’ve not tested it and just recently I’ve noticed it no longer works. Specifically, the PWM startup routine forces my ESP8266s to reboot with a watchdog timeout.

So first things first, the SDK manual appears to STILL be incorrect. It states in version 1.53 (ESP8266 SDK API guide) in page 178 that the DUTY parameter is pointer to an 8 bit array.

Yet the header and routines elsewhere require 32 bit values for the array. I’ve always ignored this.

#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U
#define PWM_1_OUT_IO_NUM 15
#define PWM_1_OUT_IO_FUNC FUNC_GPIO15

#define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_GPIO4_U
#define PWM_3_OUT_IO_NUM 4
#define PWM_3_OUT_IO_FUNC FUNC_GPIO4

#define PWM_4_OUT_IO_MUX PERIPHS_IO_MUX_GPIO5_U
#define PWM_4_OUT_IO_NUM 5
#define PWM_4_OUT_IO_FUNC FUNC_GPIO5

uint32 duty[] = {0, 0, 0};
uint32 freq = 1000;
static uint8 donepwm = 0;

uint32 io_info[][3] = {
  {PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM},
  {PWM_3_OUT_IO_MUX, PWM_3_OUT_IO_FUNC, PWM_3_OUT_IO_NUM},
  {PWM_4_OUT_IO_MUX, PWM_4_OUT_IO_FUNC, PWM_4_OUT_IO_NUM}
};

So with these definitions I call….

if (donepwm == 0) {
   pwm_init(freq, duty, 3, io_info);
   donepwm = 1;
}

 

You should call the setup once only.. hence the wrapper using “donepwm”. This has always worked and yet now, no matter what I do, this crashes the processor – usually a few seconds after it has been called.

Result..

ets Jan  8 2013,rst cause:4, boot mode:(1,0)

wdt reset

This used to work – now it causes the WDT.

The example in the manual..

Example: uint32 io_info[][3] =  {{PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},          {PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM}, {PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM}};

pwm_init(light_param.pwm_period, light_param.pwm_duty, 3, io_info);

HERE is a  “fix”…

http://www.esp8266.com/viewtopic.php?f=6&t=4675&p=46060#p46060

I amended the rom0.ld file and sure enough – fixed…

But that means there’s an issue somewhere –  and that manual needs fixing  - I hope Espressif are looking in.

Facebooktwittergoogle_pluspinterestlinkedin

North East Maker Faire 2016

$
0
0

peepsI could not be there at the Maker Faire UK in the Centre for Life in Newcastle – but thanks to my spies – it’s great to see so many people there.

Apparently this couple on the left are into ESP8266 and got some ideas from the blog.  Glad you like it guys and sorry I could not be there. Understand you had a chat with Aidan.

Hope everyone there is having a great time – let us know if you’re looking in.

Meanwhile I’m in and settled in Spain – spent the whole day updating software (and more to go as in many of my older boards there was no OTA software.  Just cracked the problems I was having with PWM on the ESP software and so the repository now along with the .BIN file I made available are all updated. 

And now, while the sun is shining (and it is 23c outside) I’m off to update the rest of my boards.

Facebooktwittergoogle_pluspinterestlinkedin

Status update

$
0
0

GaleraIt may seem like I’ve been quite the past week – but having arrived safely in Spain we’ve had lots to do.  However I have done some updates to the “home control 2016” blog entry as I’ve implemented some fixes to the node-red-contrib-esplogin node.

For those of you unfamiliar with this – the idea is a node-red node that updates a bunch of ESP8266 modules with time and date info as well as dusk and dawn timings. It does this on power-up of Node-Red, on demand from individual units and every 12 hours – except it wasn’t doing it every 12 hours. It is now. Here’s the link for those interested. The node itself also now has much better status information and help. http://flows.nodered.org/node/node-red-contrib-esplogin

cludgeMeanwhile I’ve been struggling with rubbish broadband back home in England as the router failed every now and then to reconnect. Aidan and I have implemented a solution using one of the ESP8266 modules which will check Google every minute and if it gets nothing for 10 minutes will reboot the router.

new layoutAidan is working on a new version of the home control board with a couple of minor improvements – the connection for a Dallas temperature chip is now a 4-pin job suitable for the Dallas chip or the DHT-22 and we’re also putting on-board an optional RGB serial LED as the status LED on the board uses all sorts of flashing convolutions to indicate state and we thought it might be nice to use colours instead. There  is still a question mark over simultaneously using PWM and sending serial data to LEDs and that is being tested right now.

There’s a significant update to the ESP8266 source(home control 2016 project etc.) as I fixed a minor silly in my watering system code. https://bitbucket.org/scargill/esp-mqtt-dev and added a load of improvements including a serial RGB indicator LED

Meanwhile I’m sitting here on the edge of my seat waiting for a new Nikon camera to arrive so I can make best use of the excellent weather out here in Andalusia.

Facebooktwittergoogle_pluspinterestlinkedin

The Electrodragon Alternative

$
0
0

 

electrodragon[6]Part 1: At $6, the Electrodragon “WIFI IOT Relay Board based on ESP8266” looks like a force to be reckoned with, offering WIFI control over two 10 amp relays. But what about the SONOFF from ITEAD? How do they compare?

Making use of their own incredibly cheap power supply is one reason the cost is so low and the board looks on the surface to be well made and well thought out – but read on.

The unit uses what appears (from the antenna design) to be the ESP-12F module which, it is said, has a better antenna than previous models but is otherwise pretty much like the ESP-12E.

The two relay outputs are on GPIO12 and 13 respectively – with the status LED on GPIO16. The socket for a temperature sensor uses GPIO14 !!! That’s new – usually people use GPIO2. Oh, well.

In order to do the board justice I went off to their website http://www.electrodragon.com/w/ESP_Relay_Board#Pin_Mapping_and_Wiring and there seemed to be a fair bit of info available. Clearly the first thing I’d be interested in would be blowing my own software. The page refers to buttons 0 and 1 but on the board are buttons 1 and 2…  but elsewhere they clarify these as buttons 1 and 2. I had expected these would be used for reset and programming respectively and that as it happens is easy as a 6*2 way connector conveniently brings out RX and TX. In practice one of them does indeed go to GPIO1 for programming but you have to power cycle the board to start programming – that kept me going for a while… always read the manual.

electrodragonThe case of the module I received, it would seem, was one already available because the 4-way connection bringing out the power via the relays, is partially obscured by the case itself. Not a good idea when you’re messing with mains wires – and especially those able to take 10 amps – but wait - there are lots of thing they’ve gotten right – the neutral line is not only separated from the live by a gap but it is also on the other side of the board, but the two tracks bringing power right across the board from the mains to the two relays –  while being nicely isolated by an air gap which is GOOD, are WAY too thin to handle a total of 20 amps (2 * 10amp relays) or, IMHO. I’m happy with that as I’m only likely to want to power a couple of bulbs but it seems a bit daft to use a pair of 10 amp relays then keep the track so narrow – around 1mm.

The power supply claims to have all matter of things including temperature protection, overcurrent, overvoltage and short circuit full protection, high and low voltage isolation – and yet, it is a really small and simple looking, exceedingly low cost model available for little under £1 – do we believe the claims? Do they matter? If you’re powering only the relays there’s not much chance of getting an electric shock but the board encourages you to attach a DHT22 which means you could be in contact with wires – my only advice here would be never to touch them when this board is connected to the mains – and make sure no-one else can.  But why you ask, surely you’d put the DHT22 in the unit itself?  Not if you want any meaningful temperature sensing out of it – these devices HAVE to have air around them and not the warm air off a power supply. Really, don’t waste your time putting a temperature sensor inside this OR a SONOFF box unless of course you’re using it to see how hot the electronics get.

So, how was I going to test this unit – I noticed something about AT commands – but I gave up on that way of programming with ESP8266 chips a LONG time ago – regular readers will know that I generally talk to such boards by MQTT protocol using my own code as found in the Home Control 2016 project and the prize-winning (subtle) WIFI Touch Display project and this was to give me pause for thought as I use GPIO13 for status indication – as do the SONOFF units and the relays here are on 12 and 13.

Well, nothing should be set in stone so I spent the evening adding more commands to my code and added a function to allow for these Electrodragon units – strangely enough I’ve named the command “electrodragon” – if set to 1… we’re using these boards, if set to 0, we’re not! Simples.

Programming Electrodragon

So, I’d not realised this but reader Nathan tells me that the chip isn’t actually programmed other than what’s on the chip initially i.e. the AT command set. So that has to come off.

Above you see a picture of a typical FTDI – that is the little box that plugs into your PC or whatever and converts USB into serial signals. That box is wired as you see above to the connector on the Electrodragon – and the button I’ve highlighted is the one that needs pressing BEFORE AND DURING POWERON in order to put the Electrodragon into programming mode.

To program the board I did NOT connect it to the mains or to any output. I connected up my FTDI as you see above – now, the sharp reader might say “but that’s on the 5v setting by the link on the FTDI and won’t that break the board?” – I have to say that the vast majority of the information on the web says YES, but here’s why I’ve done it this way: firstly putting the FTDI in 3v3 mode means it has VERY little power to spare and in many cases you’ll end up with relays jittering and lights flashing and you’ll get no-where (that would be with the power (red) lead elsewhere of course – bottom right pin in fact on the Electrodragon), and secondly while I would never normally use 5v logic with an ESP8266, I have NEVER broken an ESP12 by using a 5v FTDI signal on the serial.  Serial from the Electrodragon incidentally to the FDTI is fine – it’s the higher voltage serial output from the FTDI to the serial in on the Electrodragon we’re talking about.  Your choice if you decide to copy me – but specifically using FTDIs that look like the one above – I have blown ESP12s WELL over 1000 times without doing them any harm. The alternative is a 3v3 power supply feed to the board and leave the power output of the FTDI unconnected. Your choice, your responsibility.

Remember I use my own software that needs to talk to MQTT and have access to a WIFI access point.

For the software you need to go to the home control 2016 blog – there is source code for the Windows Unofficial Programming Environment or a pair of ROMS for those unable to do this (and to be fair it took me a while to get to grips with using the SDK etc)  – RBOOT.BIN to 0x000000 and ROMX.BIN to 0x002000 using your preferred tool. The ROMS are in the root of www.scargill.net.  Once programmed, disconnect and reconnect the FTDI.  Most likely you won’t see the light flashing on the board. Instead you’ll hear a relay flashing on and off quickly – that’s because by default, GPIO13 is an indicator!!!!  At 115,200k send serially the commands:

{wifi_button:1}

{electrodragon:1}

The relay will stop clicking but the indicator won’t yet flash - and now reboot – the indicator on the board should start to flash and these commands will now work…  {out13:1}, {out13:0}, {out12:1}, {out12:0} – so that’s your two relays working - you’ll then need to go through the instructions to set up your WIFI access point and MQTT details – that’s done by a web interface or just as easily you can do it by serial just as above. Once that is done – Bob’s your uncle.

So in my case:

{id:”electro2”}

{ssid:”wififorus”}

{pass:”xxxxxxxx”}

{ssid2:”wififorus”}

{pass2:”xxxxxxxx”}

{mqtt_host:”192.168.1.19”}

{mqtt_pass:”xxxxxxxx”}

{mqtt_port:1883}

{mqtt_user:”admin”}

{mqtt_pass:”xxxxxxxx”}

reboot (i.e. pull the power and reconnect.

Now WHY does that have to be complicated by adding a second SSID? Because my software handles two of them for backup and while you’re messing about it is trying to connect to a default SSID you don’t have – there’s a chance by the time you get around to it that it is trying to connect to the SECOND SSID.  If you can’t be bothered to put the second one in – eventually the unit will get around to trying the first one again.

I’m calling my units “electro1” and “electro2” as I have two of them – they are now all programmed up and ready to go. Just to be sure I was not missing anything I left one on at midnight last night and as expected it operated flawlessly.

NEXT: Plug in the power - I don’t expect any surprises. Nathan and I have both passed comment about the power – from here on it is all your responsibility.

Facebooktwittergoogle_pluspinterestlinkedin

Special UK quality

$
0
0

Is it just me or do others find this kind of thing annoying? I thought it might be a good idea to get a PCF8574T I2C I/O expander as a little add-on to the home control system, so you could plug it into, say GPIO4 and GPIO5, losing 2 outputs – and gain 8 – net gain 6 outputs…

So off I went to Ebay – and clearly being a Brit I’d like to support British companies.  I wonder what extra value the UK version would bring? I’m currently in Spain as many of you know.. aside from customs (which would not apply at this price) and tracking…

Chinese version (and not untypical pricing).

Chinese PCF8574T

UK version (not seeing any extra gold-plating).

UK PCF8574T

Not surprisingly I’ll be ordering from China – keep eyes peeled in a couple of weeks or so for blog updates on this.

Facebooktwittergoogle_pluspinterestlinkedin

Home Control and Nextion Updates

$
0
0

Just a brief update. Thanks to some feedback I was prompted to see if it is possible in the home control project to get feedback as to the state of an output on the same line as controlling it.

hapticSo for payloads you might use {out12:1} to turn on GPIO12 and {out12?} to get feedback – well you can simply join them together as such into one message:

{out12:1;out12?}

Also on the subject of haptic feedback when using the software for a Nextion display, put a haptic feedback device onto GPIO12. I used these: http://www.ebay.co.uk/itm/321809227365?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

In the last couple of days I’ve updated the manual and the software to make the responses more consistent.

Facebooktwittergoogle_pluspinterestlinkedin

Remote checking Home Control Units

$
0
0

Those of you who are aware of the Home Control project (Home Control 2016) will know that the software/hardware combination of a Raspberry Pi (running Jessie, Node-Red, SQLite and Mosquitto) and ESP12 (running the software described in the Home Control project) is proving very reliable – but there are occasions when you may wish to be absolutely sure that units are actually doing something.  One way to do that is simply to put timeouts on every response you expect… but that makes for complicated coding. A simpler way is to regularly ask each unit for the status of one of the outputs. It doesn’t matter what the response is, as long as there is a response.

As it happens I’m having an issue right now – the heating controller part of my system back home in the UK is working perfectly except of an on-going issue with Plusnet broadband. They are denying it is their fault but the broadband fails perhaps once a day, maybe more, maybe once every two days but eventually it will fail. Most of the time the TP-Link TD-9980 router reconnects within a minute or so – but for reasons I don’t yet understand, occasionally it just will not reconnect. The solution to that was simple and two-fold, a standard timer which turns the router off for a minute in the early hours every day. That’s the “belt and braces” approach. In addition, the Raspberry Pi is polling Google every few minutes. If it fails totally over a 15 minute period to contact Google, an ESP8266 unit will reboot the router.

All of this worked perfectly for several days and then… the heating relay ESP8266 refused to log back in after one of these “cuts”. I can only put it down to being right on the edge of signal. The reason I say that is that late last year we had horrendous problems with WIFI here in Spain, some kind of attack. It went away but during that time over several days I was losing WIFI constantly so I made damned sure the ESP units would reliable log back in, in the event of temporary failure of MQTT or WIFI or both etc. And yet just occasionally this particular unit will not log back in – a power cycle fixes the problem but that means I need to know about it and ask someone to pull the plug for a moment.

So – I’ve implemented this for the two most important devices in the building – the main heating temperature sensor – and the ESP that controls the relay to turn the heating on and off.

watchdog

Timeout NodeWhat you see above is as follows: 2 Node-Red “inject” nodes (standard) fire out requests every 5 minutes to MQTT to ask the relay and temperature units for the state of output 0. 

Which command is irrelevant as long as it is a query which returns a result and otherwise has no effect on anything.  So for example with a topic holly1/toesp and a payload of {out0?} the system is expecting a response of OFF or ON (irrelevant here) from topic holly1/fromesp/out0

The two incoming MQTT nodes (left, purple) pick up on the response and feed them into my “timeout” nodes  (node-red-contrib-timeout).

As you’ll see below, the operation is simple – the timeout node doesn’t care what is incoming as long as something is. if it gets nothing for 60 minutes it will time out and send a payload out – in this case thanks to the standard email node (green) an email to me. 

During that time, normally, the MQTT nodes would have responded every 5 minutes – ie 20 times, topping the timeout node up to 3600 seconds even if most of the messages were missing (and there is no reason why any should be missing).  In this case I’ve not put messages for “safe state” or “warning” – so nothing goes out unless the timeout actually runs down to zero.

Click on any of these images for larger versions.

So while this does not solve the problem, it does mean that I’m alerted to the issue and can ask someone to disconnect and reconnect the relay unit. With what has been 100% reliability of Raspberry Pi 2 boards (with a decent Samsung microSD or similar) I can be pretty sure I’ll get an email if something goes wrong.

I hope this proves useful to others.

Facebooktwittergoogle_pluspinterestlinkedin

Speech … the Final Frontier

$
0
0

Ivona speechUpdated 11/05/2016

Buffered, SD-cached high-quality speech and sound effects for your IOT project. Requirements: Raspberry Pi or similar, Node-Red and a little of your time.

As you may know I’ve done a couple of blog items on Speech on the Raspberry Pi recently – I was quite happy with the Google Translate API until recently when they stopped making it available for free,  so I was forced to go off in search of alternatives and settled on local synthesizers like eSpeak – the problem being – they generally sound AWFUL. eSpeak sounds like someone’s dog being strangled.

And so it was that one of our readers (thank you for that) contacted me and suggested I take a look at Ivona. https://www.ivona.com/us/

This is new: I’ve just gutted the code from the original blog to produce a much better version, better thought out with cacheing for off-line use, unifying speech and sound effects into an auto-created library. In the event of an external comms failure so that you cannot access the outside world, your Ivona is going to fail and this happened here at Bedrock – SO the idea hit us to CACHE all mp3 files (assuming you’re not going to do unique messages every time). That way the SECOND time you ask for a message you will already have a file with that name – the total file space for dozens or even hundreds of these MP3 files is a tiny fraction of a typical SD storage capability and not even worth taking into consideration in most projects.

I originally did a video to accompany this blog - https://www.youtube.com/watch?v=qoxPVa48qRw

If you use the link I’ve provided above (to Ivona) and select a suitable voice on their web page then enter some text in the box, you’ll find it does a pretty good job. Ivona is free to developers – just grab a free account and get an API key and secret key. I spent the entire evening playing with the code and when I looked at the percentage of my “free use” – nothing.

Take a tip when you copy and paste that API code information (which you should immediately on getting an account as you won’t be able to get the same key later) and pass them via NOTEPAD (paste then copy again) to get rid of any hidden characters.

So now you have an API key and secret key to be used in the Node-Red node Ivona (node-red-contrib-ivona) https://www.npmjs.com/package/node-red-contrib-ivona

Your API key for Node-Red is the ACCESS code and the PASSWORD is the secret key !!!!! I used my email address for the username – this is all a bit non-intuitive so beware.

Over to Node-Red. So what this node does is take in your TEXT, send it off to Ivona which returns an MP3 file with your chosen speech. You should also have MPG123 installed on your end computer (I’m using a Raspberry Pi2 for all of this). http://www.mpg123.de/

In the simplest case you would send off your text, get the MP3 file, send that to mpg123 for playback. But then you are stuck with a file… and what if you send 2 in quick succession – they will overlap each other as Node-Red runs asynchronously.

Here’s the solution and it’s a lot better than I had in the past. You can fire off several speech requests including requests for other .mp3 files.  for special effects I have a bunch of MP3 files already stored – such as “alert” and “hailing frequencies open”.

Ivona speech

In the example above (that red block is NOT the Ivona node – it is a subflow I wrote – more in a minute)… let me show you those two INJECTS on the left..

 

Ivona speech

Ivona speech

The first has “alert” in the topic and some text “Red 1 logged in” – the second simply text.

I can click one, wait for it to speak and then click the second – or I can chose not to wait, clicking wildly – and they will still play in order.  So if you specify speech for the TOPIC AND THE PAYLOAD, simply both will go into the queue in order.

How do I do that – so looking at the red Node-Red SUBFLOW…

flow

The yellow’ish blocks are user functions, the red block is a Node-Red EXEC functions – the purple item is a simple 1 second delay for good measure. The purple item is the node-red-contrib-ivona node.

I take in text… if the topic has the word “alert” in it – I put that on the queue BEFORE the main text – other than that there is NO difference between the two.

If there is no text, just a blank message coming in, I check the queue and if not empty, try to use the items on the queue (first in, first out) one at a time.

The INJECT function is needed to start the ball rolling for the first item in the queue. Once I find text in the queue, it is send to the Ivona node IF such a named file does not exist - and then on to the mpg123 player – either way setting a BUSY flag so that those one-second ticks can’t pull another item off the queue until I’m done.

When done – I  send empty messages back into the input to trigger off any further items in the queue.

Here is the main function:

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

if (msg.payload!=="")
    {
    // just push but not recursively
    if (frompush===0)
        {
            if (msg.topic!=="")  context.arr.push(msg.topic);
            context.arr.push(msg.payload);
            return;
        }
 
    context.global.speech_busy=1;
    msg.fname=msg.payload.replace(/ /g,'_');
    msg.fname=msg.fname.replace(/\./g,'');
    msg.fname=msg.fname.replace(/\,/g,'');
    msg.fname=msg.fname.toLowerCase();
    msg.fname="/home/pi/recordings/"+msg.fname+".mp3";
    return msg;
    }

Note the busy flag and the use of PUSH for the queue.

The “copy file to payload” is trivial – Ivona returns the filename in msg.file which is not where I want it.

msg.payload=msg.file;
return msg;

The reset flag function simply clears the busy flag and returns a blank message.

context.global.speech_busy=0;
msg.payload=""; return msg;

The trigger is the Node-Red DELAY function simply set to delay for one second and then pass the message on.

Ivona speech

 

The MPG123 EXEC node calls mpg123 and passes the file name as parameter. The DELETE node simply deletes the file that Ivona creates… Here’s the Ivona setup. Put your credentials in the top box.

moustache

Note the triple moustache {{{}}} -  Ivona examples use a double – but that then interprets slashes and we don’t want to do that because we have a file path in there.

And that is about it – works a treat and produces high quality buffered speech – for free – for your IOT endeavours.

Pick your own file directory (note that I used /home/pi/recordings but that isn’t in any way special) and any words or phrases you want SOUNDS for instead of voice – simply replace with files of the same name (not that spaces are replaced in files names by underscores).  So “alert 2” as a file name would be “alert_2.mp3”

Facebooktwittergoogle_pluspinterestlinkedin

Raspberry Pi Backups

$
0
0

Backups the easy way

One of my biggest issues with the Pi has always been – backups.  Using a PC to backup a 16GB SD is a pain and of course necessitates turning the Pi off to remove the SD. Well, now there’s a better way.

A slightly less painful way than backing up the whole SD with a PC is to use BerryBoot which can do a good job of running Raspbian and at power-up giving you the option to store a compressed version of the SD to USB memory.

It was with sadness then that I updated Raspbian today to the latest version.

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install piclone geany usb-modeswitch
sudo apt-get install python-pigpio python3-pigpio

Nice theory but in practice, on reboot, I ended up with an utterly dead board – something to do with the update and BerryBoot.  I’ve reported this to the BerryBoot author.

But here’s the thing – the latest version of Raspbian Jessie now for the first time includes a live backup facility. Once you have this you’ll wonder why it was not always this way – especially if, like me you’re not a Linux fanatic.

It does not stop there however. Not only will this new utility copy from live to SD (I’ve yet to figure out how to run the SD copier from the command line but it runs from menu – accessories – SD card copier  without issue) but also – and I’m quite excited about this – you don’t need the same size SD – which means expansion or reduction is now a snap – thank heavens for that.

So in order to test this new backup facility – I grabbed the latest Raspbian (not the NOOB version) and blew it onto a16GB SD with Win32DiskManager as usual. I started up the Pi3 and put another identical SD into a convertor and stuck the USB convertor into a spare USB slot. I ran the backup, powered down, swapped SDs over and rebooted – no problem at all. Fantastic.

For my second test – I ran my script on the Raspberry Pi 3 so it was fully up to date with all of my tools – Apache, PHP, Mosquito, Node-Red, SQLite etc. – on a 16GB card. I then made a  backup the same way as above to an 8GB card…  the transfer took place while writing this blog – all in around 15 minutes.

I powered off the Pi3, put in the 8GB card and powered up. IT WORKED!!!!

With that success behind me I decided to get brave. I took the new card and put it into a Raspberry Pi 2 – surely this could not possibly work? IT WORKED!!!!

For some this may be nothing – for others a life-saver – so now it is easy – without even powering down to make copies of a working system – even on different size cards and it would seem interchangeable between Pi2 and Pi3.  Other Pi-like manufacturers take note!! Now I can be WAY more adventurous as it is so easy to make backups.

PigPio

connectionsWhile I was on I thought I’d try the new pigpio GPIO interface.

Firstly I started up the pigpio daemon – at this point being new to me I have no idea how to make this run at power up – nor do I know if there is a reason you should NOT run this at power-up.

sudo pigpiod

Bear in mind that everything was originally set up on a Pi3 – but by this time I was running the SD on a Pi2, not the Pi3.  I like doing things interactively when I’m learning so I simply typed python <enter>

I was greeted with >>

I fastened a LED/resistor combo (I always keep a few ready with female connectors on them for testing)  between connector pin 6 (ground) and 12 (GPIO18).

>> import pigpio

>> mypi=piggpio.pi()

>> mypi.write(18,1)

And it worked – the light came on and off when I used the same command with 0 as the last parameter. I’m dying to try the other more complex commands in a Python program. indeed today everything just seems to be working – the sun is shining, my gadgets are working – what more could one want. I have one duff Electrodragon (more on that later) but apart from that…

Facebooktwittergoogle_pluspinterestlinkedin
Viewing all 1386 articles
Browse latest View live