What’s this about?
This is the UK website for Peter and Maureen Scargill. We live in the Northeast of England and also on occasion in Andalucia in Spain.

Read through the blog entries, menu-accessible pages and archives if you're interested! Welcome to Peter and Maureen's website.

Want to view this on your mobile? - go ahead - there's a special version just for you. Same address.

Get in touch via Facebook My Facebook Page
You should follow me on Twitter Follow me on Twitter
Join me on  Google+ Join me on Google+
Join my LinkedIn network Join my LinkedIn network
My Pinterest Pinterest

Pete's Online CV

Home Control over the Internet

Updated June 29, 2013

This article is about a practical home control system for the enthusiast and is being updated as new developments come along. Combining extremely low cost radio and inexpensive Ethernet, the system allows for mobile phone or tablet access to a range of items including lamp control, temperature monitoring (and thermostatic control and general analog inputs)… and this is just the beginning:

tmp901ERecently I’ve turned to working with what are called “Arduino” chips and boards – actually the only “Arduino” bit I use is their boot loader routine – the boards I use are usually ATMEL chips on boards I’ve designed (or kluged)… the chip is a simple microcontroller (not powerful enough to call a “Microprocessor” but a hell of a lot nicer than the PIC chips we used a decade ago.

The Atmel chips are fun devices that are (relatively) easy to use and there are several boards available cheaply, mainly from China or Chinese companies in the UK that make this whole control thing worth looking at again. More’s the point there are lots of libraries – some working, some part working out there to save re-inventing the wheel.

The big issue for me has always been the wires. Much better to control stuff via, say, a mobile phone and have the units work by radio… but it has to be CHEAP to be worthwhile.

That is the basis of the project I’m working on right now. On the left you’ll see the first experimental screen of my Samsung S4 project (though it works seamlessly on any Android or iPhone-type device such as a tablet). For the purpose of experimentation, this screen is showing local 4 on/off type controls, 5 remote station on-off/off controls 4 remote on-off controls, time (from the base unit), temperature monitors from the base unit (internal/external) and temperature and humidity from a small unit at the end of the radio chain… but that’s just the start.

Note (June 23) – I’ve made a decision, rather than continue to struggle with space on the master unit – and in order to use the same final circuit board on the master as will be used on the slaves – to eliminate IO control on the master – hence freeing up plenty of space. The master unit will concern itself with handling keepalive signals from the slaves, talking to the Internet and handling thermostatic calculations. After much thought this is the better way to go rather than having special cases all over the place for “local” controls.

The DISPLAY is made possible by software which costs a pound or so called NETIO and is available for Android and iOS. It is a customisable App that works on the phone complete with web tools to develop such panels without programming as such.

tmp4692Essentially, the panel works by sending simple commands from the phone over WIFI or 3G to a web server running what is referred to as a WEB SOCKET – i.e. the basic underlying mechanism behind a web page but without all the extras – after all we’re talking simple commands here – it just needs to be very reliable.

And what and where is the “socket server”? It is software running on an Atmel chip of course – but the server is relatively simple (it’s actually complicated but we don’t need to know that as we just use a freely available library accepting commands and returning text responses). The rest of the code on the Arduino concerns itself with checking temperatures and firing off remote commands by radio to other boards. The App merely puts the end-user gloss on it. The radio is based on something I’ve written about before – RF24NETWORK which never worked properly in the past due to a minor issue in the underlying radio library and my own incompetence in not putting a smoothing capacitor on the radio board. But that’s all covered elsewhere.

Currently I have a board sitting on my bench talking to the App on my phone, over the Internet. On the top right you’ll see an image – I’m using a standard board for the purpose of experimenting – an Arduino Uno board at the back with an Ethernet “shield” sitting on top of it – together with a couple of test-wired Dallas 3-pin temperature-reading chips that look like simple transistors and actually only need 2 wires to work (but I’m using 3). In the foreground is a twin relay board of the type I’m using to control things such as lights or heating system thermostat replacement. I could just as easily use opto-coupled triacs. Note that the final unit has no wiring for LOCAL controls – these are all handled on the slave radio units.

In addition, there was enough room in the master board software to call an Internet TIME service and that keeps the local clock accurate – and also sends the time in the 4-byte time_t format to the slaves. As these have the real time clock software in them – they can be updated automatically by incoming packages – and hence use the time for whatever purpose…. providing time displays on household gadgets etc… one example – I have a SAD light in the bedroom which runs on a software clock only which in time becomes inaccurate – with the simple addition of the radio network and a little software, this when upgraded will keep perfect time.

Arduino with Ethernet shieldNote the yellow Internet lead and underneath (top picture) , a simple plug-in the wall power supply (5v) feeds the lot.

This is only for the purpose of testing and the hardware above probably comes to £30 – but an Arduino clone can be had for as little as £4 or so, while the  “Ethernet shield” will hopefully be replaced by a cheaper Ethernet board which can cost barely more than £4. Currently the one I’m using is around £12 – but this is only needed on your main board! The slave boards are even more inexpensive as all they need is a radio card – and so you can see it is possible to put together something for very little money.

The radio unit at the end of the chain shown below right costs excluding case and USB power less than a tenner. That board is the one supplying temperature and humidity readings in the top display. The blue item underneath is the sensor – it is pointless putting it inside the case as any residual heat no matter how little in the circuitry will affect readings.

The cheap ENC network cards are not as easy to use for “web sockets” because a lot more is left to the imagesoftware (that’s why they are cheaper) and socket implementations to date have been few and far between but thanks to work by Peter Oakes in Canada who’s been helping me with this, it looks like the ENC board is cracked all but for a question of reliability – we have a working socket implementation using code originally written for the Nanode boards. Right now it falls over occasionally so I’m leaving it to one side while I get the rest perfected.

The second screen on the right above is merely a test page showing 6 local slider controls and analog inputs from 5 boards – the last one being located way down the radio network chain at the other side of the house.

tmp66A1So that gives us one card controlled by the Internet. How does that make a home control? The next stage is to have that card also talk to a wireless controller – to talk to other boards. The cost of wireless is similarly inexpensive but very limited.

The NRF boards will typically talk DIRECTLY to 5 other boards (they CAN talk to more but typical libraries out there limit themselves to 5) over the kind of range you’ll see for cheap home WIFI – i.e. not very far and definitely not through more than a couple of walls – what’s needed is a means to network them – and that’s where the software library RF24NETWORK comes in – a simple means to network dozens of these together. It may be in this case that the network is not needed – the fact that the main unit can talk to 5 other radio boards may well be sufficient and if not then simply relaying software from one to the next takes that up to 25 boards and way beyond.

The NETio designer is in touch and has been helpful. Next step is to fully test it on the really cheap Ethernet boards (done that but not yet happy about potential memory leaks). I’ve already had success with the radio boards and the rest is easy. Here are a couple of early blogs on the subject of the radio network… and with links to other resources.

Current prototypes feature:

2 12-bit analog inputs (had 4 but needed pins 0 and 1 to check serially…)

3 digital outputs

3 analog PWM outputs (ideal for LED LIGHTING by adding a MOSFET and 12v supply for the lighting – again a plug in the wall job)

2 DHT11/22 chip temperature inputs (I have implemented both humidity and temperature – could have used Dallas chips for temperature but this seemed like 2 for 1).

You can add as many radio boards as you need and each one has the same facility.

The THIRD screen (left, above) is the thermostat control page – I’ve added the ability to control a single remote relay as the thermostat chip -  with the kind of control (heat delay etc) you’d expect from a Thermostat.

Alongside this I’ve asked the NETio designers if they will consider implementing MQTT – as this adds security – we already have MQTT working on the ENC boards thanks to a Saturday session with friend Jonathan Farmer and a lot of follow up work. For now my security consists of sending a special character string to allow access to other functions – that times out after 60 seconds unless refreshed by the App. Hey – it works!

Current state of the art

NOTE IN THE CURRENT WORK I’ve SCRAPPED IO shown on the master unit – I was determined to stick with the 328 and I was running out of both RAM and ROM. Currently I have enough memory to do the job using the WIZ network card (hence saving RAM)… and ROM I’m up to 26.6k out of 30k available.

The way this works (and I have a working setup on my desk)…. the units responds to commands such as x/OUT1=1  or x/OUT1=0  where x is the unit number in octal (base 8 – hence 0 1 2 3 4 5 6 7 10 11 12 etc)

tmp652BThe word OUT1 on it’s own returns the status of that output – and so on. So 2/OUT1=1 would turn on output 2 on the radio slave “2” for example. In the picture above, lets say the radio board that has a blue arrow to it’s right is radio 2. To handle relaying of these short range radios, that radio can talk to radio “22” as well as 4 other siblings. – radio “22” can talk to 5 siblings – “122” through “522” etc., the further down the chain the more you add on the LEFT of the address. So  522/OUT1=1 would turn on the smallest board on the right, picture above, the 5th one.

So – at level 1 the base can talk to 5 units… next level in it can talk to 5+(5*5) = 30 units. At the next level 5+(5*5)+(5*5*5)=155 units – next level out increases dramatically to 780 units – ANY unit can talk to any other but the parents MUST be turned on (hey what do you want for a few pounds)… I think 4 levels (780 units) is likely sufficient (and polling such a large number would likely be impractical but it does give you a good hopping range given the limitations of the cheap radios) and in my prototype setup I can run a slider on the phone and vary the brightness of a LED on the farthest unit virtually in real time with only a tiny, fractional second delay.

Arduino clone plus radioFor an absolute minimal slave board you just need the radio and one of the small surface mount Arduino clones such as the one shown on the left here. We’re looking at no more than £6 plus power (5v – i.e. any old USB plug-in-the-wall supply available for less than £3) – this needs something like a relay to drive a lamp or heating – and that’s it – clearly if you want more – add more. That whole board is the size of my thumb!

And that’s it – the first fruits of this work will be to put temperature monitors and light/heat control in our rental cottage and our place in Spain so I have access to this and other information on the phone. Implementing a movement counter with a simple infra-red is another idea etc.… I need some boards first as right now this is all a bit too spaghetti.

I’m currently making mods to store in EPROM, settable remotely, the unit number from which to  get the temperature for thermostatic control – and the unit which you need to talk to in order to turn the heat on by a relay. I’ve also clarified my worst fear – RF24NETWORK cannot handle sending out one communication after another while expecting to READ communications… so I’ve arranged that data is only initiated by unit 0 – which then always expects a response back. I’ve arranged a timeout for 0.2 seconds for expected data return before sending the next package out – obviously cancelling that delay when something comes in – with that in place and only with that in place I’m getting 99% reliability out of the radio packages. I’ve just added multiple retries (rarely needed) and with that I seem to be getting 100%.

And now a little history – you can stop reading now if you’re not interested but this might help to understand how I got this far… Once upon a time in the 90s, my business partner (of the time) and I developed a home control project called Appcon which consisted of a small board with various sensors and outputs – a triac (solid-state relay) to control, say lighting or heating, a temperature sensor, a general input and a speaker output. Click these pictures to see larger versions.

1994 PC AnswersThis small board ran from 12 volts and connected to other boards via a 4-core telephone wire.  at one end of the wire was a PC firing out commands, reading data and generally controlling the whole thing with a set of rules.

imageIt was developed on the original Windows 3.1 before the time of widely available Internet and LONG before we could buy cheap stuff from China.

This worked well, in my house in Newcastle I had around 40 of these cigarette-pack sized boards controlling just about everything from heating, lighting, burglar alarm, putting out “cricket” sounds in the garden, you name it.

The problem in developing this was the nature of construction – the fact that the boards had to be wired together was a real issue. In some homes it’s just not that easy to put a wire all over the place to connect everything together. It certainly is not in my stone-walled country cottage today.. I’d get shot!

The interface was good but as Windows matured it rapidly started to date and there was no such thing as a mobile phone interface! Today you would not think of using this (well, I wouldn’t!)

That product was GREAT fun and we sold quite a lot of them, but at the end of the day, home control remained a minority sport and we never did get this into the B&Qs of this world. Meanwhile, particularly in the UK, what’s out there remains expensive. Not too many people want to shell out £30-50 just to turn a light on and off!

This all sprang up from my original article on a cottage thermostat in which I envisaged a very simple controller. Then came the UberBareBoard article about an Atmega328-based Arduino clone, initial attempts to master the NRF24L01 radio and after this I wrote part 2

One Response to “Home Control over the Internet”