eHouse RS-485 Smart Home C source code Linux

eHouse1 Home Automation, Building Management – C,C++ open source code for linux

Smart Home eHouse Home Automation software source code C , C ++ , Object C for LINUX operating systems .
This article is an extension Home Automation , C source code .
Connection to eHouse intelligent building automation from “PC” or microcomputer was described in earlier post for various distributions of Linux.
Description of eHouse1 frame transmission protocol via RS-485 and status data structure were discussed in the article eHouse 1 smart home – C programming which describes the source code written in C++ to support eHouse home automation with any device containing Linux operating system.

At the time of writing this article it has the following functionality:

  • Supervising eHouse 1 home automation via RS-485/RS-232/USB
  • Maintain time synchronization of controllers
  • Initiating a sequential query of controllers status and receive it
  • Sending a general temperature measurements (external Pn , Pd , West , East , room , light level sensors) for processing by controllers
  • Receiving logs of controllers
  • Receiving confirmation of events Infrared Transmissions (up to external controllers) and receive IR RC codes (Sony remote control signals) for processing by the server
  • transfer events and confirmations between eHouse1 smart home controllers (as a gateway)
  • Sending events to control eHouse1 home automation controllers
  • Maintaining most current data structure for direct decoding of the binary status
  • Gives the ability to create your own control algorithms based on the received status of the controllers and send events to eHouse1 smart home

Software in the following form does not contain only:

  • possibility of changing the configuration of eHouse1 home automation controllers itself, however it works as a gateway or proxy server between eHouse 1 controllers and eHouse.exe configuration application on Windows
  • firmware upgrade of eHouse1 smart home controllers itself, however it works as a gateway or proxy server between eHouse 1 controllers and eHouse.exe configuration application on Windows

Make sure you have set definition file Smart home eHouse – c open source Linux configuration
ETHERNET_EHOUSE = 0 (1 – default , Ethernet eHouse and eHouse1 managed by CommManager ) – set to 0 to enable only native RS-485 / eHouse1
EHOUSE1_DEVS_COUNT = x (where x is the highest ADRESL of RoomManager – default 15) in the case of a too low number, the controllers with a greater number does not manage to send its status, to the software because next request will be launched (Query).
This parameter affects the time between successive sending inquiries for controllers status , time synchronization , etc. .
COM_PORT – This definition contains the path of the serial port (default is /dev/ttyUSB0 – for the USB adapter > RS-232 because especially in the case of microcomputers difficult to find RS-232 serial port) . It is not recommended to edit this setting but uncomment lines with the appropriate serial port ( ttyUSB0..2 or ttyS0..2 ports for native RS-232 without adapter USB).
STATUS_ARRAYS_SIZE – size of matrix controllers status of eHouse1 minimum highest RM ADRESL + 1 .
Do not change the number manually but uncomment required amount due to the fact that this value is used as a mask for the index table status . Otherwise, the indexes of some drivers will be covered and will be sequentially overwritten. (the default is 15 RM and unless we have more than 15 RM should not change anything) .
and definitions that RoomManager and their sensors perform measurements of ambient temperatures and lighting – give index
eH[AdrL] where AdrL – AddressLow of RM – must be less than the size of the status array eH[]

  • T_NORTH_RM – eH [AdrL] RM measures the outside temperature – midnight
  • T_NORTH_ADC – ADC input number [1 . . 7] – that is connected to the outdoor temperature sensor – midnight
  • T_SOUTH_RM – eH [ AdrL ] RM measures the outside temperature – noon
  • T_SOUTH_ADC – ADC input number [1 . . 7] – that is connected to the outdoor temperature sensor – noon
  • T_WEST_RM – eH [ AdrL ] RM measures the outside temperature – west
  • T_WEST_ADC – ADC input number [1 . . 7] – that is connected to the outdoor temperature sensor – west
  • T_EAST_RM – eH [ AdrL ] RM measures the outside temperature – east
  • T_EAST_ADC – ADC input number [1 . . 7] – that is connected to the outdoor temperature sensor – east
  • T_ROOM_RM – eH [ AdrL ] RM measures the internal temperature – for HeatMangera the needs of CO
  • T_ROOM_ADC – ADC input number [1 . . 7] – that is connected to temperature sensor – for HeatManager the needs of CO
  • LIGHT_LEVEL_RM – eH [ AdrL ] RM measures the light level outside
  • LIGHT_LEVEL_ADC – ADC input number [ 0 ] – that is connected to the level sensor outdoor lighting

All eHouse1 building automation controllers must be programmed in the extended address mode to work properly with this software (status, sending events, event transmission between controllers via software) .
Please use the following addresses ADRESL from 1 due to, that the software for the convenience of the status of the controller saves the status matrix eH [ ADRESL ] with the index equal to the low address. In cell [0] HeatManager status is loaded if it is installed.

If you set the above parameters and compile application is ready to work.
The source code is located under the following links : Smart House eHouse 1 open source linux C++ RS service-485 eHouse Intelligent building Server open source linux C++

The entire eHouse1 server runs one function “uart_int(void )” who works in an infinite loop.
Loop that can be interrupted only by way of an application or function starts “TerminateUart()” .
This application is a software template, and there is no support for multi-threading communication processes.
It is in order to understand, education and support for eHouse 1 smart home, and not for creating an advanced Server in binary form that meets the requirements of all.

To enhance its functionality you should start the service “uart()” for threading with low or lowest priority, to minimize processor utilization. It is very beneficial to the loading configuration from text files, which do not require to continuously recompile the code with the simplest change of settings.

To send eHouse system events “DirectEvent” function is used :
“void SendDirectEventeHouse1(const unsigned char * evt)” – it allows direct sending of event control eHouse 1 smart home working on RS-485.
Parameter here is a string of length 10B in binary code containing a system event in the following form
EVT[0] – AdrH
EVT[1] – AdrL
EVT[2] – command
EVT[3] – arg1 (arguments appropriate for your command
EVT[4] – arg2 (arguments appropriate for your command
EVT[5] – arg3 (arguments appropriate for your command
EVT[6] – arg4 (arguments appropriate for your command
EVT[7] – Arg5 (arguments appropriate for your command
EVT[8] – arg6 (arguments appropriate for your command
EVT[9] – arg7 (arguments appropriate for your command

Noteworthy is the function “void RS485PerformData(void )” that runs periodically after receipt of all statuses and performs data processing and sending of events.
RS485PerformData void (void )

if (( eH[0].HM.OUT.o1 ) // HM // output 1 is switched on and
&& (( eH[1].RM.OUT.o7 ) | (eH[2].RM.OUT.o11)) // output 7 of RM (55 , 1 ) or exit 11 from the RM (55 , 2 ) is on and
&& ((( eH[1].RM.ADC [1 ].MSB << 8) + eH[1].RM.ADC[1].LSB) > 0x230 )) // measurement from the sensor ADC [ 1] of RM (55 , 1 ) is greater than 0x230
{// Launches event for RM (55 , 3 ) the output setting 9 to 32 seconds
SendDirectEventeHouse1( (unsigned char *) ” \x37\x03\x01\x09\x01\x1f\x0\x0\x0\x0″) ;
{// Launches event for RM (55 , 3 ) off exit 9
SendDirectEventeHouse1 ( (unsigned char *) ” \\\\ x37 \\\\ \\\\ x03 x01 x09 \\\\ \\\\ x00 x0 \\\\ \\\\ x0 x0 \\\\ \\\\ x0 x0 \\\\ ” ) ;

It can be any type control algorithms for intelligent system eHouse significantly expanding its functionality in relation to the system as a serial .