This is the original blog entry on the home control script – now replaced the this script.
Please ONLY use the script referred to in the new blog entry!
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:
and you get something like this rather nice display
As someone has put up an article entitled “ESP8266 Killer?” I thought I’d better step in..
There are two boards to look out for on Ebay – the EMW3165 - http://goo.gl/ccWgtT
and the NL6621-Y1 - http://goo.gl/qdMhtm
I noted one article suggested the EMW3165 was “just a dollar more than the ESP8266” – just in case anyone believed that – a simple comparison of Ebay prices brings the ESP-12 in at under £2 the NL6621 at £3 and the EMW3165 at £8.52
So I don’t think Espressif have anything to worry about yet and one could ask where all the documentation and examples are and development systems for these boards…
Anyone know better than me on this one?
I was just getting settled into my new office when BANG – a flood –not the global warming type but the crappy plumber type. So – right now the place is a bombsite and we’re sleeping elsewhere at least for tonight – indeed could be longer if they can’t get the water partly running.
Meanwhile a couple of items turned up in the post this morning which might interest you. Firstly I’ve been looking for small movement sensors – most of them are WAY too bulky – and I picked up a couple of these IR movement sensors from Banggood! 3 for a fiver. You can see how small the thing is comparing it to my normal size hand!
I already have a larger and slightly more obnoxious sensor inside. I need to put a light sensor in as well because I have lights coming on in my office during the day when it’s just not necessary.
So tonight I decided to give it a go (I have half the mains on – including my office which fortunately has electric heat). I hooked one of the units up to 5v and ground – (the outputs are ground, output and 5v in that order. Ground is obvious – lots of tracking and a minus sign). I hooked a LED to the output, switched on and… zilch.
Fortunately a little while ago I was fortunate enough to become the owner of a little NSCOPE – a USB low-bandwidth scope with breadboard – a wonderfully useful gadget. Well, that WORKED and on close inspection they have a 20k resistor in series with the output – clearly not meant for a LED but just fine for an ESP8266 or Arduino. The units pick up movement several metres away and at a range of angles… I’m thinking…. hole in the door frame – unit inserted in there somewhat recessed to reduce it’s angle of operation… picks up people near the door….
Meanwhile, one of the other competitors on the esp826.com annual ESP8266 competition (which I do not expect to win – mine is item 75 – vote if you like it) send me one of his units – it’s called a ZMOTE – a neat little infra-red learning remote.
I’ve not gone into it yet due to the flooding but you can find out about it on the ESP8266.COM website – I’ll do a write-up when I’m not running around with buckets.
So – I was asked recently if I would go into detail about the Node-Red thermostat node I wrote some time ago.. I was at pains to point out that I’ve not developed this further because I’m finding FUNCTIONS to be more useful. With the latter it is easier to just “dig in” and make changes – important when you’re developing..
The whole flow of my Thermostatic controls with add-ons, bells and whistles is way too much to go into – however the central function – the bit that controls the temperature is really quite simple.
There it is – so every 10 seconds it runs, reading some global variables and outputting an MQTT message to turn the heater on and off. As you can see it gives a summary underneath (I know the Node-Red guys are not keen an adding visual elements but that status display was a GREAD add in to functions).
And so the output just goes off to an MQTT node to turn the heat on and off. But what’s inside the function?
I originally put it in here but it is so long it will bore the PANTS off anyone only vaguely interested so I’ve put the entire code into a snippet on Bitbucket.
So just a couple of things to help with anyone wanting to look at this – PLEASE don’t ask me to support this as by the time you read it I’ll probably have changed the original – it’s a work in progress.
However reading the code above you’ll need a little help.
The above is just me being lazy – “stat” allows me to access the global var and it’s bits without having to type in the long name – I’ve a large object full of things like 5 sets of times per day during the week, same again for the weekend – each with an accompanying target temperature, there’s a manual offset to the temperature and last but not least, in the ESP board (MQTT) that is sensing the temperature I also control some serial LEDS to light it up blue when the heat is off and orange when it is on - that of course is totally over the top but I like going over the top.
There is also a frost temperature setting in there… most should be fairly obvious and if anyone wants to cannibalise this for their own use – by all means.
Just some minor updates…
If you’re using Blynk server locally for your IOT there is a new update – a fix for crashing with Raspberry Pi 3 and some other fixes by the look of it – link is here. Incidentally I just rename the server file to server.jar and restart Node-Red when they come out with a fix. I should say that mine is running on a pair of Raspberry Pi 2 boards and I’ve not had one error out of it in the last couple of months. I’m using the node-red-contrib-blynk-websockets library which continues (unlike the non-websockets version) to operate flawlessly. Now if only Blynk would get rid of the fixed on/off titles on buttons…
MQTT – TuanPM version – I noted a minor fix in there which explained some issues I’d had with retries on bad connections. About a month old but just in case you missed this - https://github.com/tuanpmt/esp_mqtt
Thanks to David Miles for alerting me to this cheap cat poo sensor – ordered a couple of China as no-one in Europe seems to be selling them on Ebay - http://www.ebay.co.uk/itm/272041590945 that should alert me to any cat-accidents – I’m wondering if it will pick up on kitchen smells – I’m thinking for our holiday cottage rental it could be useful to long-term monitor the air.
The code we use for our own IOT which is featured in Home Control 2016 and the Serial Nextion project (don’t forget to vote – item 75 in the ESP8266.com competition) has been updated to handle multiple SSIDs and is something I keep going back to and improving within the limitations of rapidly decreasing .TEXT memory in the ESP (my one gripe about the chip).
Still finding success with Imperihome Android App but the lack of general purpose buttons, sliders and LEDS is beginning to get to me – so many people putting in requests for specialised hardware, it seems to me that providing generalised inputs and outputs seems a more sensible route – I guess they must get a lot of mail as I’ve had no feedback from my requests. Hence I still need Blynk and node-red-contrib-ui to perform certain functions like setting on/off times and heating schedules for my thermostat.
And that’s about all that is new for now.
For those interested – I’ve been quiet the last couple of days as we’re ploughing ahead getting the new office up and running – got walls up and ceiling almost done – got power and Ethernet in last last night and today we’re off to get wall sockets and worktops. I have to say I have never known joint aches like it!
The dangers of controlling stuff over the Internet became apparent last night as the heating went awol. At some point we realised we were roasting to death at about the same time as the Sky box indicated it has no Ethernet. It turns out that in the process of wiring up Ethernet for the office, we’d uncovered a flaky connection to the main access point which provides all the ESPs with connectivity and feeds the Sky box.
Still – though it took until 1am in the morning to find the problem, at least it’s a clean problem with a clean solution – replacing an RJ45 connector.
Anyway a package turned up for me yesterday which I’ve not had time to do anything with yet - the Omega and a bunch of peripherals – so expect a review coming up soon.
Things have come quite a way since my first stab at using the Itead Nextion displays with an ESP8266. I now have a fully working thermostat display running on MQTT – but I’m beginning to wonder if 56KBaud is pushing it a bit for the software UART. Now that I’m pushing a reasonable amount of information onto the little display, I’m very occasionally seeing small glitches in incoming information when pushing buttons. Not enough to worry about but perhaps drop the speed down a notch.
Sometime I wonder…
So we have the SUDO command to keep everyone happy in Linux (Debian in this case) by not using ROOT – and on the Raspberry Pi that’s just fine – but every other board I’ve tested you seem to spend more time putting in the password.
Then I discovered this - http://askubuntu.com/questions/147241/execute-sudo-without-password
At the risk of repeating myself (apologies to regular readers for this first para) the Nextion display is in fact a range of touch-LCD displays from small to large. The thing they all have in common is a a complete programming environment where, by downloading a desktop graphical tool, you can lay out the display, what it will show and how it will respond to button presses. All of this happens serially so that you program it serially via, say an FTDI (usb-to-serial interface) and when you’re done and a button is pressed, serial output is sent back out to your application and you do what you want with that.
So first things first – what it IS, is an excellent low-cost way to get visual controls onto your IOT device. What it is not, is fun to program. There is a language interpreter built into both the display itself and the desktop “debug” simulator – and I would summarise by saying that it is probably the worst interpreter I have ever experienced since Bill Gates 5K BASIC back in the 80s. However, it works – and with a little effort you can soon bypass the inefficiencies of the interpreter and get the job done.
A friend of mine and I have been looking to use these in our IT projects for some time – and while a serial interface is great, it isn’t much use if you just want to stick a thermostat control on a wall 2 rooms away from where your controller is.
As many of you know I’m a Raspberry Pi/MQTT/Node-Red fan and so everything I do is oriented towards making peripherals that will talk via MQTT protocol, wirelessly back to the Pi – hence my interest in the SONOFF units as they are a VERY cheap mechanism for controlling lights etc – using my own software or that of others which you will have seen in here.
And so it was that Aidan and I set about making a little board to go on the back of the Nextion – the first one came back from the Chinese supplier with the top grounding disconnected – that gave us the opportunity to do a MKII which we’re expecting in a week or so which we actually think will make a GREAT general purpose board for experimenting with the ESP-12… but more of that later.
So – we’ll not concentrate on the communications angle here but on how I managed to get the nice buttons. That entire display is actually put together from TWO images – thanks to a feature of the Nextion called CROPPED IMAGE
One apparently BIG problem with the Nextion displays is their inability to handle transparent PNG images – like round buttons. On the surface this might be fine if you have a static background colour and can match it around the edges of the button -but this is often not the case. In order to work with limited processing power (and I suspect the limited programming ability or program space if the interpreter is anything to go by) they like to handle rectangular areas – these are easy to move about at high speed. But they have come up with a good solution to this – the cropped image.
So let’s say you make 2 images – one with everything turned OFF and one with everything turned on. A BUTTON can be a rectangular area with text on it – which looks ABSOLUTELY AWFUL – or it can be a CROPPED IMAGE – showing part of the chosen image depending on the state of the button. So a rectangular area over a round button showing a window into the overall ON image or the OFF image will give the impression that only the rounded area is changing – and you don’t have to worry about gradiated backgrounds etc.
In essence you use a basic image with everything shown turned off – i.e. the buttons are nothing more than a single image – in my case a pair of Powerpoint images – I use Powerpoint as it is easy to align images,
Use of the second image – with everything turned on – is controlled by the Nextion itself – that is selectively showing parts of that second image as needed – of course this is just a very BASIC example – you can have multiple pages, you could programmatically select more than just 2 alternatives (3 state button or LED… and the Nextions – if you get TOO ambitious – can handle an external SD for even more images. A cheap throwaway 256Meg SD holds quite a few images.
Thanks to advice from friends and people in here I found quite a few images – I put a link in the comments to a previous article – any transparent PNG images can be pulled into Powerpoint or similar to make up your basic pages - the cropping ability of the Nextion makes it possible to turn this into a dymamic display.
And so we come to the Nextion interpreter which is HORRIBLE. How do I get a button press (dual-state button) to send out the right info – this might look like a mess but when you get into the Nextion editor and have a go – you might thank me for this - no it isn’t my lousy programming that makes it look like this and no you can’t put it all one one line and yes, amazingly you can’t have a space after the IF statement – I’ve thought of volunteering to go over and help them with the interpreter!!! But it works so once you’ve done one – it’s a copy and paste job.
printh ff ff ff
As that data comes out of the Nextion, my ESP software picks it up, sends the message out over MQTT and triggers a timer for the little cheap phone buzzer for haptic feedback.
When we get our new boards and I get my office put together – I will endeavour to go into that side of the project – as I see a lot of future in this as a high quality, wireless touch display.