Home Automation System Architecture, Communication and Server using PHP Laravel

Home Automation System Architecture, Communication and Server using PHP Laravel and Websocket for communication.

In this blog post i will try to explain my thoughts about the home automation system architecture, communication between module and server, and an administration panel for Home Automation systems.

The server side is build using PHP and will use Websocket for communication with other modules. Even Though it is preferred to use protocols like MQTT, i will be doing without MQTT. Websocket handling and admin panel side is build with Laravel PHP framework.

Module-Things Based System Architecture

The Home Automation system should be module based, which means we can add/remove modules on the fly. The system should capable of integrating multiple type of modules and and follow a common communication standard, which will help for developing module independent of knowing about internal working on central server. This allows more flexibility to develop module much faster and more flexibility on which hardware to use.

Module-Things Based System Architecture

Module-Things Based System Architecture


A Module is is an endpoint with an communication, processing and storage capabilities. The module will be connected to multiple things. Things are normally I/O devices including Sensors, Relays, LEDs, Displays, Motor etc. Things does not need to have its own processing or communication capabilities. Module controller interact with Things and communicate with server. Module itself is responsible for managing any failover conditions of its things. These failover conditions include any communication failure with server, any sensor or output device failure etc.
The example of the Module include, but not limited to,

  • ESP8266 Relay board controller.
  • ESP8266 based water level sensor.
  • Raspberry Pi which connected to Temp-Humidity sensor & Relay.
  • Arduino Board which connected to Motion Sensor and LED indicator.
  • Web based Admin Dashboard which has multiple user inputs.

The microprocessor in the module is also responsible for Establishing network connection(WiFi) connect to server, authenticate itself to server, initializing things, updating status to the server, execute commands from server and provide temporary storage if required. Modules does have full duplex communication to server through websocket. The module and things have unique IDs, which used to identify each modules by the server.

Modules and things can perform individual functionalities. But to perform automated decisions, multiple things need to work together. That is where is the roles of System comes in. System is functionality of a home automation system. System does have multiple input and output things and decisions and data processing section on server module. For example, Automatic water level control is a system. Which have ultrasonic water level sensor and Motor switching relay as things and Server have its own control and processing module with configurable settings.

Communication flow

Every module communicate with server though websocket. Once network connection established, module proceed to connect to server using IP address and port number. After establishing websocket connection module will send server registration request, which include MODULEID and AUTHKEY. This request is validated by server and once it matches with the values in server, it will make module as online and notify other related modules listening for that. Then server send response back to module with initial configuration and status data required.

IoT System communication flow

IoT System communication flow


If a thing(eg.sensor) have an data update to server, the module connected to it will send update to server with Thing ID. once server got the sensor value update it log data on server and notify systems and module about the change. The systems logic process that change in value and perform required actions. If server need to send an update to module it send data to parent module with module value and new value. The module received the value and make changes to thing and send acknowledgement response back to server. All the modules in the follow same communication flow. This make adding or removing modules much easier.

Download source Contribute


Websocket server is build using a composer package which is compatible with Laravel framework. The websocket package provides configuration options like listening port number and IP address. This websocket library also need a handler for handling websocket events. Event include common events like ‘serverStart’, ‘onConnect’, ‘onDisconnect’ and custom configurable events.

Admin Panel

Admin panel provides basic interface for homeowners to manage all modules, things and systems. It also provides full interface to control and view history of each Things connected. Current admin panel include functionality to switch Room Light, Water Motor, LED Light, LED Light color change etc. The responsive web interface allows you to view and manage systems anywhere in the world using any devices.

Admin Panel Home Automation

Admin Panel Home Automation


Admin panel is completely built using laravel framework. And current version of admin panel include basic demonstration functionalities. Full code of server and admin panel is available in following git repo.

Download source Contribute

Future upgrades

  • Implementation of server using NodeJs
  • System wise programmatic model to easy switching of modules
  • Homeowner login and dynamic addition of modules
  • UX optimized Single page front end web app using AngularJS 2

This is my first try to develop a server system for IoT experiments. Please share your thoughts, suggestions or any questions below.

Thanks.

Previous:
Next:

Tagged with: