Introduction: Wireless Home Cloud for the Crowd
I spent many hours replicating other people's projects on wireless smart things. Actually so many that I wound up with an obvious conclusion: After third or forth job you find out that all of them are made on different principles using different methods and tricks, especially after you redesign and reengineer some of them. That means your universe of things becomes completely unserviceable.
In other words you have to keep an enormous repository of specs and sketches. And you need more time to grapple with all your devices. Certainly some are more self-organized than I am, but for sure the majority of others in entropy response are kind of nothing to write home about. No offence meant.
What can I do to curb the invasion of my home by robots? (Anyway it's inevitable, isn't it)
Simple: Simpler things. Smarter cloud
As a matter of fact it's not an instructable in a general sense, it's more an example of how to make industrial level things using a set of simple tools.
- Things are as simple as possible: standard module to connect them to your private cloud. It consists of wireless unit and initialization scripts (both in module and on the server). If the module fails you just trow it away and replace with a new standard one. Cost gravity pulls their price to the floor.
- All the logic and intellect reside on the server. A simple linux router.
Simpler things. Smarter cloud
A tiny server (described in 1st step) is receiving data from sensors, storing them and giving commands to control devices. Your devices are not a crowd of cogitative things. They are just synapses of the server brain. That's plain and natural.
There are two types of devices on my network:
- Sensors and controls (input) and
- Relays, valves etc. (ouput).
All of them are communicating with my server via simple wifi modules (ESP8266 also from Aliexpress).
- Inputs are sending their status data to database server.
- Outputs receive and execute commands from the server.
As I mentioned no device has intelligence.
The goal is to keep things as simple as possible
All the logic stays on the server. Server has algorithms, triggers etc.
For example server makes a decision to switch on the heating if the temperature in certain rooms stays below certain level for certain period of time. Server makes a decision to turn the solenoid to water greenhouse if soil moisture falls below certain value and it's a daytime now. Of course a human can always cut in and get in control of everything or change the logic at any time.
Server shall inform the owner of critical issues by SMS. It shall obtain commands from particular phone numbers.
Step 1: Smart Cloud Core
I used a small wireless router with OpenWRT and extended memory capable of handling a web server and a database GL.iNet 6416A bought at Aliexpress (under USD25).
An amazingly tiny device by Chinese start-up provides us with:
- lighttpd web server for hosting pages of my interface (out of the box)
- php to make them interactive (out of the box)
- MySQL database for data storage (to be installed). Some use SQLite, but it's not able to process simultaneous requests, trash it.
This is my private cloud. It creates its own subnet (192.168.8.1) with own wifi network (with 6 inch long password :) accessible by my IoT devices only. It also has an external interface (WAN) connected to my ordinary home local network (assigned IP 192.168.1.100). I need it to have a control panel accessible from within my home wifi network.
Software I used for connecting to the server and database
- WinSCP - graphic FTP client to place files to the server
- HeidiSQL - graphic SQL client to develop the database
- PuTTy - SSH client to give commands to OpenWRT
Yes, mea culpa, I used a flash drive as a file storage, though big kids should not use NAND memory (mySQL requirements).
Step 2: Standard Module
WiFi module (ESP8266) stuffed with standard sketch. In two words, it reads last access point credentials, tries to connect to AP, if fails it starts up its own AP with web form where you enter new AP credentials (in case you replaced AP or AP's credentials). If it succedes it downloads scripts assinged to this module and runs it. We differentiate the modules by their unique MAC address.
On my cloud for each MAC there is a separate folder with it's job script at the location 192.168.8.1:86
So initally the module has three files on it:
AP_config - two lines: SSID and password
init.lua - connction to AP with credentials from AP_config. If failed - do("ap_request.lua"). If succeeded - upload job scripts and do them.
ap_request.lua - request for new AP credentials, putting them into AP_config (if connection with previous parameters failed)
I packed these files to the enclosed rar file.
Step 3: Controlled Devices (output)
Step 4: Sensors (input)
Step 5: Control
All the fun is in the cloud!
The sweetest part of all is that I don't have any conventional control panel. All interfaces are virtual. Buttons, switches, sliders are virtual. Of course I can make them real objects and I will make some.
Using this web site you can monitor sensors' history and current parameters, you can control lamps, valves, etc.
I use image maps with images built using quite simple program SweetHome 3D for navigating all around the house.
- Indipendence from Internet access (from Internet access and IoT service providers)
- Standard units - instant replaceability
- commodity hardware
- Reliable protocoles (TCP/IP, IEEE 802.11, SSL)
- Simple languages: PHP, Lua
- Easy start
- Easy (relatively) repeatability
- Adjustable web interface
- Single point of failure
- Network disturbances possible
Solutions to shortcomings:
- regular back-ups
- spare server. Good thing is it's not that expensive any more.
Step 6: Wireless Coverage Enhancement
Step 7: Unleash Your Imagination
Yet we have to state a couple of rules (just a common sense)
- Actuation devices (relays, drivers, etc.) shall be controlled by manual controls as well
- In case of emergency the system shall alert the owner (sms, email, red color of control panel, sound alarm, etc.)
- Take good care while handling high voltage.
For sure I will share all my know-how and outputs with anyone curious under standard disclamer.