Monthly Archives: April 2015

A guide to reviews

I’ve had a number of requests to do reviews on the blog recently… so if anyone is looking in with this in mind, please note I’m only happy to review items that are of interest to the readers here. A quick look around the blog should give you an idea of the kind of things my readers and I are into.  Much of the time we’re getting 1000 visitors a day here and I’d like to keep it that way with items they might find of use.

Thanks.

Facebooktwittergoogle_pluspinterestlinkedin

The Saturday Catch

While working on my Raspberry Pi image (with everything I need stored in an image so it it all goes to hell I can recover everything) I realised something I was missing on the Pi was a package manager. A graphical APT-GET for those who are not too keen on command lines. Well I came across this link. http://www.neil-black.co.uk/install-a-graphical-package-manager-on-the-raspberry-pi#.VTLxwCHCoyA

Suffice it to say this is a not-too-exciting but graphical package manager – but the real catch for me as an unwilling-Linux-newbie was this…   I use Geany editor and half of the time I need root privileges because the default settings won’t let me save some files I’ve edited. I usually end up using SUDO GEANY at the terminal just to bring it up in the right mode.

Well, not any more. Half way down the link above are instructions for changing menu items such as Geany and in fact this package manager – to run as root (i.e. the highest level of privilege).

The only difference I made was this.. So for Geany

Find /usr/share/applications/geany.desktop (I’m guessing this applies to anything else)

and near the end you may find in the text of that file Exec=geany or similar. Well, just prefix it with sudo and save… Job done.

Simples…

So now I have a graphical package manager, a remote graphical admin tool (webmin) – SCP for accessing files from the PC and UltraVNC to run the graphical environment remotely (sadly, when working with TightVNC it has problems with copy and paste to and from the PC – if anyone knows how to fix that do let me know)

Facebooktwittergoogle_pluspinterestlinkedin

The Raspberry Pi SD Wear Issue

Raspberry PiReading around the web it is easy to see that SD memory and lifespan are very poorly understood. There are conflicting explanations of lifespan, there are solutions which don’t work because someone didn’t actually test them before writing up … what a mess.

So here’s the deal. SD memory (the type you put in the PI to boot up) has limited write time – SO DOES USB MEMORY.

How long the microSD in your new Raspberry Pi2 will last is anyone’s guess and depends on “disk” activity, i.e. the number of WRITES (the number of READS is irrelevant).

So how to maximise this. It would seem that you CANNOT offload the whole thing to a hard drive.. but you can have the Pi boot up from the microSD – and then do everything ELSE on the hard drive. You cannot power the hard drive off the USB on the Pi as it does not provide enough juice – so you’d need a powered USB hub. This article looks good – I only got as far as transferring files externally so don’t ask me questions on it – but this seems to be one of the better explanations for using an external file storage. https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=44177

Another way to improve the life of the SD and one that makes sense to me is a RAMDRIVE. That is instead of allowing the Pi to write constantly to log files on your Pi, have it read all log files into RAM at power up – write to the RAM and then on (intentional) power down, write back to the SD. RAM of course, you can write to forever without issue.

This kind of implies reliable power and I suggest you hunt out an uninterruptable supply – you can sometimes use those little phone charger supplies but I have found that some work, some don’t. The easy way, after backing up your Pi, is to try any one you have lying around. Plug power into the supply, plug the supply into the Pi. Watch the Pi on screen and test the keyboard or mouse. Repeatedly remove and reconnect the power to the supply – if the Pi works without any issue throughout this - then you’re probably onto a winner. I have 2 of them that work, 2 of them that don’t.

Ok, so there is a package called Ramlog which does the job of ensuring the logs are only written at power down. I followed two sets of instructions both of which failed part way through because the writer hadn’t actually tested what he was writing down, missing off a SUDO (super-user-do) command or similar. This explanation http://www.vdsar.net/limit-sd-card-writes-rasberry-pi-using-ramlog/ worked for me.

It would seem that SOME SD memory has something called “wear-levelling” in which the write use of blocks of memory in the chip are evened out so that continuously writing to one block ACTUALLY doesn’t happen as the wear is “spread” – sadly trying to find out how well this works and with which manufacturer’s chips it works – is something akin to dabbling in witchcraft. There is just so much rot out there so personally I’m not counting on it.

Oh and how do you tell if you’re reducing the number of writes – less or no flashing lights on your Pi.

I hope that helps. I’m coming to the conclusion that for long term use an external drive might be a good idea but I think I’ll wait a while until someone comes up with a package or batch file to make this nice and easy – meanwhile Ramlog seems like a good compromise.

About the only thing I did notice is that my SD usage according to WEBMIN before I installed Ramdisk was 3.5GB and after it was 7.10GFB but that’s clearly rubbish – it would be interesting to see it anyone else gets any “special effects”.

Facebooktwittergoogle_pluspinterestlinkedin

ESP8266 Test Board

I mentioned that Espressif were kind enough to send me a test board to play with – and very nice too. Not had time yet as I’m struggling with learning how to make an installer for my Node-Red package – with some great help from the guys involved with this….

So meanwhile here’s a lovely diagram – which I asked Espressif for specifically so you could see what the board does.

If you double-click on the image you will get a larger version. What’s really nice are the logical groupings. Not TOO keen on the tiny connectors on the right – but the main ones are 0.1” standard stuff. Quite looking forward to having a play.

 

ESP8266 Development Board

Facebooktwittergoogle_pluspinterestlinkedin

Slimmer Raspberry Pi 2

In the process this week of producing a new new Raspberry Pi2 with just the stuff I needed on it I thought I’d have a go at removing unnecessary programs from the Pi – that is the ones that come with it – after all the Debian installation from the NOOBS package is designed to please all.

I have not and never did have a use for the Wlfram engine but I had no idea how much room I’d save – was it even worth removing?

OH YES.

Between Wolfram-engine, minecraft-pi, scratch and sonic-pi I just saved 584 Mb. Now if you’re using an 8GB microSD that is a significant chunk! I’m using a 16GB but I’m still happy to gain that chunk back.

Facebooktwittergoogle_pluspinterestlinkedin

A Fresh Pi2 Start

pi2

The thing about rushing in with something new is that you tend to bring your learning mistakes with you.

Firstly for new readers, why am I fascinated with the Raspberry Pi? Well I’ve been working on IOT for some time now and I’ve tried out many ideas most of which you’ll see blogged about in here. I originally used an Atmel 1284 based solution of my own (own board, own software) to control a number of Atmega328-based boards by short range radio. Indeed right now I have 3 properties – two here in the Northeast and one in Spain which are using this successfully. But there were a lot of range issues with the radios and I was running out of steam with the 1284s and along came the ESP8266 chips… This opened up so many possibilities but I really needed something more powerful at the helm without spending more money (many have heard me say “I’m not spending £60 to switch a lightbulb”) – and in the nick of time along came the Raspberry Pi2 – which for £30 is a bargain even though you really have to learn just a little Linux to make good use of it.

The Raspberry Pi 2 was so new to me a matter of weeks ago (never had the original Pi) that I loaded the entire kitchen sink onto it. In anticipation that this might happen I bought a second Pi2. That gave me all sorts of issues, stalled keyboard, memory problems.. I w2as convinced it was the microSD chip… then I realised the other day that this could all be put down to a lousy power supply! I replaced that with something meaty and I’ve never looked back.  Mindful of the fact that my 32Gb microUSB drive for the first Pi2 was taking an hour or more to back up I went out and bought a Sandisk Extreme 16Gb and an Anker USB3 adaptor and that really made a difference – but still I was basing everything on a bloated software base. So this week I sat down and started from scratch.

You can save many, many megabytes by un-installing the rubbish that comes with the Pi2, that Wolfram thing which I cannot imagine any use for, the games etc. Having stripped the Pi down to essentials I then installed Webmin (and if you are not using this, why not?) – which by its nature needs PHP and MQSQL to run – and that’s fine as I have a use for both (graphing). When fitting the WIFI dongle to the board (who wants another wire) I realised I could do with the equivalent of the Windows WiFi properties window and stumbled on Conky – I’ll let you research that one. I then installed Mosquitto with some help from Mike at ThingStud.io (and others) and finally with LOADS of help from the guys responsible for Node-Red, put that up (the installation is very different to my first attempt).

With all of that in place and all the latest updates (courtesy of Webmin) I’ve barely used over 3.5GB which is excellent because as time goes on the size of the microSD will start to shrink if nothing else because these devices have limited lives and the more expensive chips have intelligence on-board to move data around as parts of the chip die. I’m hoping to get several years of life out of this when I’m done so the more spare capacity the better.

So there we are, a clean start on which to build my ESP8266 and Arduino-based home control.

Facebooktwittergoogle_pluspinterestlinkedin

Presents from Espressif

envelope from EspressifLet me start by explaining that Espressif are makers of fine WIFI gadgets.. specifically they have spawned a whole new lease of life for IOT… by producing a marvellous little chip that contains a complete processor, memory and WIFI interface needing only a tiny FLASH memory chip and a couple of “bits and bobs” to make a complete working WIFI router, or IOT device or web server – largely limited to the imagination for, well, a couple of pounds ££…  the price is really what does it – you can buy a little board complete with aerial for less than £2 from China which is just a complete game changer.

Espressif packageAnd for everyone else, well, you know I’ve been working with these chips since day one and am just about to start fitting controllers all over the house etc. based on an overall setup that has been years in the formulation (in English lots of false starts) and currently comprises NETIO for the user control end (possibly soon to be replaced by ThingStudio if all goes well with their current alpha software), Node-Red and Mosquito on a Raspberry Pi2, controlling lots and lots of ESP8266-based boards around the place.

And so… with that in mind I’ve been in contact a number of times with Espressif and they’ve been helpful and keep me up to date. So the other day I received an email to say they were sending me some stuff to play with!  This morning, an envelope arrived in the post.

ESP8266 stuffInside a large cardboard box –  inside that, a package and inside that – a development board and some little modules.

The modules look like ESP-12s but have 2 less connectors – which means no A/D output !! They do have an internal aerial and are marked ESP-Vroom-02 and are “developer only.   The pin-out is not compatible with the ESP-12 which is slightly painful as that means a new rig to program them!  At some point it will be clear to me why they made these, leaving out the A/D – but for now it’s a mystery.

More interesting perhaps is the development board.  It is rather tempting to compare it to another development board that appeared on Ebay a short while ago.

Compare ESP

 

THe Espressif development board is much smaller and neater but contains a unit that has no less than 24 pins coming out – the most I’ve EVER seen. It does not unfortunately have an internal aerial so I’ll have to go and hunt out a suitable screw-in job. The board is marked ESP8266EX Demo Board and has more connectors than you can shake a stick to. It has an infra-red input, but micro-USB uart and general micro-USB inputs, 5 switches…

and that’s about it  - just got this in the post, thought you might like to see the stuff – not done any experimenting yet, no doubt that will follow soon.

Facebooktwittergoogle_pluspinterestlinkedin

Mosquitto and Web Sockets

This entry is about ThinkStudio (thingstud.io), Web Sockets and Mosquitto in my quest for ESP nirvana.

So TODAY I was alerted to an early version of a new service which I think you might like… so check out http://www.thingstud.io/ 

Clarification: This is ALPHA software but already, provided they keep at it I think this has the potential to replace the rather slow-moving NETIO app which provides a nice user interface for IOT. 

mqttThis software uses MQTT which is right up my street.

Well, always one for a challenge, I went to the site, set up an account and…. nothing – not a thing. I put in my MOSQUITTO (MQTT) credentials and got absolutely no-where apart from having a nice pretty interface. They have a nice pop up live help (pretty amazing for an alpha product) and before long I was happily chatting away to Michael Karliner. It turns out that the product needs MQTT to have Websocket support which my Mosquitto on the Raspberry Pi does not.  I’ve been putting it off because every explanation I’ve seen up to now involves compilers and all sorts of horrible things.

I was pointed to this link… blog.thingstud.io which Michale had just completed - and in there is an article about installing Mosquitto with websockets. I was in one of those “devil may care” moods and so figured there was no reason why this could no upgrade my existing Mosquitto.

So I did – I followed the instructions from the start right up to but not including the bit about installing Node-Red as I’ve already done that.

WELL BLOW ME!!! it worked. Well… not quite. It over-wrote my mosquitto.conf file with a virgin one so now my security was bust and my local boards could not talk to anyone.

I opened the virgin mosquitto.conf which had everything commented out and added these lines as per the blog

listener 9001

protocol websockets

So now I could run a websocket on port 9001 (I tested that by redirecting the port on my external address then trying  http://www.hivemq.com/demos/websocket-client/ – worked a treat)

That allowed the websockets to work – on port 9001. But… my normal port would not work any more – 1883.. so I added this.

listener 1883

protocol mqtt

That got both pipes listening – all that was needed was to restore my user access.

allow_anonymous false

password_file /etc/mosquitto/passwords.txt

And Bob’s your uncle – the latest Mosquitto (which is just excellent) and now websockets.. which means I can write my own web pages to access MQTT if I want to!!! And no doubt I will – but if ThingStud.io works out –  I might not have to. Ensure you are registered to get updates in here or follow my usual Twitter and Facebook accounts to make sure you don’t miss out – I have a hunch about this one.

Update: Oh I found another link with instructions for installing websockets – and a little info on the mosquitto.conf file…

http://harizanov.com/wiki/wiki-home/raspberry-pi/how-to-rasbperry-pi-install-mosquitto-with-websockets-enable/

Facebooktwittergoogle_pluspinterestlinkedin

The DTR Line and ESP

Hitting an issue with ECLIPSE on the PC and the TERMINAL program.

So in our little board we’re using an ATTINY85 to control the programming process for the ESP12s…  

I have some issues..

If you’re using GPIO as an output to a relay… this whole process can cause the relay to click… the last thing you want to do if you have a lamp or heating system on that output.

Keeping things simple with 5v relays you really need to use an NPN transistor so just basing stuff on the 3v line is out.

In the ECLIPSE programming environment when programming, DTR goes low as does RTS, then RTS goes high, then DTR goes high then you program the chip. You can control all of that in ESPTOOL.PY

In the TERMINAL program addon for Eclipse, opening the terminal causes DTR to go LOW, HIGH, and LOW and STAY LOW!!!!

So my thoughts are to buffer the GPIO output to the relay via the TINY. On powerup the TINY output to relay is LOW…

So if the TINY sees DTR go low, it would pull both DTR and RESET LOW… if DTR STAYS LOW for more than a second… GPIO-0 is floated (Tiny pin becomes input) then RESET is floated (tristate on the Tiny) and  from that point on the relay output follows the input from GPIO  until DTR goes high then low and we start again.

If on the other hand DTR goes low then high, we assume programming, release RESET first then GPIO-0…  then we wait for no serial activity for a couple of seconds before resetting again and then following GPIO-0….

Make sense? I can’t find any way to control DTR on that Terminal program so this is the best I can come up with for now…

image

Facebooktwittergoogle_pluspinterestlinkedin

Node-Red Scheduler

I’m Peter Scargill and this is a scheduler for Node-Red (well, more of a timer really but someone surely has already used the term timer) for Node-Red which includes days and months, dawn and dusk with optional offsets and a time-out mode, You may notice this has improved since the first version – I’m learning as I go along.

Please note: This program was replaced some time ago with bigtimer – there is no down side – bigtimer is better. See http://tech.scargill.net/big-timer/

As you may know, I’m interested in using Node-Red on the Raspberry Pi (though for this purpose it could be any piece of kit) to control ESP8266 boards via a variety of mechanisms, one of them being MQTT.

Up until recently I would use a Node-Red standard  Inject function to trigger an event, lets say once a day. The Trigger function however is very limited. It does not know about months and it has no idea about concepts such as “dusk” and “dawn” which you might reasonably want to use for a porch light.

SunriseSo, I buckled down and learned how Node-Red nodes were made (with some help later from dceejay Dave and others in the googlegroups node-red group – for which I’m grateful) – and the first thing I did was to start off with the sunrise/sunset node (you’ll need that installed as I rely on one of their routines) to send the time, date, sunrise and sunset information to my boards based on longitude and latitude. In essence, in my case I use MQTT to tell boards about the time when they power up and at 12 hour intervals and in the meantime they maintain their own time in software.

However the more I get into Node-Red the more I see it doing the actual control… so the next thing I did was to sit down and wrote a node – again borrowing from the Sunrise calculations for dusk and dawn settings but gutted to actually send one of two messages (settable) to a message topic (settable and suitable for passing onto an MQTT node for example) at any given time with presets for dusk and dawn and allowing control over days and months as well as a time-out function (i.e. turn on at 10am for 5 minutes).  So a typical example might allow us to turn something on every Wednesday at dusk until midnight but only from November to January. My node of course does not actually send an MQTT message – it just passed the topic and message onto the relevant node (the MQTT node shown in purple here). You could use that message for a variety of other purposes – like sending you a tweet at regular intervals. That is so easy in Node-Red.

The code handles summer time adjustments (well, it did this time, you might want to check that very carefully). You can even offset the dusk and dawn offset times in minutes to save, say, lighting energy, I find garden lights come on WAY before you need them – hence building in the offsets.

Here’s what it all looks like.

scheduler[1]

So every minute, my node (in blue) self-triggers  (my thanks to dcjay for showing me how to add JS timers) to do it’s calculations and decide whether or not to send a message to the MQTT output node in purple (you could easily alter the code to do something other than send an MQTT output. You will notice in the image above that there are now TWO outputs.. the top output sends a message on change – i.e. when it wants to turn something on or off.. the lower output sends a simple 1 or 0 message every minute regardless – think of it as a regular status output just like the little text and icon indicator under the node itself in the picture above. In this case each output is also sending out a debug message to the debug window in green – that’s just for testing purposes.

If you double-click on my scheduler node, here’s what you get…

scheduler

 

Simple enough, give it a name (any name), on-time and off-time which includes every 15 minutes of the day and dusk and dawn dropdown options as well as timeout options for off time… then set your longitude and latitude (from Google Maps or memory if you are like that), the topic you want to send and the two messages – one to turn something on and another to turn something off. In my case I have an MQTT message system going to ESP8266 units – I’ve detailed this elsewhere in the blog.

Tick or un-tick boxes for the weekday/month combination you want. The code is checked once every minute but the top output only sends something out at power up or when the state changes.

If this isn’t powerful enough for you? – let’s say you want something to happen twice a day? – put two of them in there.

2 schedulers[4]

So – to make this work – i.e. to make your own node there are two files – and you just create a directory in your node-red/node-red-nodes folder called scheduler, dump these two files in and restart Node-Red.

The two files are the HTML file and the .JS file called scheduler.html and scheduler.js respectively.

If you make good use of this mode, a credit would be encourage me to support it.

Also if you spot any mistakes especially in the timing – or have ideas for improvement – do let me know.

The purpose for the timeout to the end time options – is so you can say for example – turn a sprinkler on every night for 5 minutes after dusk. And that’s exactly what I plan to use it for – but only in the summer months!

Attach for example an MQTT node onto the first output and put your broker details in there. The node will pick up the topic and message from my node.

And finally  – this code is deliberately NOT constantly sending out the ON instruction every minute but only when the state changes. At any time you can press the button on the left of the node to force an output of the currently relevant message.

Enough of this – here are the goods – no guarantee implied.

Some folk had issues reading the SOURCE CODE files – so I’ve put the files on Github here.. https://github.com/scargill/scheduler

This node is relatively simple but I think that’s the point. It still took me several days to get it right and I’d appreciate any testing reports.  My next job is a thermostat node and that’s coming along nicely.

Make sure you sign up to the blog to be kept up to date or, if you prefer social media – there’s always http://www.twitter.com/scargill  or http://www.facebook.com/petescargill

Facebooktwittergoogle_pluspinterestlinkedin