Wireless Home Cloud for the Crowd

by AlexanderTRU in Circuits > Sensors

9289 Views, 245 Favorites, 0 Comments

Wireless Home Cloud for the Crowd

2016-05-18_15-20-36.jpg

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.

The concept

  • 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:

  1. Sensors and controls (input) and
  2. Relays, valves etc. (ouput).

All of them are communicating with my server via simple wifi modules (ESP8266 also from Aliexpress).

  1. Inputs are sending their status data to database server.
  2. 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.

Smart Cloud Core

2016-06-21 10.30.35.jpg
2016-06-20 17.17.46.jpg

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:

  1. lighttpd web server for hosting pages of my interface (out of the box)
  2. php to make them interactive (out of the box)
  3. 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

Current configuration is stored at GitHub home cloud. Click "View Raw" to download zipped files.

Yes, mea culpa, I used a flash drive as a file storage, though big kids should not use NAND memory (mySQL requirements).

Standard Module

wifi module.png

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.

Downloads

Controlled Devices (output)

2016-05-07 20.18.55_2.jpg
2016-05-07 20.19.47.jpg
IMG_20160518_185734.jpg

The aim is to make periferal devices as simple as possible. For example a two relay (light switches) module consists of:

By and large below US $7

Sensors (input)

2016-04-25_10-06-29.png
2016-05-11 08.02.33.jpg

Sensing device consists of

Total about US $5

It sends temperature and humidity values every 3 minutes to server where they are stored in MySQL database.

Control

2016-05-18_15-21-26.png
2016-05-18_15-22-13.png
2016-05-18_15-23-40.png
2016-05-18_15-24-06.png
2016-05-18_15-20-36.png
Home Web Interface

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.

You always can add more devices to your control panel using simple HTML and JavaScript coding skills.

I use image maps with images built using quite simple program SweetHome 3D for navigating all around the house.

Advantages:

  • 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

Shortcomings:

  • 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.

Wireless Coverage Enhancement

2016-04-25_09-43-41.png
2016-06-20_15-31-31.png

I use Xiaomi WiFi Repeater (also under US $10 / piece)

When I examined the Wifi network coverage with Android app WiFi Coverage Mapper I found out where shoud I place my WiFi repeater to extend the coverage area.

Unleash Your Imagination

TouchPad controlled light

Much more people know how to code for the web (PHP, Javascript, HTML) than for MCUs (C++, Lua). Using this structure we can obtain, request, send data and controls with several php or js scripts. We can build a teachable system which can adapt to our habits, inform us of all irregularities.

Yet we have to state a couple of rules (just a common sense)

  1. Actuation devices (relays, drivers, etc.) shall be controlled by manual controls as well
  2. In case of emergency the system shall alert the owner (sms, email, red color of control panel, sound alarm, etc.)
  3. Take good care while handling high voltage.

For sure I will share all my know-how and outputs with anyone curious under standard disclamer.

Have fun!