For some time I've wanted to tinker around with using the internet as a means of monitoring and control.
There's an appreciation that the growth in internet applications will likely be for internet connected devices - The Internet of Things, Web 2.0, or in sci-fi speak "The Rise of the Machines". Whilst not quite in Terminator league, I thought I'd get an internet dev board from Microchip and see what I could cook up.
The first step was to connect it up to a low power wireless transmitter, so that it could extend the scope of its control, beyond the confines of its own pcb.
I'm fascinated by minimalist solutions, and also hacking old gadgets to improve their performance or functionality. I like the idea of a network of very low cost wireless sensors scattered around the house, such as temperature sensors in every room linked to motorised radiator valves - all of which can be monitored and controlled remotely via the internet.
The key thing is that the sensors can talk to each other - regardless of the type of microcontroller make or model. So they need a standard serial communications protocol that they all can generate and decode. This protocol needs to have a low overhead to run on the smallest of micros with limited on chip resources and simple to hack and debug - more on this later.
I've coined the term "CheaperNet" to describe this network of low cost sensors, and so to get me started, I first needed a low cost candidate to be the first CheaperNet application.
There's a Homecamp Christmas party coming up soon, with talk of internet connected Chrismas lights - so I thought I'd hack together an internet controlled mains switch by way of a demo for a "show and tell" session to illustrate some of the virtues of CheaperNet.
This involves several stages of connectivity. Firstly using the PIC dev board which hosts a micro web server, using the free Microchip TCP/IP stack and the HTTP2 sever application that comes with it. This board acts as a kind of hub/gateway device onto the CheaperNet, and then radiating out from this hub is a a 433MHz wireless link to individual sensors. The first of these being the remote controlled mains socket. Plenty opportunities for a good hardware and firmware hack.
As stated, the PICDEM.Net dev board acts as a micro webserver. This is an almost "out of the box" solution requiring very little configuration to get you connected. The harder step would be to hack it to control a wireless link to a remote control socket which turns the electrical load on using a relay. Fortunately the PICDEM board has some LED outputs which can be turned on and off from the net, so if I could sense one of these I/O pins changing state and generate a wireless message to turn the remote relay on, it would be a simple enough hack.
The PICDEM board is a stupidly big board for what it does. All you really need is the £5 PIC in the middle and the ethernet connector. The little board below could also be dumped if you drive the 433MHz wireless transmitter straight off the I/O of the larger PIC.
The idea being that I can display my live electricity consumption in one browser window, and at the same time click on a button in another browser window that activates the Internet Socket turning something on - so that you can see almost immediately the effect on the live power trace.
A bit geekish perhaps - but worth a challenge. Good way to turn the Christmas lights on at the forthcoming Homecamp party.
The first thing to do was to salvage the old unreliable remote control socket that I purchased as a set of 4 from Lidls a few years ago.
These consist of a 433MHz super-regenerative receiver, a microcontroller and a mains relay all packaged in a plug in plastic case. Unfortunately, these suffer from any old 433MHz interference will cause them to turn on, or off, because of a very poor wireless protocol, which is readily confused by any other wireless devices nearby.
The solution was to implement a simple wireless protocol called SNAP at each end of the wireless link, and bodge a new microcontroller into the spare space in the plastic case. Probably the closest thing this cheapo Lidl switch has had to a brain transplant!
The existing Lidl microcontroller is dumped and replaced with one a little less stupid. The Lidl decoder was very prone to falsely switching when some other 433MHz transmissions - like the neighbours door bell started transmitting. I'm using a PIC16F88, solely because a have a few of them lying around the workroom and I have the beginnings of the SNAP wireless protocol already used on a past project
So after a few hours on Friday, I got the wireless protocol to work, and a few hours today got the unit together with new brain and a suitable wireless interface on my micro webserver dev board and voila I now have a desk lamp that can turned on and off from anywhere on the planet - or perhaps beyond.
This is a SnapRat board - just a PIC16F88 with a 433MHz wireless transmitter. I designed these a few years ago to make a solar powered wireless compost heap temperature monitor - definitely a world's first.
When you click on the 8th LED button on the web page, the micro on PICDEM board raises on of it's I/O pins (to light a real LED) I use the SnapRat board to monitor this and send a "relay-on" message to the receiver and PIC inside the remote socket. This turns the relay on - at a distance of about 20m indoors.
Some of the detail.
The PIC micro web server uses the Microchip TCP/IP stack. There are several dev boards which run this stack - such as those from Olimex or Celeritous.
I use a PIC16F88 to run the wireless protocol at both ends. The protocol is called SNAP (Scaleable Network Address Protocol) and details can be found on the High Tech Horizons site www.hth.com/snap/
I use a PIC implementation that is based on the published code by CASTRICINI & MARINANGELI - originally written for a PIC16F84. (See the HTH site). The whole protocol fits into about 850 words of ROM including the serial transmit and receive bit banging routines, error handling etc.
SNAP was designed to be a minimalist protocol to run on small micros. There are versions of it for BASIC Stamps and AVRs. Someone has bound to have hacked it onto an Arduino - if not - please would someone rise to this challenge.
If you want to see my firmware - leave me a comment.
Well done on a clear explanation of a complex subject. I bought the same Lidl remote sockets and had the same problem. Disappointed product from a German brand. I may still have them and now have a project to use them, or pass them to someone who could.
ReplyDeleteVery nice project, only a pitty you do not posted schematics and source code.
ReplyDelete