Smart Home – Programming and integration with Apache Web Server

Smart Home – Programming and integration with Apache Web Server

Smart Home
eHouse – Integration and software development for the Apache webserver .
Apache is the most common and free solution of web server, working on the Windows , Linux and various hardware and software platforms.
It has very big functionality :

  • Highly scalable for different operating systems and types of equipment (PC ) ( Intel , ARM , ATOM , AMD , Samsung , etc. . )
  • High level of security , authorization , login , certificates , encryption
  • High stability and reliability
  • Ability to create custom modules that integrate with Apache to the “outside world”

For this reason we decided to create a module which integrates the eHouse Intelligent Home with Apache Web Server.
This allows safe operation and control from Internet browser or additional integration with other computer aided systems via “Get” and “Post” methods.
The module is intended to be “gateway” between eHouse system (application “eHouse4cServer”, “eHouse.PRO” ) and Web Browser .

  • eHouse Intelligent home controllers( Ethernet , RS485, eHouse.PRO, eHouse4CAN) eHouse Intelligent home eHouse controllers have their own communication protocols and frame formats widely discussed in previous posts . There are currently following combinations of the system :
    • Working directly in the LAN – eHouse 4 Ethernet controllers
    • Working directly on eHouse1 bus (RS – 485) – “eHouse One” controllers under the supervision of a computer , microprocessor systems , etc. . Connection is realized by RS – 485 / RS – 232 / USB adapter
    • Working directly on eHouse CAN bus (CAN) – “eHouse4CAN” controllers under the supervision of a computer , microprocessor systems , etc. . Connection is realized by RS – 232 / USB / CAN “gateway”
    • Hybrid – eHouse 1 (RS – 485) controllers under the supervision of CommManager. Data from eHouse1 controllers pass through CommManager, and eHouse1 controllers statuses are attached to CommManager status, and sent via UDP broadcasts packets the LAN
  • eHouse.PRO centralized installation (for main switchboards) and hybrid version.
  • “eHouse4cServer & eHouse.PRO” Software which is eHouse home automation server ( Ethernet , RS485, PRO, CAN) for the system operates on Linux based systems. The software has implemented all transmission methods directly to eHouse controllers. It allows full control and management and status collection in real time from all eHouse controllers
    Two-way communication is as follows:

    • Statuses are received from the Ethernet eHouse controllers by broadcasts in binary form (below 200B each) over UDP protocol with attached cheksum for data verification . Sending events is done via TCP/IP – Sockets, with standard eHouse authentication to ensure safety and to confirm receipt and add events to the queue by the driver .
    • The software sends the synchronization time for the eHouse1 controllers initiates sequential sending status of the drivers on an RS – 485 / RS – 232 / USB . Events are sent to the controller via RS – 485
    • The software receives the status of eHouse 1 controllers as UDP broadcasts with an attached status CommManager own CM . Additionally receives UDP broadcasts from all Ethernet eHouse controllers.
      Events for eHouse1 controllers are sent via CommManager through TCP/IP protocol as discussed earlier. CommManager direct Ehouse1 events to RS-485 interface and check for confirmation.
      Events for Ethernet controllers are sent directly to the recipient by TCP/IP protocol discussed above.

    Both controllers and eHouse4cServer software remember received events for about 1 – 1.5 seconds , blocking their re-execution in the event of network errors , automatic retransmission , re-launch of the panels, switches , etc. .
    This solution protects electrical equipment from multiple turn on/off in a very short time , which could damage unit as a result of repeated surges.
    eHouse4cServer also has TCP/IP server to respond to requests from the Web server module installed to control eHouse system. “eHouse4cServer” server is discussed in a post dedicated to him .

  • Apache Web server “ehouse4apache.so” module installed.
    The “ehouse4apache.so” module assures eHouse system integration with Apache, is working as a “gateway ( or “proxy server”) to provide two-way communication (1:1) between Web Server and ” eHouse4cServer ” Server software. The module is a minimalist so as not to decrease throughput, stability and performance of Apache. In addition to perform data transmission it is possible to reset , block , unlock software ” eHouse4cServer ” . This ensures a stable and uninterrupted operation and remote reset in cases of suspension or malfunction.
    Minimizing the module for Apache addition to the above factors, it is also conditioned by the following factors:

    • the least load Apache and risks of its instability , which is a critical point ( part of a chain )
    • much more difficult , more time-consuming process of creating Apache modules than standard external application
    • Problems with debugging Apache modules comparing to standard external application
    • the need to create multiple – dozens of independent threads / processes of communication : RS Server – 485 , UDP Listener , Clients TCP/IP , TCP servers
  • Any web browsers – for graphical visualization and control require JavaScript and SVG . Apache Server data are transmitted in the form of a standard query in the form of an addition to the presence of address such as : “http://localhost/eh.x?QUERY”, where QUERY contains a command and its parameters for the Apache module “ehouse4apache.so” and “eHouse4cServer”. In response, the confirmation is received or requested data in clear text for processing by JavaScript scripts.

Installing and configuring Apache to work with eHouse system Home Automation

Basic assumptions relate to the wider miniature hardware (32b) running on the Linux operating system . They may be cheap computer or microprocessor board (without hard drive) such Raspberry Pi for less than 50Euro. Although this software is very powerful and functional it can handle an unlimited number of control panels (eg . a Web browser ) .

  • On the available hardware should be installed Linux distribution available without a graphical environment such as server (tested on Ubuntu 13 . 04, Raspberry PI) .
  • Then, install the Apache Web Server (tested version 2.2.x, 2.4.x) to default location , using administrator privileges ” sudo apt-get install apache2″ ..
  • The configuration file “/etc/apache2/conf/httpd.conf” enable the required authentication and security , certificates which we intend to use and make 2 lines incorporating and configuring the module “ehouse4apache.so ” .
    “LoadModule eh /usr/local/ehouse/ehouse4apache.so
    AddHandler eh .x
  • In the new versions of Apache to copy files eh.load and eh.conf directory from directory “C :\e – house\linux\%DISTRIBUTION%\etc\apache2\mods-available” to the “/etc/apache2/mods-available/” .
    Create symbolic links to these files in the “/etc/apache2/mods-enabled/” :
    “ln – s /etc/apache2/mods-available/eh.load /etc/apache2/mods-enabled/eh.load”
    “ln – s /etc/apache2/mods-available/eh.conf /etc/apache2/mods-enabled/eh.conf”
  • create a directory “/usr/local/ehouse/” and give him all necessary rights , maximum = “sudo chmod 777 /usr/local/ehouse/” . After starting the software, you can reduce it.
  • copy to the directory “/usr/local/ehouse/” module “ehouse4apache.so ” and server software ” eHouse4cServer ” and configuration files
  • Edit the configuration file “eHouseServerC.cfg” according to the descriptions in the file
  • start the server in a terminal window ” /usr/local/ehouse/chouse4cserver” and see if there throws some errors
  • restart or start the Apache server “service apache2 restart”
  • Check telnet is connecting to the “eHouse4cServer” server – ” telnet localhost 1111 ”
  • type or copy command quickly “eHGlobalStatus” and see if the server returns the results of (timeout 20sec )
  • in web browser try to open address runing the same command as follows when accessing the site “localhost/eh.x?eHGlobalStatus”
  • for correct operation you must copy the exported scripts and Web visualization directory “/usr/local/apache2/htdocs” action scripts and try typing the address “localhost/VIEW_NAME.svg” or “localhost/VIEW_NAME.xml”
  • The next step is to limit access rights to file, create users to connect to the Web and set security, certificates and other Apache settings.
  • If you need to work from the outside ( from the internet), you need also properly configured router providing Internet service on the selected port. In addition, it is also necessary to configure DDNS services unless we static IP address.