Local server Configuration and registration
The concept of automation is closely related to the concept of autonomy. Therefore, the natural and fair desire of the owner of a smart home to strive to provide for the case when the cloud server will be out of reach. Although, in practice, we all realize that without the Internet is nowhere, but we are somehow eaten up by the thought from the inside: But what if they disconnect? Let's not look deeply into it and prove probabilities, just accept it as our evolutionary mental instinct that saved us earlier and requires satisfaction.
Computer for the server
If you decide to organize your own smart home server, you will first need a personal server computer. It will have to be with the controllers in one common local network. Which computer to choose? This question does not have an unambiguous answer. Yes, the simplest option is to use an old system unit as a server. However, it can be quite noisy, and unreliable. There is an option to use single-board computers, such as Raspberry Pi. Their power will be enough, but you should pay attention to the peculiarities of their work with Flash-cards, which may have a limited lifespan. From our practice, the most stable solution will be a server based on the Mini ITX form factor. Such computers are more stable, less noisy and small-sized.
OS and software installation
After choosing a computer for the server, you will need to install an operating system (OS) on it. It is possible, and even likely, that the home server will perform a number of tasks. For example, it can act as a shared network storage (NAS), support video surveillance, implement PBX tasks for IP-telephony, be a game server and of course already hold some software (software) for the organization of a smart home. Therefore, it is difficult to recommend any OS for your server, because it must take into account all your tasks. We, in our turn, have realized the SmartESP server in such a way that it can be installed on the maximum number of different computer platforms.
This technology is called containerization and allows you to run different services with their specific requirements on the same system. We use Docker technology, which allows the SmartESP server to be installed in a separate container. The server installation process is simple enough for a novice administrator and is described below.
Let's assume that you already have a home server with a Linux family OS installed, for example you can use Ubuntu 20.04 LTS.
- Preparing directories:
- Create a new directory that will become the main directory for the project:
$ mkdir /var/smartesp
- Create a directory for the database:
$ mkdir /var/smartesp/db
- Set up configuration files:
- Navigate to the working directory of the project:
$ cd /var/smartesp
- Create and edit the file
config.ini
with the following contents (You can use the command:nano config.ini
):; Code page
CHARSET = "UTF-8"
; Database
DB_HOST_NAME = "db"
DB_NAME = "smartesp_db"
DB_USER_NAME = "smartesp_user"
DB_USER_PASS = "smartesp_pass"
; Secret key to restrict calling of the special cron-scripts
MASTER_KEY = "master_key"
; User registration secret key (allow all if empty)
REGISTER_KEY = ""
; Log retention period with full report, days
SAVE_LOG_PERIOD = 2
; Retention period for the summarized report archive, days
SAVE_ARCHIVE_PERIOD = 1000 - Create and edit the file
docker-compose.yml
with the following contents (you can use the command:nano docker-compose.yml
):version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql_passkey
MYSQL_DATABASE: smartesp_db
MYSQL_USER: smartesp_user
MYSQL_PASSWORD: smartesp_pass
volumes:
- /var/smartesp/db:/var/lib/mysql
restart: always
web:
depends_on:
- db
image: smartesp/smartesp-vega:stable
volumes:
- /var/smartesp/config.ini:/var/www/html/config.ini
ports: - 80:80
restart: always - Install and start the container:
- Make sure you have installed Docker Engine and Docker Compose
- Download the server image: docker:/smartesp/smartesp-vega:
$ docker pull smartesp/smartesp-vega:stable
- Run your docker container and related services in the background:
$ docker-compose up -d
- Configure Task Scheduler. open the current user's cron table with the command:
$ crontab -e
and add the following tasks:3 0 * * * * * /usr/bin/wget -O /dev/null -T 10 -t 1 http://192.168.XXX.XXX/cron/service/master_key/
is the IP address of your server on the local network.
* * * * * * * /usr/bin/wget -O /dev/null -T 59 -t 1 http://192.168.XXX.XXX/cron/auto/master_key/ 192.168.XXX.XXX
In case you need to stop and update or restart the container, you can do it as follows:$ docker-compose down
$ docker pull smartesp/smartesp-vega:stable
$ docker-compose up -d
After starting the container, it will take some time until the database is created. Therefore, when opening the site, a message may appear Connection refused. Просто подождите несколько минут и обновите страницу.
After installing the server, open it in a browser and perform the initial installation (database creation) by clicking the Start button.
After that, perform the standard registration of a new user.
That's it! Your own server is ready to work.
Registering a local server
There are a few other interesting and important things worth mentioning.
First of all, it is the ability to receive notifications. Even though your own server is local, it does not mean that you will be near it all the time. The server can be connected to the Internet, which gives you a very useful opportunity to send notifications about critical conditions of the smart home. A notification system is implemented in every project and can be extremely important. Here is an example of automatic notifications created for a climate control project:
To receive notifications, you must register on the SmartESP website in your Personal section.
After registration, go to the Servers section and click New Server.
In the window that appears, specify a conditional Name for your server and select the option Local. In addition to this field, you will need to specify the License Code. To do this, log in to your own server as a user and go to the Account section, where your unique license code will be available. Copy it here.
Click Save and a new entry will appear in the list of your servers.
To confirm it, click Submit and you will immediately be given the corresponding license key.
Copy it and go back to your own server in the control panel. Edit the License Key field by pasting the previously copied number.
Done! Now your own local server is able to send notifications via our cloud server to your Telegram messenger.