📜 ⬆️ ⬇️

Wireless home cloud for internet stuff

I spent many hours repeating projects of others on smart wireless things. This led me to the obvious conclusion: after the third or fourth project, you discover that they are all implemented on different principles, using different technologies and techniques, especially after you have changed or modernized some of them. This means that your world of things becomes completely out of service.

In other words, you must support huge libraries of specifications and codes. And it takes more time to cope with all their devices. Certainly, some are more organized than me, but, for sure, the majority in the fight against entropy have achieved minor successes. No offense.

What to do to curb the invasion of robots in your home (and this is in any case inevitable)? .. It's simple. Things are easier. The cloud is smarter.
')
Concept

  1. Devices as simple as possible: standard communication module with a private cloud. It consists of a wireless module and initialization scripts (both in the module and on the server). If the module fails, we discard it and change it to a new standard module.
  2. All logic and intelligence is located on the server. A simple Linux router.


Things are easier. Cloud smarter

The tiny server receives data from sensors, stores them and sends commands to the actuators. Now your devices are not a crowd of thinking things. They are only synapses in the brain of the server. It is simple and natural.

There are two types of devices on my network:


All of them communicate with the server via wifi modules (ESP8266 from a famous Chinese store). Inputs send their status data to a database server. Outputs accept and execute commands from the server. As I mentioned, there is no reason for devices.

The goal is to make things as simple as possible.

All logic remains on the server. On the server, all algorithms, triggers, etc. For example, the server decides to turn on the heating if the temperature in certain areas drops below a certain level for a certain amount of time. The server decides to open the solenoid solenoid valve in the greenhouse if the soil moisture has dropped to a certain level at a certain time of day. Naturally, a person can always intervene and take control in his hands or change the logic. The server also notifies the owner of critical events via SMS. It can receive commands from certain phones.

The core of the smart cloud


image

image

I used a small wireless router with OpenWRT and extended memory, capable of containing a web server and a database server - Gl-iNet 6416A no more than 25 USD.

Amazingly tiny device gives us:

  1. Lighttpd web server for hosting interface pages (preinstalled)
  2. php to be interactive (preinstalled)
  3. MySQL database server for data storage (installed). Someone uses SQlite, but he is not able to handle simultaneous requests, into the firebox

This is my private cloud. It creates its own network subnet (192.168.8.1), its own wifi network, accessible only to my things. It also has an external interface (WAN) connected to my regular home router (with the assigned address 192.168.1.100). It is needed to access the control panel from my home wifi network.

Application software used in the project:


The current configuration is stored on GitHub .

And yes, it's to blame, I used a flash drive as file storage, although as an adult I should not use NAND memory (mySQL requirement).

Standard module


image

The wifi module (ESP8266) is filled with a standard sketch. In short, he reads the parameters of the last access to the access point, tries to connect to it, if he fails, he starts his access point and the page with the form for new access parameters. And if he manages to connect, he downloads the scripts intended for this module from the server and starts them. Modules differ in MAC address.

In my cloud for each MAC address there is a dedicated daddy with working scripts at 192.168.8.1:86

So, initially the module has only three scripts:

AP_config - two lines: SSID and password.

init.lua — connects to an access point with saved settings from AP_config. If unsuccessful, run do (“ap_request.lua”). With luck - download the working scripts and run them.

ap_request.lua - request for new access parameters to the access point, write them to the AP_config file (if the connection with the pre-set ones failed).

Module scripts

Managed devices


image

image

image

The goal is to make peripherals as simple as possible. For example, a module with two relays (light switches) consists of:


Everything about everything - 7 USD.

Sensors (inputs)


image

image

A device with a sensor consists of:


All not more than 5 USD.

It measures the temperature and humidity readings and sends it to the server every 3 minutes, where they are stored in the mySQL database.

Control


image

image

image

image

image



All the fun on the server!


The most interesting thing is that I do not have the usual control panels. All interfaces are virtual. Buttons, switches, engines are virtual. Of course, you can make them real and some of them I will.

Through this site we can observe the history of sensors and current values, we can control lamps, valves, etc.
You can always add new devices to the panel with simple HTML and Javascript coding skills.

I used reference maps with images built in the SweetHome 3D simple program to organize home navigation.

Turn on your imagination


Far more people know how to code for the web (PHP, Javascript, HTML) than for controllers (C ++, Lua). With this structure, we can receive, request, send data and commands using simple php or js scripts. We can build a learning system that can adapt to our habits, tell us about incidents.

Source: https://habr.com/ru/post/396755/


All Articles